answer.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class Answer
  5. * Allows to instantiate an object of type Answer
  6. * 5 arrays are created to receive the attributes of each answer belonging to a specified question
  7. * @package chamilo.exercise
  8. *
  9. * @author Olivier Brouckaert
  10. */
  11. class Answer
  12. {
  13. public $questionId;
  14. // these are arrays
  15. public $answer;
  16. public $correct;
  17. public $comment;
  18. public $weighting;
  19. public $position;
  20. public $hotspot_coordinates;
  21. public $hotspot_type;
  22. public $destination;
  23. // these arrays are used to save temporarily new answers
  24. // then they are moved into the arrays above or deleted in the event of cancellation
  25. public $new_answer;
  26. public $new_correct;
  27. public $new_comment;
  28. public $new_weighting;
  29. public $new_position;
  30. public $new_hotspot_coordinates;
  31. public $new_hotspot_type;
  32. public $autoId;
  33. public $nbrAnswers;
  34. public $new_nbrAnswers;
  35. public $new_destination; // id of the next question if feedback option is set to Directfeedback
  36. public $course; //Course information
  37. /**
  38. * constructor of the class
  39. *
  40. * @author Olivier Brouckaert
  41. * @param int $questionId that answers belong to
  42. * @param int $course_id
  43. */
  44. public function __construct($questionId, $course_id = null)
  45. {
  46. $this->questionId = intval($questionId);
  47. $this->answer = array();
  48. $this->correct = array();
  49. $this->comment = array();
  50. $this->weighting = array();
  51. $this->position = array();
  52. $this->hotspot_coordinates = array();
  53. $this->hotspot_type = array();
  54. $this->destination = array();
  55. // clears $new_* arrays
  56. $this->cancel();
  57. if (!empty($course_id)) {
  58. $courseInfo = api_get_course_info_by_id($course_id);
  59. } else {
  60. $courseInfo = api_get_course_info();
  61. }
  62. $this->course = $courseInfo;
  63. $this->course_id = $courseInfo['real_id'];
  64. // fills arrays
  65. $objExercise = new Exercise($this->course_id);
  66. $exerciseId = isset($_REQUEST['exerciseId']) ? $_REQUEST['exerciseId'] : null;
  67. $objExercise->read($exerciseId);
  68. if ($objExercise->random_answers == '1') {
  69. $this->readOrderedBy('rand()', '');// randomize answers
  70. } else {
  71. $this->read(); // natural order
  72. }
  73. }
  74. /**
  75. * Clears $new_* arrays
  76. *
  77. * @author Olivier Brouckaert
  78. */
  79. public function cancel()
  80. {
  81. $this->new_answer = array();
  82. $this->new_correct = array();
  83. $this->new_comment = array();
  84. $this->new_weighting = array();
  85. $this->new_position = array();
  86. $this->new_hotspot_coordinates = array();
  87. $this->new_hotspot_type = array();
  88. $this->new_nbrAnswers = 0;
  89. $this->new_destination = array();
  90. }
  91. /**
  92. * Reads answer information from the database
  93. *
  94. * @author Olivier Brouckaert
  95. */
  96. public function read()
  97. {
  98. $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
  99. $questionId = $this->questionId;
  100. $sql = "SELECT * FROM $TBL_ANSWER
  101. WHERE
  102. c_id = {$this->course_id} AND
  103. question_id ='".$questionId."'
  104. ORDER BY position";
  105. $result = Database::query($sql);
  106. $i=1;
  107. // while a record is found
  108. while ($object = Database::fetch_object($result)) {
  109. $this->id[$i] = $object->id;
  110. $this->answer[$i] = $object->answer;
  111. $this->correct[$i] = $object->correct;
  112. $this->comment[$i] = $object->comment;
  113. $this->weighting[$i] = $object->ponderation;
  114. $this->position[$i] = $object->position;
  115. $this->hotspot_coordinates[$i] = $object->hotspot_coordinates;
  116. $this->hotspot_type[$i] = $object->hotspot_type;
  117. $this->destination[$i] = $object->destination;
  118. $this->autoId[$i] = $object->id_auto;
  119. $i++;
  120. }
  121. $this->nbrAnswers = $i-1;
  122. }
  123. /**
  124. * returns all answer ids from this question Id
  125. *
  126. * @author Yoselyn Castillo
  127. * @return array - $id (answer ids)
  128. */
  129. public function selectAnswerId()
  130. {
  131. $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
  132. $questionId = $this->questionId;
  133. $sql="SELECT id FROM
  134. $TBL_ANSWER
  135. WHERE c_id = {$this->course_id} AND question_id ='".$questionId."'";
  136. $result = Database::query($sql);
  137. $id = array();
  138. // while a record is found
  139. if (Database::num_rows($result) > 0) {
  140. while ($object = Database::fetch_array($result)) {
  141. $id[] = $object['id'];
  142. }
  143. }
  144. return $id;
  145. }
  146. /**
  147. * Reads answer information from the data base ordered by parameter
  148. * @param string Field we want to order by
  149. * @param string DESC or ASC
  150. * @author Frederic Vauthier
  151. */
  152. public function readOrderedBy($field, $order='ASC')
  153. {
  154. $field = Database::escape_string($field);
  155. if (empty($field)) {
  156. $field = 'position';
  157. }
  158. if ($order != 'ASC' && $order!='DESC') {
  159. $order = 'ASC';
  160. }
  161. $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
  162. $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION);
  163. $questionId = intval($this->questionId);
  164. $sql = "SELECT type FROM $TBL_QUIZ
  165. WHERE c_id = {$this->course_id} AND id = $questionId";
  166. $result_question = Database::query($sql);
  167. $question_type = Database::fetch_array($result_question);
  168. $sql = "SELECT answer,correct,comment,ponderation,position, hotspot_coordinates, hotspot_type, destination, id_auto
  169. FROM $TBL_ANSWER WHERE c_id = {$this->course_id} AND question_id='".$questionId."'
  170. ORDER BY $field $order";
  171. $result=Database::query($sql);
  172. $i = 1;
  173. // while a record is found
  174. $doubt_data = null;
  175. while ($object = Database::fetch_object($result)) {
  176. if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) {
  177. $doubt_data = $object;
  178. continue;
  179. }
  180. $this->answer[$i] = $object->answer;
  181. $this->correct[$i] = $object->correct;
  182. $this->comment[$i] = $object->comment;
  183. $this->weighting[$i] = $object->ponderation;
  184. $this->position[$i] = $object->position;
  185. $this->destination[$i] = $object->destination;
  186. $this->autoId[$i] = $object->id_auto;
  187. $i++;
  188. }
  189. if ($question_type['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) {
  190. $this->answer[$i] = $doubt_data->answer;
  191. $this->correct[$i] = $doubt_data->correct;
  192. $this->comment[$i] = $doubt_data->comment;
  193. $this->weighting[$i] = $doubt_data->ponderation;
  194. $this->position[$i] = $doubt_data->position;
  195. $this->destination[$i] = $doubt_data->destination;
  196. $this->autoId[$i] = $doubt_data->id_auto;
  197. $i++;
  198. }
  199. $this->nbrAnswers = $i-1;
  200. }
  201. /**
  202. * returns the autoincrement id identificator
  203. *
  204. * @author Juan Carlos Ra�a
  205. * @return integer - answer num
  206. */
  207. public function selectAutoId($id)
  208. {
  209. return isset($this->autoId[$id]) ? $this->autoId[$id] : null;
  210. }
  211. /**
  212. * returns the number of answers in this question
  213. *
  214. * @author Olivier Brouckaert
  215. * @return integer - number of answers
  216. */
  217. public function selectNbrAnswers()
  218. {
  219. return $this->nbrAnswers;
  220. }
  221. /**
  222. * returns the question ID which the answers belong to
  223. *
  224. * @author Olivier Brouckaert
  225. * @return integer - the question ID
  226. */
  227. public function selectQuestionId()
  228. {
  229. return $this->questionId;
  230. }
  231. /**
  232. * returns the question ID of the destination question
  233. *
  234. * @author Julio Montoya
  235. * @return integer - the question ID
  236. */
  237. public function selectDestination($id)
  238. {
  239. return isset($this->destination[$id]) ? $this->destination[$id] : null;
  240. }
  241. /**
  242. * returns the answer title
  243. *
  244. * @author Olivier Brouckaert
  245. * @param - integer $id - answer ID
  246. * @return string - answer title
  247. */
  248. public function selectAnswer($id)
  249. {
  250. return isset($this->answer[$id]) ? $this->answer[$id] : null;
  251. }
  252. /**
  253. * return array answer by id else return a bool
  254. */
  255. public function selectAnswerByAutoId($auto_id)
  256. {
  257. $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER);
  258. $auto_id = intval($auto_id);
  259. $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER
  260. WHERE c_id = {$this->course_id} AND id_auto='$auto_id'";
  261. $rs = Database::query($sql);
  262. if (Database::num_rows($rs) > 0) {
  263. $row = Database::fetch_array($rs);
  264. return $row;
  265. }
  266. return false;
  267. }
  268. /**
  269. * returns the answer title from an answer's position
  270. *
  271. * @author Yannick Warnier
  272. * @param - integer $id - answer ID
  273. * @return bool - answer title
  274. */
  275. public function selectAnswerIdByPosition($pos)
  276. {
  277. foreach ($this->position as $k => $v) {
  278. if ($v != $pos) {
  279. continue;
  280. }
  281. return $k;
  282. }
  283. return false;
  284. }
  285. /**
  286. * Returns a list of answers
  287. * @author Yannick Warnier <ywarnier@beeznest.org>
  288. * @return array List of answers where each answer is an array
  289. * of (id, answer, comment, grade) and grade=weighting
  290. */
  291. public function getAnswersList($decode = false)
  292. {
  293. $list = array();
  294. for ($i = 1; $i <= $this->nbrAnswers; $i++) {
  295. if (!empty($this->answer[$i])) {
  296. //Avoid problems when parsing elements with accents
  297. if ($decode) {
  298. $this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding());
  299. $this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding());
  300. }
  301. $list[] = array(
  302. 'id' => $i,
  303. 'answer' => $this->answer[$i],
  304. 'comment' => $this->comment[$i],
  305. 'grade' => $this->weighting[$i],
  306. 'hotspot_coord' => $this->hotspot_coordinates[$i],
  307. 'hotspot_type' => $this->hotspot_type[$i],
  308. 'correct' => $this->correct[$i],
  309. 'destination' => $this->destination[$i]
  310. );
  311. }
  312. }
  313. return $list;
  314. }
  315. /**
  316. * Returns a list of grades
  317. * @author Yannick Warnier <ywarnier@beeznest.org>
  318. * @return array List of grades where grade=weighting (?)
  319. */
  320. public function getGradesList()
  321. {
  322. $list = array();
  323. for ($i = 0; $i<$this->nbrAnswers;$i++){
  324. if(!empty($this->answer[$i])){
  325. $list[$i] = $this->weighting[$i];
  326. }
  327. }
  328. return $list;
  329. }
  330. /**
  331. * Returns the question type
  332. * @author Yannick Warnier <ywarnier@beeznest.org>
  333. * @return integer The type of the question this answer is bound to
  334. */
  335. public function getQuestionType()
  336. {
  337. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  338. $sql = "SELECT type FROM $TBL_QUESTIONS
  339. WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'";
  340. $res = Database::query($sql);
  341. if (Database::num_rows($res)<=0){
  342. return null;
  343. }
  344. $row = Database::fetch_array($res);
  345. return $row['type'];
  346. }
  347. /**
  348. * tells if answer is correct or not
  349. *
  350. * @author Olivier Brouckaert
  351. * @param - integer $id - answer ID
  352. * @return integer - 0 if bad answer, not 0 if good answer
  353. */
  354. public function isCorrect($id)
  355. {
  356. return isset($this->correct[$id]) ? $this->correct[$id] : null;
  357. }
  358. /**
  359. * returns answer comment
  360. *
  361. * @author Olivier Brouckaert
  362. * @param - integer $id - answer ID
  363. * @return string - answer comment
  364. */
  365. public function selectComment($id)
  366. {
  367. return isset($this->comment[$id]) ? $this->comment[$id] : null;
  368. }
  369. /**
  370. * returns answer weighting
  371. *
  372. * @author Olivier Brouckaert
  373. * @param - integer $id - answer ID
  374. * @return integer - answer weighting
  375. */
  376. public function selectWeighting($id)
  377. {
  378. return isset($this->weighting[$id]) ? $this->weighting[$id] : null;
  379. }
  380. /**
  381. * returns answer position
  382. *
  383. * @author Olivier Brouckaert
  384. * @param - integer $id - answer ID
  385. * @return integer - answer position
  386. */
  387. function selectPosition($id)
  388. {
  389. return isset($this->position[$id]) ? $this->position[$id] : null;
  390. }
  391. /**
  392. * returns answer hotspot coordinates
  393. *
  394. * @author Olivier Brouckaert
  395. * @param integer Answer ID
  396. * @return integer Answer position
  397. */
  398. public function selectHotspotCoordinates($id)
  399. {
  400. return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null;
  401. }
  402. /**
  403. * returns answer hotspot type
  404. *
  405. * @author Toon Keppens
  406. * @param integer Answer ID
  407. * @return integer Answer position
  408. */
  409. public function selectHotspotType($id)
  410. {
  411. return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null;
  412. }
  413. /**
  414. * Creates a new answer
  415. *
  416. * @author Olivier Brouckaert
  417. * @param string $answer answer title
  418. * @param integer $correct 0 if bad answer, not 0 if good answer
  419. * @param string $comment answer comment
  420. * @param integer $weighting answer weighting
  421. * @param integer $position answer position
  422. * @param array $new_hotspot_coordinates Coordinates for hotspot exercises (optional)
  423. * @param integer $new_hotspot_type Type for hotspot exercises (optional)
  424. * @param string $destination
  425. */
  426. public function createAnswer(
  427. $answer,
  428. $correct,
  429. $comment,
  430. $weighting,
  431. $position,
  432. $new_hotspot_coordinates = null,
  433. $new_hotspot_type = null,
  434. $destination = ''
  435. ) {
  436. $this->new_nbrAnswers++;
  437. $id = $this->new_nbrAnswers;
  438. $this->new_answer[$id] = $answer;
  439. $this->new_correct[$id] = $correct;
  440. $this->new_comment[$id] = $comment;
  441. $this->new_weighting[$id] = $weighting;
  442. $this->new_position[$id] = $position;
  443. $this->new_hotspot_coordinates[$id] = $new_hotspot_coordinates;
  444. $this->new_hotspot_type[$id] = $new_hotspot_type;
  445. $this->new_destination[$id] = $destination;
  446. }
  447. /**
  448. * Updates an answer
  449. *
  450. * @author Toon Keppens
  451. *
  452. * @param string $answer
  453. * @param string $comment
  454. * @param string $correct
  455. * @param string $weighting
  456. * @param string $position
  457. * @param string $destination
  458. * @param string $hotspot_coordinates
  459. * @param string $hotspot_type
  460. */
  461. public function updateAnswers(
  462. $autoId,
  463. $answer,
  464. $comment,
  465. $correct,
  466. $weighting,
  467. $position,
  468. $destination,
  469. $hotspot_coordinates,
  470. $hotspot_type
  471. ) {
  472. $answerTable = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  473. $autoId = intval($autoId);
  474. $params = [
  475. 'answer' => $answer,
  476. 'comment' => $comment,
  477. 'correct' => $correct,
  478. 'ponderation' => $weighting,
  479. 'position' => $position,
  480. 'destination' => $destination,
  481. 'hotspot_coordinates' => $hotspot_coordinates,
  482. 'hotspot_type' => $hotspot_type,
  483. ];
  484. Database::update($answerTable, $params, ['id_auto = ?' => $autoId]);
  485. }
  486. /**
  487. * Records answers into the data base
  488. *
  489. * @author Olivier Brouckaert
  490. */
  491. public function save()
  492. {
  493. $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER);
  494. $questionId = intval($this->questionId);
  495. $c_id = $this->course['real_id'];
  496. $correctList = [];
  497. $answerList = [];
  498. for ($i=1; $i <= $this->new_nbrAnswers; $i++) {
  499. $answer = $this->new_answer[$i];
  500. $correct = $this->new_correct[$i];
  501. $comment = $this->new_comment[$i];
  502. $weighting = $this->new_weighting[$i];
  503. $position = $this->new_position[$i];
  504. $hotspot_coordinates = $this->new_hotspot_coordinates[$i];
  505. $hotspot_type = $this->new_hotspot_type[$i];
  506. $destination = $this->new_destination[$i];
  507. $autoId = $this->selectAutoId($i);
  508. if (!(isset($this->position[$i]))) {
  509. $params = [
  510. 'c_id' => $c_id,
  511. 'question_id' => $questionId,
  512. 'answer' => $answer,
  513. 'correct' => $correct,
  514. 'comment' => $comment,
  515. 'ponderation' => $weighting,
  516. 'position' => $position,
  517. 'hotspot_coordinates' => $hotspot_coordinates,
  518. 'hotspot_type' => $hotspot_type,
  519. 'destination' => $destination
  520. ];
  521. $autoId = Database::insert($answerTable, $params);
  522. if ($autoId) {
  523. $sql = "UPDATE $answerTable SET id = iid, id_auto = iid WHERE iid = $autoId";
  524. Database::query($sql);
  525. }
  526. } else {
  527. // https://support.chamilo.org/issues/6558
  528. // function updateAnswers already escape_string, error if we do it twice.
  529. // Feed function updateAnswers with none escaped strings
  530. $this->updateAnswers(
  531. $autoId,
  532. $this->new_answer[$i],
  533. $this->new_comment[$i],
  534. $this->new_correct[$i],
  535. $this->new_weighting[$i],
  536. $this->new_position[$i],
  537. $this->new_destination[$i],
  538. $this->new_hotspot_coordinates[$i],
  539. $this->new_hotspot_type[$i]
  540. );
  541. }
  542. $answerList[$i] = $autoId;
  543. if ($correct) {
  544. $correctList[$autoId] = true;
  545. }
  546. }
  547. $questionType = self::getQuestionType();
  548. if ($questionType == MATCHING) {
  549. if (!empty($correctList)) {
  550. foreach ($correctList as $autoId => $status) {
  551. /*$correct = $data['correct'];
  552. if (isset($answerList[$correct])) {
  553. $correct = $answerList[$correct];
  554. }*/
  555. $sql = "UPDATE $answerTable
  556. SET correct = $autoId
  557. WHERE
  558. id_auto = $autoId
  559. ";
  560. Database::query($sql);
  561. }
  562. }
  563. }
  564. if (count($this->position) > $this->new_nbrAnswers) {
  565. $i = $this->new_nbrAnswers + 1;
  566. while ($this->position[$i]) {
  567. $position = $this->position[$i];
  568. $sql = "DELETE FROM $answerTable
  569. WHERE
  570. c_id = {$this->course_id} AND
  571. question_id = '".$questionId."' AND
  572. position ='$position'";
  573. Database::query($sql);
  574. $i++;
  575. }
  576. }
  577. // moves $new_* arrays
  578. $this->answer = $this->new_answer;
  579. $this->correct = $this->new_correct;
  580. $this->comment = $this->new_comment;
  581. $this->weighting = $this->new_weighting;
  582. $this->position = $this->new_position;
  583. $this->hotspot_coordinates = $this->new_hotspot_coordinates;
  584. $this->hotspot_type = $this->new_hotspot_type;
  585. $this->nbrAnswers = $this->new_nbrAnswers;
  586. $this->destination = $this->new_destination;
  587. // clears $new_* arrays
  588. $this->cancel();
  589. }
  590. /**
  591. * Duplicates answers by copying them into another question
  592. *
  593. * @author Olivier Brouckaert
  594. * @param int question id
  595. * @param array destination course info (result of the function api_get_course_info() )
  596. */
  597. public function duplicate($newQuestionId, $course_info = null)
  598. {
  599. if (empty($course_info)) {
  600. $course_info = $this->course;
  601. }
  602. $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  603. $fixed_list = array();
  604. if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ||
  605. self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE
  606. ) {
  607. // Selecting origin options
  608. $origin_options = Question::readQuestionOption($this->selectQuestionId(), $this->course['real_id']);
  609. if (!empty($origin_options)) {
  610. foreach ($origin_options as $item) {
  611. $new_option_list[] = $item['id'];
  612. }
  613. }
  614. $destination_options = Question::readQuestionOption($newQuestionId, $course_info['real_id']);
  615. $i = 0;
  616. if (!empty($destination_options)) {
  617. foreach($destination_options as $item) {
  618. $fixed_list[$new_option_list[$i]] = $item['id'];
  619. $i++;
  620. }
  621. }
  622. }
  623. // if at least one answer
  624. if ($this->nbrAnswers) {
  625. // inserts new answers into data base
  626. $c_id = $course_info['real_id'];
  627. for ($i=1;$i <= $this->nbrAnswers;$i++) {
  628. if ($this->course['id'] != $course_info['id']) {
  629. $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
  630. $this->answer[$i],
  631. $this->course['id'],
  632. $course_info['id']
  633. );
  634. $this->comment[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course(
  635. $this->comment[$i],
  636. $this->course['id'],
  637. $course_info['id']
  638. );
  639. }
  640. $answer = $this->answer[$i];
  641. $correct = $this->correct[$i];
  642. if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE ||
  643. self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE
  644. ) {
  645. $correct = $fixed_list[intval($correct)];
  646. }
  647. $comment = $this->comment[$i];
  648. $weighting = $this->weighting[$i];
  649. $position = $this->position[$i];
  650. $hotspot_coordinates = $this->hotspot_coordinates[$i];
  651. $hotspot_type = $this->hotspot_type[$i];
  652. $destination = $this->destination[$i];
  653. $params = [
  654. 'c_id' => $c_id,
  655. 'question_id' =>$newQuestionId,
  656. 'answer' => $answer,
  657. 'correct' => $correct,
  658. 'comment' => $comment,
  659. 'ponderation' => $weighting,
  660. 'position' => $position,
  661. 'hotspot_coordinates' => $hotspot_coordinates,
  662. 'hotspot_type' => $hotspot_type,
  663. 'destination' => $destination
  664. ];
  665. $id = Database::insert($TBL_REPONSES, $params);
  666. if ($id) {
  667. $sql = "UPDATE $TBL_REPONSES SET id = id_auto WHERE id_auto = $id";
  668. Database::query($sql);
  669. }
  670. }
  671. }
  672. }
  673. /**
  674. * Get the necessary JavaScript for some answers
  675. * @return string
  676. */
  677. public function getJs()
  678. {
  679. //if ($this->questionId == 2)
  680. return "<script>
  681. jsPlumb.ready(function() {
  682. if ($('#drag{$this->questionId}_question').length > 0) {
  683. MatchingDraggable.init('{$this->questionId}');
  684. }
  685. });
  686. </script>";
  687. }
  688. }