Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Qcm Public Bundle Laravel Package

avoo/qcm-public-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer:

    composer require avoo/qcm-public-bundle "@dev-master"
    

    Note: Use @dev-master as the package isn't officially released.

  2. Register Bundles: In AppKernel.php, add both QcmCoreBundle and QcmPublicBundle to the registerBundles() method:

    new Qcm\Bundle\CoreBundle\QcmCoreBundle(),
    new Qcm\Bundle\PublicBundle\QcmPublicBundle(),
    
  3. Configure Routing: Add the routing imports to app/config/routing.yml:

    qcm_core:
        prefix: /
        resource: "@QcmCoreBundle/Resources/config/routing.yml"
    qcm_public:
        resource: "@QcmPublicBundle/Resources/config/routing.yml"
        prefix: /
    
  4. Import Configs: In app/config/config.yml, import the core configs:

    imports:
        - { resource: @QcmCoreBundle/Resources/config/core.yml }
        - { resource: @QcmPublicBundle/Resources/config/core.yml }
    
  5. First Use Case: Access the public QCM (Questionnaire, Course, Module) routes via /. The bundle provides public-facing endpoints for QCM content, likely including:

    • Public quiz displays.
    • Course/module listings.
    • User-submitted responses (if enabled).

Implementation Patterns

Core Workflows

  1. Public Content Exposure:

    • The bundle abstracts logic for rendering QCM content publicly (e.g., quizzes, courses) without requiring authentication.
    • Use the generated routes (e.g., /quiz/{id}) to display public-facing QCM content.
    • Example: Render a public quiz in a Twig template:
      {% extends 'base.html.twig' %}
      {% block body %}
          {{ render(controller('QcmPublicBundle:Quiz:show', {'id': quizId})) }}
      {% endblock %}
      
  2. Dependency on QcmCoreBundle:

    • All public functionality relies on QcmCoreBundle for data models (e.g., Quiz, Question, Course).
    • Extend or override core entities/services from QcmCoreBundle if customization is needed.
  3. Configuration-Driven Behavior:

    • Public access rules (e.g., anonymous access, rate limiting) are likely configurable via config.yml or parameters.
    • Example: Restrict public quiz access to specific IPs:
      # app/config/config.yml
      parameters:
          qcm_public.allowed_ips: ['192.168.1.1', '127.0.0.1']
      
  4. Integration with Frontend:

    • Use the bundle’s routes to embed QCM content in existing templates or SPAs.
    • Example: Fetch public quiz data via AJAX:
      fetch(`/api/quiz/${id}/public`, { headers: { 'Accept': 'application/json' } })
          .then(response => response.json())
          .then(data => renderQuiz(data));
      
  5. Event-Driven Extensions:

    • Listen to core events (e.g., qcm.core.quiz.submitted) to extend public behavior.
    • Example: Log public quiz submissions:
      // src/Acme/AppBundle/EventListener/QcmListener.php
      class QcmListener
      {
          public function onQuizSubmitted(GetResponseForQuizSubmittedEvent $event)
          {
              // Log or notify admins
          }
      }
      
      Register the listener in services.yml:
      services:
          acme.qcm_listener:
              class: Acme\AppBundle\EventListener\QcmListener
              tags:
                  - { name: kernel.event_listener, event: qcm.core.quiz.submitted, method: onQuizSubmitted }
      

Gotchas and Tips

Common Pitfalls

  1. Missing QcmCoreBundle:

    • The public bundle requires QcmCoreBundle. Forgetting to register it will cause ClassNotFound errors.
    • Fix: Ensure both bundles are listed in AppKernel.php and configs are imported.
  2. Route Conflicts:

    • The prefix: / in routing may clash with existing routes. Use unique prefixes or route namespaces:
      qcm_public:
          resource: "@QcmPublicBundle/Resources/config/routing.yml"
          prefix: /public/qcm  # Avoid root conflicts
      
  3. Deprecated Symfony2 Syntax:

    • The bundle targets Symfony2, which may use outdated practices (e.g., AppKernel, YAML configs).
    • Tip: Use a Symfony2-compatible environment (e.g., symfony/symfony:2.8.*) for testing.
  4. Lack of Official Docs:

    • Documentation is minimal. Refer to QcmCoreBundle for core concepts.
    • Tip: Inspect the bundle’s Resources/config/ and Controller/ directories for usage patterns.
  5. Anonymous Access Risks:

    • Public endpoints may expose sensitive data. Validate access in controllers:
      // src/Qcm/PublicBundle/Controller/QuizController.php
      public function showAction($id)
      {
          $quiz = $this->getDoctrine()->getRepository('QcmCoreBundle:Quiz')->find($id);
          if (!$quiz->isPublic()) {
              throw $this->createAccessDeniedException();
          }
          // ...
      }
      

Debugging Tips

  1. Enable Debug Mode:

    • Symfony2’s debug toolbar (%kernel.debug%: true) helps inspect routes, services, and events.
  2. Check Event Dispatching:

    • Use bin/console debug:event-dispatcher to verify if events (e.g., qcm.core.quiz.submitted) are fired.
  3. Inspect Twig Templates:

    • The bundle may rely on Twig templates in Resources/views/. Override them in your app:
      # app/config/config.yml
      twig:
          paths:
              '%kernel.root_dir%/../vendor/avoo/qcm-public-bundle/Resources/views': QcmPublicBundle
              '%kernel.root_dir%/Resources/views': AcmeAppBundle
      

Extension Points

  1. Custom Public Routes:

    • Extend routing by creating a custom route loader or overriding the bundle’s routing.yml:
      # app/config/routing.yml
      acme_qcm_public:
          resource: "@AcmeAppBundle/Resources/config/routing/qcm.yml"
          prefix: /custom/qcm
      
  2. Override Controllers:

    • Extend public controllers (e.g., QuizController) in your bundle:
      namespace Acme\AppBundle\Controller;
      use Qcm\Bundle\PublicBundle\Controller\QuizController as BaseQuizController;
      
      class QuizController extends BaseQuizController
      {
          public function showAction($id)
          {
              // Custom logic
              return parent::showAction($id);
          }
      }
      
      Update services.yml to replace the original service:
      services:
          acme.qcm_public.quiz_controller:
              class: Acme\AppBundle\Controller\QuizController
              parent: qcm_public.quiz_controller
              tags:
                  - { name: controller.service_arguments }
      
  3. Add Public API Endpoints:

    • Use Symfony’s FOSRestBundle or NelmioApiDocBundle to document and expose public QCM data as JSON:
      # app/config/routing.yml
      acme_qcm_api:
          type: rest
          resource: "@AcmeAppBundle/Controller/QcmApiController"
          prefix: /api/qcm
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui