public function post(array $parameters) { $baseQuestion = new BaseQuestion(); $baseQuestion->setCreatedBy($this->getUser()); /** @var BaseQuestion $baseQuestion */ $baseQuestion = $this->processForm($baseQuestion, $parameters, 'POST'); switch ($baseQuestion->getType()) { case BaseQuestion::TEXT_AREA: if (!isset($parameters['text_limit'])) { throw new BadRequestHttpException('Text limit required.'); } $this->createTextAreaQuestion($baseQuestion, $parameters['text_limit']); break; case BaseQuestion::CHOICE: if (!isset($parameters['correct_choices'])) { throw new BadRequestHttpException('Number of correct choices needed.'); } $this->createChoiceQuestion($baseQuestion, $parameters['correct_choices']); break; } $this->em->flush(); return $baseQuestion; }
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('content', 'textarea')->add('enabled', 'checkbox')->add('topic', 'entity', ['class' => Topic::class])->add('type', 'choice', ['choices' => array_combine(BaseQuestion::getTypes(), BaseQuestion::getTypes())])->add('text_limit', 'integer', ['mapped' => false, 'constraints' => [new GreaterThan(10)], 'description' => 'Required for type textarea.'])->add('correct_choices', 'integer', ['mapped' => false, 'constraints' => [new GreaterThanOrEqual(1)], 'description' => 'Required for type Variant.']); }
private function route(BaseQuestion $question) { return $this->get('router')->generate('api_1_get_module', ['question' => $question->getId()]); }