Installation:
composer require avoo/qcm-core-bundle "@dev-master"
Add the bundle to AppKernel.php:
new Qcm\Bundle\CoreBundle\QcmCoreBundle(),
Configure Routing:
Import the routing in app/config/routing.yml:
qcm_core:
resource: "@QcmCoreBundle/Resources/config/routing.yml"
prefix: /
Basic Configuration:
Add to app/config/config.yml:
imports:
- { resource: "@QcmCoreBundle/Resources/config/core.yml" }
Security Setup:
Configure security.yml as per the README.
First Use Case:
Create a questionnaire entity by extending Qcm\Component\Questionnaire\Model\QuestionnaireInterface and register it as a Sylius resource.
Questionnaire Management:
ResourceController to CRUD questionnaires.namespace AppBundle\Entity;
use Qcm\Component\Questionnaire\Model\QuestionnaireInterface;
use Doctrine\ORM\Mapping as ORM;
class Questionnaire implements QuestionnaireInterface {
// Implement required methods from QuestionnaireInterface
}
Question and Answer Handling:
Qcm\Component\Question\Model\QuestionInterface and Qcm\Component\Answer\Model\AnswerInterface.QcmCoreBundle's built-in forms for validation.Statistics and Templates:
config.yml:
qcm_core:
service:
statistics:
class: AppBundle\Statistics\CustomStatistics
template: AppBundle\Template\CustomTemplate
Qcm\Component\Template\TemplateInterface for custom rendering.API Integration:
FOSRestBundle for RESTful endpoints (e.g., /api/questionnaires).JMSSerializerBundle for JSON serialization/deserialization.Pagination:
WhiteOctoberPagerfantaBundle for paginated results:
$pagerfanta = $this->get('pagerfanta.doctrine.orm');
$adapter = new DoctrineORMAdapter($em->getRepository('AppBundle:Questionnaire')->findAll());
$pagerfanta->setAdapter($adapter)->setMaxPerPage(10);
beberlei/DoctrineExtensions for soft-deletes or timestamps if needed.qcm.questionnaire.pre_persist or qcm.answer.post_update events for custom logic.Qcm\Component\Validator\Constraints for custom validation rules.Dependency Conflicts:
sylius/resource-bundle:0.11.*@dev, which may conflict with newer Sylius versions. Pin dependencies explicitly in composer.json:
"conflict": {
"sylius/resource-bundle": "0.11.*"
}
Configuration Overrides:
core.yml is imported after other configurations to avoid precedence issues.config.yml, not services.yml).Timeouts and Time Per Question:
time_per_question is set, timeout is ignored. Validate this logic in your frontend:
if (config.time_per_question) {
timeout = questions.length * config.time_per_question;
}
Serialization Issues:
Serializable or use @JMS\Serializer\Annotation for proper JSON handling.Security:
sha512 encoder is weak. Upgrade to bcrypt or argon2 in security.yml:
encoders:
Qcm\Component\User\Model\UserInterface: bcrypt
Event Debugging:
# app/config/config.yml
framework:
profiler: { only_exceptions: false }
qcm.* events in the profiler.Database Schema:
doctrine:schema:update --dump-sql to verify migrations before applying.Template Debugging:
Qcm\Component\Template\TemplateInterface and add debug logs:
public function render(QuestionnaireInterface $questionnaire) {
error_log("Rendering questionnaire: " . $questionnaire->getId());
return parent::render($questionnaire);
}
Custom Question Types:
MultipleChoiceQuestion) and register it via a service:
services:
app.qcm.question.multiple_choice:
class: AppBundle\Entity\MultipleChoiceQuestion
tags:
- { name: qcm.question_type, alias: multiple_choice }
Answer Validation:
Qcm\Component\Answer\Model\Answer:
use Symfony\Component\Validator\Constraints as Assert;
class Answer {
/**
* @Assert\Length(max="200")
*/
protected $content;
}
API Extensions:
Qcm\Bundle\CoreBundle\Controller\ApiController for custom API logic:
namespace AppBundle\Controller;
use Qcm\Bundle\CoreBundle\Controller\ApiController as BaseApiController;
class CustomApiController extends BaseApiController {
public function customAction() {
// Override or extend API behavior
}
}
Statistics Enhancements:
Qcm\Component\Statistics\Model\QuestionnaireStatistics to add custom metrics:
class CustomStatistics extends QuestionnaireStatistics {
public function getCustomMetric() {
return $this->calculateCustomLogic();
}
}
How can I help you explore Laravel packages today?