Installation
composer require aldaflux/game-quizz-bundle
Ensure your composer.json meets the PHP (>=7.3.2) and Symfony (>=5.2) requirements.
Enable the Bundle
Add to config/bundles.php:
return [
// ...
Aldaflux\GameQuizzBundle\AldafluxGameQuizzBundle::class => ['all' => true],
];
Configure the Bundle
Publish the default config (if needed) and update config/packages/aldaflux_game_quizz.yaml:
aldaflux_game_quizz:
fields:
video:
youtube: true
videolink: true
audio:
question: true
reponse: true
folders:
public: '%kernel.project_dir%/public'
audio: 'sons'
video: 'game_quizz_data/videos'
google_json: '%kernel.project_dir%/path/to/google_id.json' # Required for TTS
Symlink Assets
php bin/console assets:install --symlink
First Use Case: Create a Quiz
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
/game/admin to create a quiz via the provided CRUD interface./game/admin) to:
audio, video).Quiz, Question, Answer) to extend or customize fields.
Example:
// Extend a question entity (if needed)
namespace App\Entity;
use Aldaflux\GameQuizzBundle\Entity\Question as BaseQuestion;
class Question extends BaseQuestion {
// Add custom fields
}
/game/play to trigger quiz sessions.
<a href="{{ path('quizz_game_play_bundle_play', {'id': quiz.id}) }}">Start Quiz</a>
{% extends 'AldafluxGameQuizzBundle::base.html.twig' %}
{% block body %}
{{ include('AldafluxGameQuizzBundle::question.html.twig', {
question: currentQuestion,
answers: currentAnswers
}) }}
{% endblock %}
fields.video/fields.audio.public/{audio|video}/ folders (symlinked via assets:install).youtube: true and providing URLs.google_json path) to generate audio for questions/answers.use Google\Cloud\TextToSpeech\V1\TextToSpeechClient;
$client = new TextToSpeechClient();
$response = $client->synthesizeSpeech([
'input' => ['text' => 'Your question here'],
'voice' => ['languageCode' => 'en-US', 'name' => 'en-US-Wavenet-D'],
]);
file_put_contents('public/sons/question.mp3', $response->getAudioContent());
vendor/aldaflux/game-quizz-bundle/Resources/views/ to
templates/bundles/AldafluxGameQuizzBundle/.question.html.twig):
{% extends 'AldafluxGameQuizzBundle::question.html.twig' %}
{% block answer_item %}
<div class="custom-answer">
{{ parent() }}
<span class="feedback">{{ answer.feedback }}</span>
</div>
{% endblock %}
use Symfony\Component\Serializer\SerializerInterface;
class QuizApiController {
public function __construct(private SerializerInterface $serializer) {}
public function getQuiz(int $id): JsonResponse {
$quiz = $this->quizRepository->find($id);
return new JsonResponse($this->serializer->serialize($quiz, 'json'));
}
}
Google TTS Configuration:
google_json path causes TTS failures.Google\Api\Core\ApiException errors.Media Uploads:
php bin/console assets:install --symlink after config changes.folders.public points to the correct public/ directory.Doctrine Migrations:
doctrine:migrations:diff after extending entities and update manually if needed.Route Conflicts:
/game/admin or /game/play may conflict with existing routes.config/routes.yaml:
aldaflux_game_quizz:
resource: '@AldafluxGameQuizzBundle/Controller/AdminController.php'
prefix: '/custom/prefix/admin'
Twig Template Overrides:
php bin/console cache:clear
APP_DEBUG=1 in .env for detailed error logs.aldaflux_game_quizz.question.save to debug custom logic:
// src/EventListener/CustomQuizListener.php
namespace App\EventListener;
use Aldaflux\GameQuizzBundle\Event\QuizEvents;
class CustomQuizListener {
public function onQuestionSave(QuestionEvent $event) {
// Log or modify question data
}
}
Register in services.yaml:
services:
App\EventListener\CustomQuizListener:
tags:
- { name: kernel.event_listener, event: aldaflux_game_quizz.question.save, method: onQuestionSave }
Custom Fields:
Question) to add fields like difficulty or tags.QuestionType) to include new fields:
// src/Form/QuestionTypeExtension.php
use Symfony\Component\Form\AbstractTypeExtension;
use Aldaflux\GameQuizzBundle\Form\Type\QuestionType;
class QuestionTypeExtension extends AbstractTypeExtension {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('difficulty', ChoiceType::class, ['choices' => ['Easy', 'Medium', 'Hard']]);
}
public static function getExtendedType(): string { return QuestionType::class; }
}
Validation:
use Symfony\Component\Validator\Constraints as Assert;
class Question {
/**
* @Assert\Length(min=10)
*/
private $content;
}
API Endpoints:
#[Route('/api/quizzes', name: 'api_quizzes')]
class QuizApiController {
#[Route('/{id}', name: 'api_quiz_detail')]
public function detail(Quiz $quiz): JsonResponse {
return $this->json($quiz->toArray());
}
}
Localization:
translations/bundles/AldafluxGameQuizzBundle.en.yaml:
question:
title: "Custom Question Title"
How can I help you explore Laravel packages today?