Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.98 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Controller\Question;
  4.  
  5. use App\Breadcrumbs\BreadcrumbsBuilder;
  6. use App\Form\QuestionType as QuestionType2;
  7. use App\Model\InterviewQuery;
  8. use App\Model\Question;
  9. use App\Model\QuestionAnswerQuery;
  10. use App\Model\QuestionnaireType;
  11. use App\Model\QuestionQuery;
  12. use App\Model\QuestionType;
  13. use App\Model\QuestionTypeQuery;
  14. use App\Utils\QuestionTypeUtil;
  15. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  16. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  17. use Propel\Runtime\ActiveQuery\ModelCriteria;
  18. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  20. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  21. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\StreamedResponse;
  24. use Symfony\Component\Routing\Annotation\Route;
  25.  
  26. class CrudController extends AbstractController
  27. {
  28. private $breadcrumbs;
  29.  
  30. public function __construct(BreadcrumbsBuilder $breadcrumbs)
  31. {
  32. $this->breadcrumbs = $breadcrumbs;
  33. }
  34.  
  35. /**
  36. * @Route("/question/{questionnaire_type_id}/{question_type_id}/new", name="question_new", requirements={"questionnaire_type_id": "\d+", "question_type_id": "\d+"})
  37. * @ParamConverter("questionnaireType", options={"mapping"={"questionnaire_type_id"="id"}})
  38. * @ParamConverter("questionType", options={"mapping"={"question_type_id"="id"}})
  39. * @Method({"GET", "POST"})
  40. * @Security("has_role('ROLE_ADMIN')")
  41. */
  42. public function new(Request $request, QuestionnaireType $questionnaireType, QuestionType $questionType)
  43. {
  44. $respondentName = $questionnaireType->getName();
  45. $this->breadcrumbs->add('Questionnaire', 'questionnaire_index');
  46. $this->breadcrumbs->add($respondentName.' Questions', 'question_index', ['id' => $questionnaireType->getId()]);
  47. $this->breadcrumbs->add('Create Question', 'question_new', ['questionnaire_type_id' => $questionnaireType->getId(), 'question_type_id' => $questionType->getId()]);
  48.  
  49. $question = new Question();
  50. $question->initAnswer($this->initNumber($questionType));
  51. $question->setQuestionnaireTypeId($questionnaireType->getId());
  52. $question->setQuestionTypeId($questionType->getId());
  53.  
  54. $collectionChoices = ($questionType->getId() === QuestionTypeUtil::Image_selection) ? 1 : null;
  55. $isCard = ($questionType->getId() == QuestionTypeUtil::card) ? 1 : null;
  56. $isRating = ($questionType->getId() == QuestionTypeUtil::Range_Answer) ? true : false;
  57. $form = $this->createForm(QuestionType2::class, $question, [
  58. 'is_choices' => $collectionChoices,
  59. 'is_rating' => $isRating,
  60. 'is_card' => $isCard,
  61. ]);
  62. $form->handleRequest($request);
  63.  
  64. if ($form->isSubmitted() && $form->isValid()) {
  65. $question->setQuestion($question->getQuestion());
  66. $question->setCreatedBy($this->getUser()->getId());
  67. $question->save();
  68.  
  69. $this->addFlash('success', 'Question successfully added!');
  70.  
  71. return $this->redirectToRoute('question_index', ['id' => $questionnaireType->getId()]);
  72. }
  73.  
  74. //Rendering
  75. if($questionType->getId() == QuestionTypeUtil::Single_Answer_with_other || $questionType->getId() == QuestionTypeUtil::Multiple_has_other) {
  76. $withOther = true;
  77. } else {
  78. $withOther = false;
  79. }
  80.  
  81. if($questionType->getId() == QuestionTypeUtil::Matrix_Answer || $questionType->getId() == QuestionTypeUtil::Matrix_multiple_select) {
  82. $withAtribut = true;
  83. $withAtributValue = ($questionType->getId() == QuestionTypeUtil::Matrix_multiple_select) ? true : false;
  84. } else {
  85. $withAtribut = false;
  86. $withAtributValue = false;
  87. }
  88.  
  89.  
  90. if($questionType->getId() === QuestionTypeUtil::Single_Answer_yes_no) {
  91. $formTemplate = 'question/form_boolean.html.twig';
  92. } else if($questionType->getId() === QuestionTypeUtil::Openended_Answer_text || $questionType->getId() === QuestionTypeUtil::Openended_Answer_with_masking || $questionType->getId() === QuestionTypeUtil::card){
  93. $formTemplate = 'question/form_input.html.twig';
  94. } else if($questionType->getId() === QuestionTypeUtil::Matrix_Answer){
  95. $formTemplate = 'question/form_matrix.html.twig';
  96. } else if($questionType->getId() === QuestionTypeUtil::Image_selection){
  97. $formTemplate = 'question/form_image.html.twig';
  98. } else if($questionType->getId() === QuestionTypeUtil::Matrix_multiple_select){
  99. $formTemplate = 'question/form_matrix_multiple.html.twig';
  100. } else if($questionType->getId() === QuestionTypeUtil::Range_Answer){
  101. $formTemplate = 'question/form_rating.html.twig';
  102. } else if($questionType->getId() === QuestionTypeUtil::panel_dynamic){
  103. $formTemplate = 'question/form_panel_dynamic.html.twig';
  104. } else {
  105. $formTemplate = 'question/form.html.twig';
  106. }
  107.  
  108. return $this->render('question/new.html.twig', [
  109. 'form' => $form->createView(),
  110. 'title' => $question->getQuestionType()->getName(),
  111. 'menu' => implode('', $this->generateMenu($questionnaireType->getId(), $questionType->getId())),
  112. 'formTemplate' => $formTemplate,
  113. 'withOther' => $withOther,
  114. 'withAtribut' => $withAtribut,
  115. 'withAtributValue' => $withAtributValue,
  116. 'questionnaire_type_id' => $questionnaireType->getId(),
  117. 'question_type_id' => $questionType->getId(),
  118. 'respondent_type_name' => $respondentName,
  119. 'is_card' => $isCard,
  120. 'is_masking' => $questionType->getId() == QuestionTypeUtil::Openended_Answer_with_masking,
  121. ]);
  122. }
  123.  
  124. /**
  125. * @Route("/question/{questionnaire_type_id}/{question_type_id}/edit/{question_id}", name="question_edit", requirements={"questionnaire_type_id": "\d+", "question_type_id": "\d+", "question_id": "\d+"})
  126. * @ParamConverter("questionnaireType", options={"mapping"={"questionnaire_type_id"="id"}})
  127. * @ParamConverter("questionType", options={"mapping"={"question_type_id"="id"}})
  128. * @ParamConverter("question", options={"mapping"={"question_id"="id"}})
  129. * @Method({"GET", "POST"})
  130. * @Security("has_role('ROLE_ADMIN')")
  131. */
  132. public function edit(Request $request, QuestionnaireType $questionnaireType, QuestionType $questionType, Question $question)
  133. {
  134. $questionnaireName = $questionnaireType->getName();
  135. $this->breadcrumbs->add('Questionnaire', 'questionnaire_index');
  136. $this->breadcrumbs->add($questionnaireName.' Questions', 'question_index', ['id' => $questionnaireType->getId()]);
  137. $this->breadcrumbs->add('Edit Question', 'question_edit', ['questionnaire_type_id' => $questionnaireType->getId(), 'question_type_id' => $questionType->getId(), 'question_id' => $question->getId()]);
  138.  
  139. if($question->getQuestionTypeId() != $questionType->getId()) {
  140. //Inisiasi - jumlah jawaban yg ada
  141. $initNumber = $this->initNumber($questionType) - $question->getQuestionAnswers()->count();
  142. $numbertoAdd = $initNumber >= 0 ? $initNumber : 0;
  143. $question->initAnswer($numbertoAdd);
  144. }
  145. $collectionChoices = ($questionType->getId() === QuestionTypeUtil::Image_selection) ? 1 : null;
  146. $isCard = ($questionType->getId() == QuestionTypeUtil::card) ? 1 : null;
  147. $isRating = ($questionType->getId() == QuestionTypeUtil::Range_Answer) ? true : false;
  148. $form = $this->createForm(QuestionType2::class, $question, [
  149. 'is_choices' => $collectionChoices,
  150. 'is_rating' => $isRating,
  151. 'is_card' => $isCard,
  152. ]);
  153.  
  154. $form->handleRequest($request);
  155.  
  156. if($form->isSubmitted() && $form->isValid()) {
  157. $question->setQuestion($question->getQuestion());
  158. $question->setQuestionTypeId($questionType->getId());
  159. $question->setCreatedBy($this->getUser()->getId());
  160. $question->save();
  161.  
  162. $this->addFlash('success', 'Question has been updated!');
  163.  
  164. return $this->redirectToRoute('question_index', ['id' => $questionnaireType->getId()]);
  165. }
  166.  
  167. //render edit
  168. if($questionType->getId() == QuestionTypeUtil::Single_Answer_with_other || $questionType->getId() == QuestionTypeUtil::Multiple_has_other) {
  169. $withOther = true;
  170. } else {
  171. $withOther = false;
  172. }
  173.  
  174. if($questionType->getId() == QuestionTypeUtil::Matrix_Answer || $questionType->getId() == QuestionTypeUtil::Matrix_multiple_select) {
  175. $withAtribut = true;
  176. $withAtributValue = ($questionType->getId() == QuestionTypeUtil::Matrix_multiple_select) ? true : false;
  177. } else {
  178. $withAtribut = false;
  179. $withAtributValue = false;
  180. }
  181.  
  182. if($questionType->getId() === QuestionTypeUtil::Single_Answer_yes_no) {
  183. $formTemplate = 'question/form_boolean.html.twig';
  184. } else if($questionType->getId() === QuestionTypeUtil::Openended_Answer_text || $questionType->getId() === QuestionTypeUtil::Openended_Answer_with_masking || $questionType->getId() === QuestionTypeUtil::card){
  185. $formTemplate = 'question/form_input.html.twig';
  186. } else if($questionType->getId() === QuestionTypeUtil::Matrix_Answer){
  187. $formTemplate = 'question/form_matrix.html.twig';
  188. } else if($questionType->getId() === QuestionTypeUtil::Image_selection){
  189. $formTemplate = 'question/form_image.html.twig';
  190. } else if($questionType->getId() === QuestionTypeUtil::Matrix_multiple_select){
  191. $formTemplate = 'question/form_matrix_multiple.html.twig';
  192. } else if($questionType->getId() === QuestionTypeUtil::Range_Answer){
  193. $formTemplate = 'question/form_rating.html.twig';
  194. } else if($questionType->getId() === QuestionTypeUtil::panel_dynamic){
  195. $formTemplate = 'question/form_panel_dynamic.html.twig';
  196. } else {
  197. $formTemplate = 'question/form.html.twig';
  198. }
  199.  
  200. return $this->render('question/edit.html.twig', [
  201. 'form' => $form->createView(),
  202. 'title' => $questionType->getName(),
  203. 'menu' => implode('', $this->generateMenu($questionnaireType->getId(), $questionType->getId(), $question->getId())),
  204. 'formTemplate' => $formTemplate,
  205. 'withOther' => $withOther,
  206. 'withAtribut' => $withAtribut,
  207. 'withAtributValue' => $withAtributValue,
  208. 'questionnaire_type_id' => $questionnaireType->getId(),
  209. 'question_type_id' => $questionType->getId(),
  210. 'respondent_type_name' => $questionnaireName,
  211. 'is_card' => $isCard,
  212. 'is_masking' => $questionType->getId() == QuestionTypeUtil::Openended_Answer_with_masking,
  213. ]);
  214. }
  215.  
  216. /**
  217. * @Route("/question/{questionnaire_type_id}/{question_type_id}/download/{question_id}", name="question_download", requirements={"questionnaire_type_id": "\d+", "question_type_id": "\d+", "question_id": "\d+"})
  218. * @ParamConverter("questionnaireType", options={"mapping"={"questionnaire_type_id"="id"}})
  219. * @ParamConverter("questionType", options={"mapping"={"question_type_id"="id"}})
  220. * @ParamConverter("question", options={"mapping"={"question_id"="id"}})
  221. * @Method({"GET", "POST"})
  222. * @Security("has_role('ROLE_ADMIN')")
  223. */
  224. public function downloadExcel(Request $request, QuestionnaireType $questionnaireType, QuestionType $questionType, Question $question)
  225. {
  226. $head = $this->getQuestion($question);
  227. $answer = $this->getExcelData($question);
  228.  
  229. $specialQuestion = [
  230. 'Matrix Multiple Select',
  231. 'Matrix Answer'
  232. ];
  233.  
  234. $specialCase =
  235. [
  236. 'C3E'
  237. ];
  238.  
  239. //create spreadsheet
  240. $spreadsheet = new Spreadsheet();
  241. $sheet = $spreadsheet->getActiveSheet();
  242.  
  243. //create second header
  244. // if(in_array($question->getQuestionType(), $specialQuestion)) {
  245. // $questionAnswers = QuestionAnswerQuery::create()
  246. // ->filterByQuestion($question)
  247. // ->select(['answer'])
  248. // ->find()
  249. // ->toArray();
  250. //
  251. // $startCell = 'A6';
  252. // $sheet->fromArray(
  253. // $questionAnswers,
  254. // NULL,
  255. // 'A5',
  256. // true
  257. // );
  258. // }
  259. //create second header
  260. $questionAnswers = QuestionAnswerQuery::create()
  261. ->filterByQuestion($question)
  262. ->select(['answer'])
  263. ->find()
  264. ->toArray();
  265.  
  266. if(in_array($question->getQuestionNumber(), $specialCase)){
  267. $attributes = QuestionQuery::create()
  268. ->filterByQuestionNumber($question->getQuestionNumber(),ModelCriteria::EQUAL)
  269. ->select(['atribut'])
  270. ->find()
  271. ->toArray();
  272.  
  273. $attribute = explode(',', $attributes[0]);
  274.  
  275. $arr =[];
  276. for($i=0;$i<count($questionAnswers);$i++){
  277. $arr = array_merge($arr,$attribute);
  278. }
  279.  
  280. $startCell = 'A6';
  281. $sheet->fromArray(
  282. $arr,
  283. NULL,
  284. 'B5',
  285. true
  286. );
  287. }elseif(in_array($question->getQuestionType(), $specialQuestion) && !in_array($question->getQuestionNumber(), $specialCase)){
  288. $startCell = 'A6';
  289. $sheet->fromArray(
  290. $questionAnswers,
  291. NULL,
  292. 'B5',
  293. true
  294. );
  295. }else{
  296. $startCell = 'A5';
  297. }
  298.  
  299. //header
  300. $sheet->fromArray(
  301. $head,
  302. NULL,
  303. 'A4',
  304. true);
  305.  
  306.  
  307. $sheet->fromArray(
  308. $answer,
  309. NULL,
  310. $startCell,
  311. true
  312. );
  313.  
  314. //set title
  315. $sheet->setTitle($question->getQuestionNumber());
  316.  
  317. // Create your Office 2007 Excel (XLSX Format)
  318. $writer = new Xlsx($spreadsheet);
  319.  
  320. $response = new StreamedResponse(
  321. function () use ($writer) {
  322. $writer->save('php://output');
  323. }
  324. );
  325.  
  326. $dispositions = 'attachment';
  327. $filename = 'export-'.$question->getQuestionNumber().'.xlsx';
  328. $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  329. $response->headers->set('Content-Disposition', $response->headers->makeDisposition($dispositions, $filename));
  330. $response->headers->set('Cache-Control','max-age=0');
  331. return $response;
  332. }
  333.  
  334. private function getQuestion(Question $question)
  335. {
  336. $multipleAnswerQuestion =
  337. [
  338. 'Matrix Multiple Select',
  339. 'Multiple Answer with Other',
  340. 'Matrix Answer',
  341. 'Multiple Answers',
  342. ];
  343.  
  344. $specialCase =
  345. [
  346. 'C3E'
  347. ];
  348.  
  349.  
  350. if(in_array($question->getQuestionType(), $multipleAnswerQuestion)){
  351. if(in_array($question->getQuestionNumber(), $specialCase)){
  352. $tmp = [];
  353. $attributes = explode(',', $question->getAtribut());
  354. $answers = QuestionAnswerQuery::create()
  355. ->filterByQuestion($question)
  356. ->select(['answer'])
  357. ->find()
  358. ->toArray();
  359. foreach ($answers as $answer)
  360. {
  361. foreach ($attributes as $attribute)
  362. {
  363. $tmp [] = $question->getQuestion().' - '.$answer;
  364. }
  365. }
  366. $question = $tmp;
  367. }else{
  368. $question = QuestionQuery::create()
  369. ->joinQuestionAnswer()
  370. ->filterById($question->getId())
  371. ->select(['question'])
  372. ->find()
  373. ->toArray();
  374. }
  375. }else{
  376. $question = [$question->getQuestion()];
  377. }
  378. return array_merge(['Respondent ID'],$question);
  379. }
  380.  
  381. private function getExcelData(Question $question)
  382. {
  383. $oneForeachAnswer =
  384. [
  385. 'Multiple Answers',
  386. 'Multiple Answer with Other',
  387. ];
  388.  
  389. $specialCase =
  390. [
  391. 'C3E'
  392. ];
  393.  
  394. $answers = InterviewQuery::create()
  395. ->useRespondentQuery()
  396. ->filterByDeletedAt(null, ModelCriteria::EQUAL)
  397. ->endUse()
  398. ->useAssignmentDetailQuery()
  399. ->filterByStatusVerified()
  400. ->endUse()
  401. ->filterByQuestion($question)
  402. ->select(['raw_answer_export','respondent_id'])
  403. ->find()
  404. ->toArray();
  405.  
  406. $questionAnswers = QuestionAnswerQuery::create()
  407. ->filterByQuestion($question)
  408. ->select(['answer'])
  409. ->find()
  410. ->toArray();
  411.  
  412. if(($question->getQuestionType() == 'Matrix Multiple Select') && (!in_array($question->getQuestionNumber(),$specialCase))){
  413. $tmp = [];
  414. $flipQA = array_flip($questionAnswers);
  415.  
  416. foreach ($answers as $answer)
  417. {
  418. $tmp [] = json_decode($answer['raw_answer_export'],true);
  419. }
  420.  
  421. $containers = [];
  422. foreach ($tmp as $item)
  423. {
  424. foreach ($item as $index => $value)
  425. {
  426. $containers[] = $value;
  427. }
  428. }
  429.  
  430. $returns = [];
  431. foreach ($containers as $contain)
  432. {
  433. //$return [] = array_merge_recursive($contain,array_flip($questionAnswers));
  434. //$return [] = array_replace_recursive(array_flip($questionAnswers), $contain);
  435. $returns [] = array_replace_recursive($flipQA, $contain);
  436. }
  437.  
  438. $datas = [];
  439. $goods = [];
  440.  
  441. foreach ($returns as $return)
  442. {
  443. foreach ($return as $index => $data)
  444. {
  445. if(is_array($data)){
  446. $datas [$index] = array_shift($data);
  447. }else{
  448. $datas[$index] = null;
  449. }
  450. }
  451. $goods[] = $datas;
  452. }
  453. // $result = $returns;
  454. $result = $goods;
  455.  
  456. }elseif($question->getQuestionType() == 'Matrix Answer') {
  457. $tmp2 = [];
  458. $flipQuestionAnswers = array_flip($questionAnswers);
  459. $questionAnswer = [];
  460. foreach ($flipQuestionAnswers as $index => $fill)
  461. {
  462. $questionAnswer[$index] = null;
  463. }
  464.  
  465. foreach ($answers as $answer2)
  466. {
  467. $tmp2 [] = json_decode($answer2['raw_answer_export'],true);
  468. }
  469.  
  470. $container = [];
  471. foreach ($tmp2 as $item)
  472. {
  473. foreach ($item as $value)
  474. {
  475. $container[] = $value;
  476. }
  477. }
  478. $return = [];
  479. foreach ($container as $contain)
  480. {
  481. $return [] = array_replace_recursive($questionAnswer, $contain);
  482. }
  483. $result = $return;
  484. }elseif(in_array($question->getQuestionType(), $oneForeachAnswer)){
  485. $tmp3 = [];
  486. foreach ($answers as $answer3)
  487. {
  488. $tmp3 [] = json_decode($answer3['raw_answer_export'],true);
  489. }
  490.  
  491. $final =[];
  492. foreach ($tmp3 as $value){
  493. if(array_key_exists($question->getId().'-Comment', $value))
  494. {
  495. $final [] = [$value[$question->getId().'-Comment']];
  496. }
  497. else
  498. {
  499. foreach ($value as $outcome){
  500. $final[] = $outcome;
  501. }
  502. }
  503. }
  504.  
  505. $result = $final;
  506. }elseif(in_array($question->getQuestionNumber(),$specialCase)){
  507. $attributes = QuestionQuery::create()
  508. ->filterByQuestionNumber($question->getQuestionNumber(),ModelCriteria::EQUAL)
  509. ->select(['atribut'])
  510. ->find()
  511. ->toArray();
  512.  
  513. $attribute = explode(',', $attributes[0]);
  514. $flipAttributes = array_flip($attribute);
  515. $flipAttribute = [];
  516.  
  517. foreach ($flipAttributes as $index => $fill)
  518. {
  519. $flipAttribute[$index] = null;
  520. }
  521. $tmpr = [];
  522. foreach ($answers as $answered) {
  523. $tmpr [] = json_decode($answered['raw_answer_export'], true);
  524. }
  525.  
  526. $items = [];
  527. foreach ($tmpr as $values)
  528. {
  529. foreach ($values as $value)
  530. {
  531. $items [] = $value;
  532. }
  533. }
  534.  
  535. $return = [];
  536. $finalization = [];
  537. $merged = [];
  538. foreach ($items as $key => $item)
  539. {
  540. foreach ($item as $index => $price)
  541. {
  542. $return [$index] = array_replace_recursive($flipAttribute, $price);
  543. }
  544. $finalization[] = array_reduce(
  545. array_map(function($item) {
  546. return array_values($item);
  547. }, array_values($return)),
  548. [$this, "reduce_data"]
  549. );
  550. }
  551. $result = $finalization;
  552. // $result = $box;
  553. }else {
  554. $tmp4 = [];
  555. foreach ($answers as $answer4) {
  556. $tmp4 [] = json_decode($answer4['raw_answer_export'], true);
  557. }
  558.  
  559. $result = $tmp4;
  560. }
  561.  
  562. $respondent_id = [];
  563. foreach ($answers as $answer)
  564. {
  565. $respondent_id[] = json_decode($answer['respondent_id'],true);
  566. }
  567.  
  568. $newArray = [];
  569. for($i=0;$i<count($respondent_id);$i++)
  570. {
  571. array_unshift($result[$i],$respondent_id[$i]);
  572. }
  573.  
  574. return $result;
  575. }
  576.  
  577. public function reduce_data($a, $b, $initial = []) {
  578. $a = is_null($a) ? [] : $a;
  579. $b = is_null($b) ? [] : $b;
  580. $initial = is_null($initial) ? [] : $initial;
  581.  
  582. return array_merge($initial, $a, $b);
  583. }
  584.  
  585. /**
  586. * @Route("/question/{id}/delete", name="question_delete", requirements={"id":"\d+"})
  587. * @Method({"DELETE"})
  588. * @Security("has_role('ROLE_ADMIN')")
  589. */
  590. public function deleteAction(Question $question)
  591. {
  592. $question->delete();
  593.  
  594. $swal = "Question deleted!";
  595. return $this->json(['success' => true, 'message' => $swal]);
  596. }
  597.  
  598. private function generateMenu($questionnaireTypeId, $typeId, $editId = null)
  599. {
  600. $types = QuestionTypeQuery::create()->orderByName()->find();
  601.  
  602. foreach($types as $type){
  603. $class = '';
  604. $iconClass = 'text-grey-light';
  605. $textClass = 'text-grey-light';
  606. if($type->getId() == $typeId) {
  607. $class = 'active';
  608. $iconClass = 'txt-blue';
  609. $textClass = '';
  610. }
  611. if($editId) {
  612. $url = $this->generateUrl('question_edit', ['questionnaire_type_id' => $questionnaireTypeId, 'question_type_id' => $type->getId(), 'question_id' => $editId]);
  613. } else {
  614. $url = $this->generateUrl('question_new', ['questionnaire_type_id' => $questionnaireTypeId, 'question_type_id' => $type->getId()]);
  615. }
  616. $data[] = sprintf('<li class="%s"><a href="%s" class="%s"><i class="icon-check mr-5 %s"></i><span>%s</span></a></li>', $class, $url, $textClass, $iconClass, $type->getName());
  617. }
  618.  
  619. return $data;
  620. }
  621.  
  622. private function initNumber(QuestionType $questionType)
  623. {
  624. switch ($questionType->getId()) {
  625. case QuestionTypeUtil::Single_Answer_yes_no:
  626. return 2;
  627. case QuestionTypeUtil::Openended_Answer_text:
  628. return 0;
  629. case QuestionTypeUtil::Openended_Answer_with_masking:
  630. return 0;
  631. case QuestionTypeUtil::Range_Answer:
  632. return 10;
  633. case QuestionTypeUtil::card:
  634. return 0;
  635. default :
  636. return 4;
  637. }
  638. }
  639. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement