Answer the question
In order to leave comments, you need to log in
Zend Framework 2 how to implement polls module?
I am doing a project on Zend Fremework 2 + Doctrine ORM. There is a task to write the designer of polls. A survey can have an unlimited number of questions. The answer to a question can have one of 5 types: Text, Textarea, Radio, MultiCheckbox ,Select. Multiple choice options can be unlimited. I sort of solved the problem, but with a crutch. I'm sure there is a native solution based on collections, but I can't figure it out.
So, now the structure is as follows (The names of the models are fictitious to make it easier to understand):
if (!empty($this->questions)) {
foreach ($this->questions as $question) {
switch ($question->getQuestionType()->getTypeName()) {
case 'Text':
$this->add(array(
'name' => $question->getId(),
'type' => $question->getQuestionType()->getTypeName(),
'options' => array(
'label' => $question->getQuestionText(),
),
'attributes' => array(
'class' => 'form-control'
),
));
break;
case 'MultiCheckbox':
$this->add(array(
'name' => $question->getId(),
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
'options' => array(
'label' => $question->getQuestionText(),
'object_manager' => $objectManager,
'target_class' => 'Category\Entity\RegAppAnswers',
'property' => 'answer',
'is_method' => true,
'find_method' => array(
'name' => 'findBy',
'params' => array(
'criteria' => array('question' => $question->getId()),
),
),
),
'attributes' => array(
'class' => 'checkbox-inline'
),
));
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question