Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Exercise often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Exercise, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class Exercise |
||
| 17 | { |
||
| 18 | public $id; |
||
| 19 | public $name; |
||
| 20 | public $title; |
||
| 21 | public $exercise; |
||
| 22 | public $description; |
||
| 23 | public $sound; |
||
| 24 | public $type; //ALL_ON_ONE_PAGE or ONE_PER_PAGE |
||
| 25 | public $random; |
||
| 26 | public $random_answers; |
||
| 27 | public $active; |
||
| 28 | public $timeLimit; |
||
| 29 | public $attempts; |
||
| 30 | public $feedback_type; |
||
| 31 | public $end_time; |
||
| 32 | public $start_time; |
||
| 33 | public $questionList; // array with the list of this exercise's questions |
||
| 34 | /* including question list of the media */ |
||
| 35 | public $questionListUncompressed; |
||
| 36 | public $results_disabled; |
||
| 37 | public $expired_time; |
||
| 38 | public $course; |
||
| 39 | public $course_id; |
||
| 40 | public $propagate_neg; |
||
| 41 | public $saveCorrectAnswers; |
||
| 42 | public $review_answers; |
||
| 43 | public $randomByCat; |
||
| 44 | public $text_when_finished; |
||
| 45 | public $display_category_name; |
||
| 46 | public $pass_percentage; |
||
| 47 | public $edit_exercise_in_lp = false; |
||
| 48 | public $is_gradebook_locked = false; |
||
| 49 | public $exercise_was_added_in_lp = false; |
||
| 50 | public $lpList = array(); |
||
| 51 | public $force_edit_exercise_in_lp = false; |
||
| 52 | public $categories; |
||
| 53 | public $categories_grouping = true; |
||
| 54 | public $endButton = 0; |
||
| 55 | public $categoryWithQuestionList; |
||
| 56 | public $mediaList; |
||
| 57 | public $loadQuestionAJAX = false; |
||
| 58 | // Notification send to the teacher. |
||
| 59 | public $emailNotificationTemplate = null; |
||
| 60 | // Notification send to the student. |
||
| 61 | public $emailNotificationTemplateToUser = null; |
||
| 62 | public $countQuestions = 0; |
||
| 63 | public $fastEdition = false; |
||
| 64 | public $modelType = 1; |
||
| 65 | public $questionSelectionType = EX_Q_SELECTION_ORDERED; |
||
| 66 | public $hideQuestionTitle = 0; |
||
| 67 | public $scoreTypeModel = 0; |
||
| 68 | public $categoryMinusOne = true; // Shows the category -1: See BT#6540 |
||
| 69 | public $globalCategoryId = null; |
||
| 70 | public $onSuccessMessage = null; |
||
| 71 | public $onFailedMessage = null; |
||
| 72 | public $emailAlert; |
||
| 73 | public $notifyUserByEmail = ''; |
||
| 74 | public $sessionId = 0; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Constructor of the class |
||
| 78 | * |
||
| 79 | * @author Olivier Brouckaert |
||
| 80 | */ |
||
| 81 | public function __construct($course_id = null) |
||
| 82 | { |
||
| 83 | $this->id = 0; |
||
| 84 | $this->exercise = ''; |
||
| 85 | $this->description = ''; |
||
| 86 | $this->sound = ''; |
||
| 87 | $this->type = ALL_ON_ONE_PAGE; |
||
| 88 | $this->random = 0; |
||
| 89 | $this->random_answers = 0; |
||
| 90 | $this->active = 1; |
||
| 91 | $this->questionList = array(); |
||
| 92 | $this->timeLimit = 0; |
||
| 93 | $this->end_time = ''; |
||
| 94 | $this->start_time = ''; |
||
| 95 | $this->results_disabled = 1; |
||
| 96 | $this->expired_time = 0; |
||
| 97 | $this->propagate_neg = 0; |
||
| 98 | $this->saveCorrectAnswers = 0; |
||
| 99 | $this->review_answers = false; |
||
| 100 | $this->randomByCat = 0; |
||
| 101 | $this->text_when_finished = ''; |
||
| 102 | $this->display_category_name = 0; |
||
| 103 | $this->pass_percentage = ''; |
||
| 104 | |||
| 105 | $this->modelType = 1; |
||
| 106 | $this->questionSelectionType = EX_Q_SELECTION_ORDERED; |
||
| 107 | $this->endButton = 0; |
||
| 108 | $this->scoreTypeModel = 0; |
||
| 109 | $this->globalCategoryId = null; |
||
| 110 | |||
| 111 | if (!empty($course_id)) { |
||
| 112 | $course_info = api_get_course_info_by_id($course_id); |
||
| 113 | } else { |
||
| 114 | $course_info = api_get_course_info(); |
||
| 115 | } |
||
| 116 | $this->course_id = $course_info['real_id']; |
||
| 117 | $this->course = $course_info; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Reads exercise information from the data base |
||
| 122 | * |
||
| 123 | * @author Olivier Brouckaert |
||
| 124 | * @param integer $id - exercise Id |
||
| 125 | * |
||
| 126 | * @return boolean - true if exercise exists, otherwise false |
||
| 127 | */ |
||
| 128 | public function read($id, $parseQuestionList = true) |
||
| 129 | { |
||
| 130 | $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); |
||
| 131 | $table_lp_item = Database::get_course_table(TABLE_LP_ITEM); |
||
| 132 | |||
| 133 | $id = intval($id); |
||
| 134 | if (empty($this->course_id)) { |
||
| 135 | |||
| 136 | return false; |
||
| 137 | } |
||
| 138 | $sql = "SELECT * FROM $TBL_EXERCISES |
||
| 139 | WHERE c_id = ".$this->course_id." AND id = ".$id; |
||
| 140 | $result = Database::query($sql); |
||
| 141 | |||
| 142 | // if the exercise has been found |
||
| 143 | if ($object = Database::fetch_object($result)) { |
||
| 144 | $this->id = $id; |
||
| 145 | $this->exercise = $object->title; |
||
| 146 | $this->name = $object->title; |
||
| 147 | $this->title = $object->title; |
||
| 148 | $this->description = $object->description; |
||
| 149 | $this->sound = $object->sound; |
||
| 150 | $this->type = $object->type; |
||
| 151 | if (empty($this->type)) { |
||
| 152 | $this->type = ONE_PER_PAGE; |
||
| 153 | } |
||
| 154 | $this->random = $object->random; |
||
| 155 | $this->random_answers = $object->random_answers; |
||
| 156 | $this->active = $object->active; |
||
| 157 | $this->results_disabled = $object->results_disabled; |
||
| 158 | $this->attempts = $object->max_attempt; |
||
| 159 | $this->feedback_type = $object->feedback_type; |
||
| 160 | $this->propagate_neg = $object->propagate_neg; |
||
| 161 | $this->saveCorrectAnswers = $object->save_correct_answers; |
||
| 162 | $this->randomByCat = $object->random_by_category; |
||
| 163 | $this->text_when_finished = $object->text_when_finished; |
||
| 164 | $this->display_category_name = $object->display_category_name; |
||
| 165 | $this->pass_percentage = $object->pass_percentage; |
||
| 166 | $this->sessionId = $object->session_id; |
||
| 167 | $this->is_gradebook_locked = api_resource_is_locked_by_gradebook($id, LINK_EXERCISE); |
||
| 168 | $this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false; |
||
| 169 | $this->globalCategoryId = isset($object->global_category_id) ? $object->global_category_id : null; |
||
| 170 | $this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null; |
||
| 171 | |||
| 172 | $sql = "SELECT lp_id, max_score |
||
| 173 | FROM $table_lp_item |
||
| 174 | WHERE c_id = {$this->course_id} AND |
||
| 175 | item_type = '".TOOL_QUIZ."' AND |
||
| 176 | path = '".$id."'"; |
||
| 177 | $result = Database::query($sql); |
||
| 178 | |||
| 179 | if (Database::num_rows($result) > 0) { |
||
| 180 | $this->exercise_was_added_in_lp = true; |
||
| 181 | $this->lpList = Database::store_result($result, 'ASSOC'); |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->force_edit_exercise_in_lp = api_get_configuration_value('force_edit_exercise_in_lp'); |
||
| 185 | |||
| 186 | if ($this->exercise_was_added_in_lp) { |
||
| 187 | $this->edit_exercise_in_lp = $this->force_edit_exercise_in_lp == true; |
||
| 188 | } else { |
||
| 189 | $this->edit_exercise_in_lp = true; |
||
| 190 | } |
||
| 191 | |||
| 192 | if (!empty($object->end_time)) { |
||
| 193 | $this->end_time = $object->end_time; |
||
| 194 | } |
||
| 195 | if (!empty($object->start_time)) { |
||
| 196 | $this->start_time = $object->start_time; |
||
| 197 | } |
||
| 198 | |||
| 199 | // Control time |
||
| 200 | $this->expired_time = $object->expired_time; |
||
| 201 | |||
| 202 | // Checking if question_order is correctly set |
||
| 203 | if ($parseQuestionList) { |
||
| 204 | $this->setQuestionList(); |
||
| 205 | } |
||
| 206 | |||
| 207 | //overload questions list with recorded questions list |
||
| 208 | //load questions only for exercises of type 'one question per page' |
||
| 209 | //this is needed only is there is no questions |
||
| 210 | /* |
||
| 211 | // @todo not sure were in the code this is used somebody mess with the exercise tool |
||
| 212 | // @todo don't know who add that config and why $_configuration['live_exercise_tracking'] |
||
| 213 | global $_configuration, $questionList; |
||
| 214 | if ($this->type == ONE_PER_PAGE && $_SERVER['REQUEST_METHOD'] != 'POST' && defined('QUESTION_LIST_ALREADY_LOGGED') && |
||
| 215 | isset($_configuration['live_exercise_tracking']) && $_configuration['live_exercise_tracking']) { |
||
| 216 | $this->questionList = $questionList; |
||
| 217 | }*/ |
||
| 218 | return true; |
||
| 219 | } |
||
| 220 | |||
| 221 | return false; |
||
| 222 | } |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | public function getCutTitle() |
||
| 231 | |||
| 232 | /** |
||
| 233 | * returns the exercise ID |
||
| 234 | * |
||
| 235 | * @author Olivier Brouckaert |
||
| 236 | * @return int - exercise ID |
||
| 237 | */ |
||
| 238 | public function selectId() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * returns the exercise title |
||
| 245 | * |
||
| 246 | * @author Olivier Brouckaert |
||
| 247 | * @return string - exercise title |
||
| 248 | */ |
||
| 249 | public function selectTitle() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * returns the number of attempts setted |
||
| 256 | * |
||
| 257 | * @return int - exercise attempts |
||
| 258 | */ |
||
| 259 | public function selectAttempts() |
||
| 263 | |||
| 264 | /** returns the number of FeedbackType * |
||
| 265 | * 0=>Feedback , 1=>DirectFeedback, 2=>NoFeedback |
||
| 266 | * @return int - exercise attempts |
||
| 267 | */ |
||
| 268 | public function selectFeedbackType() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * returns the time limit |
||
| 275 | */ |
||
| 276 | public function selectTimeLimit() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * returns the exercise description |
||
| 283 | * |
||
| 284 | * @author Olivier Brouckaert |
||
| 285 | * @return string - exercise description |
||
| 286 | */ |
||
| 287 | public function selectDescription() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * returns the exercise sound file |
||
| 294 | * |
||
| 295 | * @author Olivier Brouckaert |
||
| 296 | * @return string - exercise description |
||
| 297 | */ |
||
| 298 | public function selectSound() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * returns the exercise type |
||
| 305 | * |
||
| 306 | * @author Olivier Brouckaert |
||
| 307 | * @return integer - exercise type |
||
| 308 | */ |
||
| 309 | public function selectType() |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return int |
||
| 316 | */ |
||
| 317 | public function getModelType() |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return int |
||
| 324 | */ |
||
| 325 | public function selectEndButton() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getOnSuccessMessage() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | public function getOnFailedMessage() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * @author hubert borderiou 30-11-11 |
||
| 348 | * @return integer : do we display the question category name for students |
||
| 349 | */ |
||
| 350 | public function selectDisplayCategoryName() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return int |
||
| 357 | */ |
||
| 358 | public function selectPassPercentage() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * |
||
| 365 | * Modify object to update the switch display_category_name |
||
| 366 | * @author hubert borderiou 30-11-11 |
||
| 367 | * @param int $in_txt is an integer 0 or 1 |
||
| 368 | */ |
||
| 369 | public function updateDisplayCategoryName($in_txt) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @author hubert borderiou 28-11-11 |
||
| 376 | * @return string html text : the text to display ay the end of the test. |
||
| 377 | */ |
||
| 378 | public function selectTextWhenFinished() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * @author hubert borderiou 28-11-11 |
||
| 385 | * @return string html text : update the text to display ay the end of the test. |
||
| 386 | */ |
||
| 387 | public function updateTextWhenFinished($in_txt) |
||
| 391 | |||
| 392 | /** |
||
| 393 | * return 1 or 2 if randomByCat |
||
| 394 | * @author hubert borderiou |
||
| 395 | * @return integer - quiz random by category |
||
| 396 | */ |
||
| 397 | public function selectRandomByCat() |
||
| 401 | |||
| 402 | /** |
||
| 403 | * return 0 if no random by cat |
||
| 404 | * return 1 if random by cat, categories shuffled |
||
| 405 | * return 2 if random by cat, categories sorted by alphabetic order |
||
| 406 | * @author hubert borderiou |
||
| 407 | * @return integer - quiz random by category |
||
| 408 | */ |
||
| 409 | public function isRandomByCat() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * return nothing |
||
| 431 | * update randomByCat value for object |
||
| 432 | * @param int $random |
||
| 433 | * |
||
| 434 | * @author hubert borderiou |
||
| 435 | */ |
||
| 436 | public function updateRandomByCat($random) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Tells if questions are selected randomly, and if so returns the draws |
||
| 452 | * |
||
| 453 | * @author Carlos Vargas |
||
| 454 | * @return integer - results disabled exercise |
||
| 455 | */ |
||
| 456 | public function selectResultsDisabled() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * tells if questions are selected randomly, and if so returns the draws |
||
| 463 | * |
||
| 464 | * @author Olivier Brouckaert |
||
| 465 | * @return integer - 0 if not random, otherwise the draws |
||
| 466 | */ |
||
| 467 | public function isRandom() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * returns random answers status. |
||
| 478 | * |
||
| 479 | * @author Juan Carlos Rana |
||
| 480 | */ |
||
| 481 | public function selectRandomAnswers() |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Same as isRandom() but has a name applied to values different than 0 or 1 |
||
| 488 | */ |
||
| 489 | public function getShuffle() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * returns the exercise status (1 = enabled ; 0 = disabled) |
||
| 496 | * |
||
| 497 | * @author Olivier Brouckaert |
||
| 498 | * @return boolean - true if enabled, otherwise false |
||
| 499 | */ |
||
| 500 | public function selectStatus() |
||
| 504 | |||
| 505 | /** |
||
| 506 | * If false the question list will be managed as always if true the question will be filtered |
||
| 507 | * depending of the exercise settings (table c_quiz_rel_category) |
||
| 508 | * @param bool active or inactive grouping |
||
| 509 | **/ |
||
| 510 | public function setCategoriesGrouping($status) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * @return int |
||
| 517 | */ |
||
| 518 | public function getHideQuestionTitle() |
||
| 522 | |||
| 523 | /** |
||
| 524 | * @param $value |
||
| 525 | */ |
||
| 526 | public function setHideQuestionTitle($value) |
||
| 530 | |||
| 531 | /** |
||
| 532 | * @return int |
||
| 533 | */ |
||
| 534 | public function getScoreTypeModel() |
||
| 538 | |||
| 539 | /** |
||
| 540 | * @param int $value |
||
| 541 | */ |
||
| 542 | public function setScoreTypeModel($value) |
||
| 546 | |||
| 547 | /** |
||
| 548 | * @return int |
||
| 549 | */ |
||
| 550 | public function getGlobalCategoryId() |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @param int $value |
||
| 557 | */ |
||
| 558 | public function setGlobalCategoryId($value) |
||
| 565 | |||
| 566 | /** |
||
| 567 | * |
||
| 568 | * @param int $start |
||
| 569 | * @param int $limit |
||
| 570 | * @param int $sidx |
||
| 571 | * @param string $sord |
||
| 572 | * @param array $where_condition |
||
| 573 | * @param array $extraFields |
||
| 574 | */ |
||
| 575 | public function getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition = array(), $extraFields = array()) |
||
| 659 | |||
| 660 | /** |
||
| 661 | * Get question count per exercise from DB (any special treatment) |
||
| 662 | * @return int |
||
| 663 | */ |
||
| 664 | View Code Duplication | public function getQuestionCount() |
|
| 682 | |||
| 683 | /** |
||
| 684 | * @return array |
||
| 685 | */ |
||
| 686 | View Code Duplication | public function getQuestionOrderedListByName() |
|
| 687 | { |
||
| 688 | $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
||
| 689 | $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
||
| 690 | |||
| 691 | // Getting question list from the order (question list drag n drop interface ). |
||
| 692 | $sql = "SELECT e.question_id |
||
| 693 | FROM $TBL_EXERCICE_QUESTION e |
||
| 694 | INNER JOIN $TBL_QUESTIONS q |
||
| 695 | ON (e.question_id= q.id AND e.c_id = q.c_id) |
||
| 696 | WHERE |
||
| 697 | e.c_id = {$this->course_id} AND |
||
| 698 | e.exercice_id = '".Database::escape_string($this->id)."' |
||
| 699 | ORDER BY q.question"; |
||
| 700 | $result = Database::query($sql); |
||
| 701 | $list = array(); |
||
| 702 | if (Database::num_rows($result)) { |
||
| 703 | $list = Database::store_result($result, 'ASSOC'); |
||
| 704 | } |
||
| 705 | return $list; |
||
| 706 | } |
||
| 707 | |||
| 708 | /** |
||
| 709 | * Gets the question list ordered by the question_order setting (drag and drop) |
||
| 710 | * @return array |
||
| 711 | */ |
||
| 712 | private function getQuestionOrderedList() |
||
| 713 | { |
||
| 714 | $questionList = array(); |
||
| 715 | |||
| 716 | $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
||
| 717 | $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
||
| 718 | |||
| 719 | // Getting question_order to verify that the question |
||
| 720 | // list is correct and all question_order's were set |
||
| 721 | $sql = "SELECT DISTINCT e.question_order |
||
| 722 | FROM $TBL_EXERCICE_QUESTION e |
||
| 723 | INNER JOIN $TBL_QUESTIONS q |
||
| 724 | ON (e.question_id = q.id) |
||
| 725 | WHERE |
||
| 726 | e.c_id = {$this->course_id} AND |
||
| 727 | e.exercice_id = ".Database::escape_string($this->id); |
||
| 728 | |||
| 729 | $result = Database::query($sql); |
||
| 730 | |||
| 731 | $count_question_orders = Database::num_rows($result); |
||
| 732 | |||
| 733 | // Getting question list from the order (question list drag n drop interface ). |
||
| 734 | $sql = "SELECT DISTINCT e.question_id, e.question_order |
||
| 735 | FROM $TBL_EXERCICE_QUESTION e |
||
| 736 | INNER JOIN $TBL_QUESTIONS q |
||
| 737 | ON (e.question_id= q.id) |
||
| 738 | WHERE |
||
| 739 | e.c_id = {$this->course_id} AND |
||
| 740 | e.exercice_id = '".Database::escape_string($this->id)."' |
||
| 741 | ORDER BY question_order"; |
||
| 742 | |||
| 743 | $result = Database::query($sql); |
||
| 744 | |||
| 745 | // Fills the array with the question ID for this exercise |
||
| 746 | // the key of the array is the question position |
||
| 747 | $temp_question_list = array(); |
||
| 748 | |||
| 749 | $counter = 1; |
||
| 750 | while ($new_object = Database::fetch_object($result)) { |
||
| 751 | // Correct order. |
||
| 752 | $questionList[$new_object->question_order] = $new_object->question_id; |
||
| 753 | // Just in case we save the order in other array |
||
| 754 | $temp_question_list[$counter] = $new_object->question_id; |
||
| 755 | $counter++; |
||
| 756 | } |
||
| 757 | |||
| 758 | if (!empty($temp_question_list)) { |
||
| 759 | /* If both array don't match it means that question_order was not correctly set |
||
| 760 | for all questions using the default mysql order */ |
||
| 761 | if (count($temp_question_list) != $count_question_orders) { |
||
| 762 | $questionList = $temp_question_list; |
||
| 763 | } |
||
| 764 | } |
||
| 765 | |||
| 766 | return $questionList; |
||
| 767 | } |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Select N values from the questions per category array |
||
| 771 | * |
||
| 772 | * @param array $categoriesAddedInExercise |
||
| 773 | * @param array $question_list |
||
| 774 | * @param array $questions_by_category per category |
||
| 775 | * @param bool $flatResult |
||
| 776 | * @param bool $randomizeQuestions |
||
| 777 | * |
||
| 778 | * @return array |
||
| 779 | */ |
||
| 780 | private function pickQuestionsPerCategory( |
||
| 781 | $categoriesAddedInExercise, |
||
| 782 | $question_list, |
||
| 783 | & $questions_by_category, |
||
| 784 | $flatResult = true, |
||
| 785 | $randomizeQuestions = false |
||
| 786 | ) { |
||
| 787 | $addAll = true; |
||
| 788 | $categoryCountArray = array(); |
||
| 789 | |||
| 790 | // Getting how many questions will be selected per category. |
||
| 791 | if (!empty($categoriesAddedInExercise)) { |
||
| 792 | $addAll = false; |
||
| 793 | // Parsing question according the category rel exercise settings |
||
| 794 | foreach ($categoriesAddedInExercise as $category_info) { |
||
| 795 | $category_id = $category_info['category_id']; |
||
| 796 | if (isset($questions_by_category[$category_id])) { |
||
| 797 | // How many question will be picked from this category. |
||
| 798 | $count = $category_info['count_questions']; |
||
| 799 | // -1 means all questions |
||
| 800 | if ($count == -1) { |
||
| 801 | $categoryCountArray[$category_id] = 999; |
||
| 802 | } else { |
||
| 803 | $categoryCountArray[$category_id] = $count; |
||
| 804 | } |
||
| 805 | } |
||
| 806 | } |
||
| 807 | } |
||
| 808 | |||
| 809 | if (!empty($questions_by_category)) { |
||
| 810 | $temp_question_list = array(); |
||
| 811 | |||
| 812 | foreach ($questions_by_category as $category_id => & $categoryQuestionList) { |
||
| 813 | if (isset($categoryCountArray) && !empty($categoryCountArray)) { |
||
| 814 | if (isset($categoryCountArray[$category_id])) { |
||
| 815 | $numberOfQuestions = $categoryCountArray[$category_id]; |
||
| 816 | } else { |
||
| 817 | $numberOfQuestions = 0; |
||
| 818 | } |
||
| 819 | } |
||
| 820 | |||
| 821 | if ($addAll) { |
||
| 822 | $numberOfQuestions = 999; |
||
| 823 | } |
||
| 824 | |||
| 825 | if (!empty($numberOfQuestions)) { |
||
| 826 | $elements = TestCategory::getNElementsFromArray( |
||
| 827 | $categoryQuestionList, |
||
| 828 | $numberOfQuestions, |
||
| 829 | $randomizeQuestions |
||
| 830 | ); |
||
| 831 | |||
| 832 | if (!empty($elements)) { |
||
| 833 | $temp_question_list[$category_id] = $elements; |
||
| 834 | $categoryQuestionList = $elements; |
||
| 835 | } |
||
| 836 | } |
||
| 837 | } |
||
| 838 | |||
| 839 | if (!empty($temp_question_list)) { |
||
| 840 | if ($flatResult) { |
||
| 841 | $temp_question_list = array_flatten($temp_question_list); |
||
| 842 | } |
||
| 843 | $question_list = $temp_question_list; |
||
| 844 | } |
||
| 845 | } |
||
| 846 | |||
| 847 | return $question_list; |
||
| 848 | } |
||
| 849 | |||
| 850 | /** |
||
| 851 | * Selecting question list depending in the exercise-category |
||
| 852 | * relationship (category table in exercise settings) |
||
| 853 | * |
||
| 854 | * @param array $question_list |
||
| 855 | * @param int $questionSelectionType |
||
| 856 | * @return array |
||
| 857 | */ |
||
| 858 | public function getQuestionListWithCategoryListFilteredByCategorySettings($question_list, $questionSelectionType) |
||
| 859 | { |
||
| 860 | $result = array( |
||
| 861 | 'question_list' => array(), |
||
| 862 | 'category_with_questions_list' => array() |
||
| 863 | ); |
||
| 864 | |||
| 865 | // Order/random categories |
||
| 866 | $cat = new TestCategory(); |
||
| 867 | |||
| 868 | // Setting category order. |
||
| 869 | |||
| 870 | switch ($questionSelectionType) { |
||
| 871 | case EX_Q_SELECTION_ORDERED: // 1 |
||
| 872 | case EX_Q_SELECTION_RANDOM: // 2 |
||
| 873 | // This options are not allowed here. |
||
| 874 | break; |
||
| 875 | View Code Duplication | case EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED: // 3 |
|
| 876 | $categoriesAddedInExercise = $cat->getCategoryExerciseTree( |
||
| 877 | $this, |
||
| 878 | $this->course['real_id'], |
||
| 879 | 'title ASC', |
||
| 880 | false, |
||
| 881 | true |
||
| 882 | ); |
||
| 883 | |||
| 884 | $questions_by_category = TestCategory::getQuestionsByCat( |
||
| 885 | $this->id, |
||
| 886 | $question_list, |
||
| 887 | $categoriesAddedInExercise |
||
|
|
|||
| 888 | ); |
||
| 889 | |||
| 890 | |||
| 891 | $question_list = $this->pickQuestionsPerCategory( |
||
| 892 | $categoriesAddedInExercise, |
||
| 893 | $question_list, |
||
| 894 | $questions_by_category, |
||
| 895 | true, |
||
| 896 | false |
||
| 897 | ); |
||
| 898 | break; |
||
| 899 | case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED: // 4 |
||
| 900 | View Code Duplication | case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED: // 7 |
|
| 901 | $categoriesAddedInExercise = $cat->getCategoryExerciseTree( |
||
| 902 | $this, |
||
| 903 | $this->course['real_id'], |
||
| 904 | null, |
||
| 905 | true, |
||
| 906 | true |
||
| 907 | ); |
||
| 908 | $questions_by_category = TestCategory::getQuestionsByCat( |
||
| 909 | $this->id, |
||
| 910 | $question_list, |
||
| 911 | $categoriesAddedInExercise |
||
| 912 | ); |
||
| 913 | $question_list = $this->pickQuestionsPerCategory( |
||
| 914 | $categoriesAddedInExercise, |
||
| 915 | $question_list, |
||
| 916 | $questions_by_category, |
||
| 917 | true, |
||
| 918 | false |
||
| 919 | ); |
||
| 920 | break; |
||
| 921 | View Code Duplication | case EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_RANDOM: // 5 |
|
| 922 | $categoriesAddedInExercise = $cat->getCategoryExerciseTree( |
||
| 923 | $this, |
||
| 924 | $this->course['real_id'], |
||
| 925 | 'title DESC', |
||
| 926 | false, |
||
| 927 | true |
||
| 928 | ); |
||
| 929 | $questions_by_category = TestCategory::getQuestionsByCat( |
||
| 930 | $this->id, |
||
| 931 | $question_list, |
||
| 932 | $categoriesAddedInExercise |
||
| 933 | ); |
||
| 934 | $question_list = $this->pickQuestionsPerCategory( |
||
| 935 | $categoriesAddedInExercise, |
||
| 936 | $question_list, |
||
| 937 | $questions_by_category, |
||
| 938 | true, |
||
| 939 | true |
||
| 940 | ); |
||
| 941 | break; |
||
| 942 | case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM: // 6 |
||
| 943 | View Code Duplication | case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED: |
|
| 944 | $categoriesAddedInExercise = $cat->getCategoryExerciseTree( |
||
| 945 | $this, |
||
| 946 | $this->course['real_id'], |
||
| 947 | null, |
||
| 948 | true, |
||
| 949 | true |
||
| 950 | ); |
||
| 951 | $questions_by_category = TestCategory::getQuestionsByCat( |
||
| 952 | $this->id, |
||
| 953 | $question_list, |
||
| 954 | $categoriesAddedInExercise |
||
| 955 | ); |
||
| 956 | $question_list = $this->pickQuestionsPerCategory( |
||
| 957 | $categoriesAddedInExercise, |
||
| 958 | $question_list, |
||
| 959 | $questions_by_category, |
||
| 960 | true, |
||
| 961 | true |
||
| 962 | ); |
||
| 963 | break; |
||
| 964 | case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED: // 7 |
||
| 965 | break; |
||
| 966 | case EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED: // 8 |
||
| 967 | break; |
||
| 968 | View Code Duplication | case EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED: // 9 |
|
| 969 | $categoriesAddedInExercise = $cat->getCategoryExerciseTree( |
||
| 970 | $this, |
||
| 971 | $this->course['real_id'], |
||
| 972 | 'root ASC, lft ASC', |
||
| 973 | false, |
||
| 974 | true |
||
| 975 | ); |
||
| 976 | $questions_by_category = TestCategory::getQuestionsByCat( |
||
| 977 | $this->id, |
||
| 978 | $question_list, |
||
| 979 | $categoriesAddedInExercise |
||
| 980 | ); |
||
| 981 | $question_list = $this->pickQuestionsPerCategory( |
||
| 982 | $categoriesAddedInExercise, |
||
| 983 | $question_list, |
||
| 984 | $questions_by_category, |
||
| 985 | true, |
||
| 986 | false |
||
| 987 | ); |
||
| 988 | break; |
||
| 989 | View Code Duplication | case EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM: // 10 |
|
| 990 | $categoriesAddedInExercise = $cat->getCategoryExerciseTree( |
||
| 991 | $this, |
||
| 992 | $this->course['real_id'], |
||
| 993 | 'root, lft ASC', |
||
| 994 | false, |
||
| 995 | true |
||
| 996 | ); |
||
| 997 | $questions_by_category = TestCategory::getQuestionsByCat( |
||
| 998 | $this->id, |
||
| 999 | $question_list, |
||
| 1000 | $categoriesAddedInExercise |
||
| 1001 | ); |
||
| 1002 | $question_list = $this->pickQuestionsPerCategory( |
||
| 1003 | $categoriesAddedInExercise, |
||
| 1004 | $question_list, |
||
| 1005 | $questions_by_category, |
||
| 1006 | true, |
||
| 1007 | true |
||
| 1008 | ); |
||
| 1009 | break; |
||
| 1010 | } |
||
| 1011 | |||
| 1012 | $result['question_list'] = isset($question_list) ? $question_list : array(); |
||
| 1013 | $result['category_with_questions_list'] = isset($questions_by_category) ? $questions_by_category : array(); |
||
| 1014 | |||
| 1015 | // Adding category info in the category list with question list: |
||
| 1016 | |||
| 1017 | if (!empty($questions_by_category)) { |
||
| 1018 | |||
| 1019 | /*$em = Database::getManager(); |
||
| 1020 | $repo = $em->getRepository('ChamiloCoreBundle:CQuizCategory');*/ |
||
| 1021 | |||
| 1022 | $newCategoryList = array(); |
||
| 1023 | |||
| 1024 | foreach ($questions_by_category as $categoryId => $questionList) { |
||
| 1025 | $cat = new TestCategory(); |
||
| 1026 | $cat = $cat->getCategory($categoryId); |
||
| 1027 | |||
| 1028 | $cat = (array)$cat; |
||
| 1029 | $cat['iid'] = $cat['id']; |
||
| 1030 | //*$cat['name'] = $cat['name']; |
||
| 1031 | |||
| 1032 | $categoryParentInfo = null; |
||
| 1033 | // Parent is not set no loop here |
||
| 1034 | if (!empty($cat['parent_id'])) { |
||
| 1035 | if (!isset($parentsLoaded[$cat['parent_id']])) { |
||
| 1036 | $categoryEntity = $em->find('ChamiloCoreBundle:CQuizCategory', $cat['parent_id']); |
||
| 1037 | $parentsLoaded[$cat['parent_id']] = $categoryEntity; |
||
| 1038 | } else { |
||
| 1039 | $categoryEntity = $parentsLoaded[$cat['parent_id']]; |
||
| 1040 | } |
||
| 1041 | $path = $repo->getPath($categoryEntity); |
||
| 1042 | $index = 0; |
||
| 1043 | if ($this->categoryMinusOne) { |
||
| 1044 | //$index = 1; |
||
| 1045 | } |
||
| 1046 | /** @var \Chamilo\Entity\CQuizCategory $categoryParent*/ |
||
| 1047 | |||
| 1048 | foreach ($path as $categoryParent) { |
||
| 1049 | $visibility = $categoryParent->getVisibility(); |
||
| 1050 | |||
| 1051 | if ($visibility == 0) { |
||
| 1052 | $categoryParentId = $categoryId; |
||
| 1053 | $categoryTitle = $cat['title']; |
||
| 1054 | if (count($path) > 1) { |
||
| 1055 | continue; |
||
| 1056 | } |
||
| 1057 | } else { |
||
| 1058 | $categoryParentId = $categoryParent->getIid(); |
||
| 1059 | $categoryTitle = $categoryParent->getTitle(); |
||
| 1060 | } |
||
| 1061 | |||
| 1062 | $categoryParentInfo['id'] = $categoryParentId; |
||
| 1063 | $categoryParentInfo['iid'] = $categoryParentId; |
||
| 1064 | $categoryParentInfo['parent_path'] = null; |
||
| 1065 | $categoryParentInfo['title'] = $categoryTitle; |
||
| 1066 | $categoryParentInfo['name'] = $categoryTitle; |
||
| 1067 | $categoryParentInfo['parent_id'] = null; |
||
| 1068 | break; |
||
| 1069 | } |
||
| 1070 | } |
||
| 1071 | $cat['parent_info'] = $categoryParentInfo; |
||
| 1072 | $newCategoryList[$categoryId] = array( |
||
| 1073 | 'category' => $cat, |
||
| 1074 | 'question_list' => $questionList |
||
| 1075 | ); |
||
| 1076 | } |
||
| 1077 | |||
| 1078 | $result['category_with_questions_list'] = $newCategoryList; |
||
| 1079 | } |
||
| 1080 | return $result; |
||
| 1081 | } |
||
| 1082 | |||
| 1083 | /** |
||
| 1084 | * returns the array with the question ID list |
||
| 1085 | * |
||
| 1086 | * @author Olivier Brouckaert |
||
| 1087 | * @return array - question ID list |
||
| 1088 | */ |
||
| 1089 | public function selectQuestionList($from_db = false) |
||
| 1090 | { |
||
| 1091 | if ($from_db && !empty($this->id)) { |
||
| 1092 | $nbQuestions = $this->getQuestionCount(); |
||
| 1093 | $questionSelectionType = $this->getQuestionSelectionType(); |
||
| 1094 | |||
| 1095 | switch ($questionSelectionType) { |
||
| 1096 | case EX_Q_SELECTION_ORDERED: |
||
| 1097 | $questionList = $this->getQuestionOrderedList(); |
||
| 1098 | break; |
||
| 1099 | case EX_Q_SELECTION_RANDOM: |
||
| 1100 | // Not a random exercise, or if there are not at least 2 questions |
||
| 1101 | if ($this->random == 0 || $nbQuestions < 2) { |
||
| 1102 | $questionList = $this->getQuestionOrderedList(); |
||
| 1103 | } else { |
||
| 1104 | $questionList = $this->selectRandomList(); |
||
| 1105 | } |
||
| 1106 | break; |
||
| 1107 | default: |
||
| 1108 | $questionList = $this->getQuestionOrderedList(); |
||
| 1109 | $result = $this->getQuestionListWithCategoryListFilteredByCategorySettings( |
||
| 1110 | $questionList, |
||
| 1111 | $questionSelectionType |
||
| 1112 | ); |
||
| 1113 | $this->categoryWithQuestionList = $result['category_with_questions_list']; |
||
| 1114 | $questionList = $result['question_list']; |
||
| 1115 | break; |
||
| 1116 | } |
||
| 1117 | |||
| 1118 | return $questionList; |
||
| 1119 | } |
||
| 1120 | |||
| 1121 | return $this->questionList; |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | /** |
||
| 1125 | * returns the number of questions in this exercise |
||
| 1126 | * |
||
| 1127 | * @author Olivier Brouckaert |
||
| 1128 | * @return integer - number of questions |
||
| 1129 | */ |
||
| 1130 | public function selectNbrQuestions() |
||
| 1131 | { |
||
| 1132 | return sizeof($this->questionList); |
||
| 1133 | } |
||
| 1134 | |||
| 1135 | /** |
||
| 1136 | * @return int |
||
| 1137 | */ |
||
| 1138 | public function selectPropagateNeg() |
||
| 1139 | { |
||
| 1140 | return $this->propagate_neg; |
||
| 1141 | } |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * @return int |
||
| 1145 | */ |
||
| 1146 | public function selectSaveCorrectAnswers() |
||
| 1147 | { |
||
| 1148 | return $this->saveCorrectAnswers; |
||
| 1149 | } |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Selects questions randomly in the question list |
||
| 1153 | * |
||
| 1154 | * @author Olivier Brouckaert |
||
| 1155 | * @author Hubert Borderiou 15 nov 2011 |
||
| 1156 | * @return array - if the exercise is not set to take questions randomly, returns the question list |
||
| 1157 | * without randomizing, otherwise, returns the list with questions selected randomly |
||
| 1158 | */ |
||
| 1159 | public function selectRandomList() |
||
| 1160 | { |
||
| 1161 | /*$nbQuestions = $this->selectNbrQuestions(); |
||
| 1162 | $temp_list = $this->questionList; |
||
| 1163 | |||
| 1164 | //Not a random exercise, or if there are not at least 2 questions |
||
| 1165 | if($this->random == 0 || $nbQuestions < 2) { |
||
| 1166 | return $this->questionList; |
||
| 1167 | } |
||
| 1168 | if ($nbQuestions != 0) { |
||
| 1169 | shuffle($temp_list); |
||
| 1170 | $my_random_list = array_combine(range(1,$nbQuestions),$temp_list); |
||
| 1171 | $my_question_list = array(); |
||
| 1172 | // $this->random == -1 if random with all questions |
||
| 1173 | if ($this->random > 0) { |
||
| 1174 | $i = 0; |
||
| 1175 | foreach ($my_random_list as $item) { |
||
| 1176 | if ($i < $this->random) { |
||
| 1177 | $my_question_list[$i] = $item; |
||
| 1178 | } else { |
||
| 1179 | break; |
||
| 1180 | } |
||
| 1181 | $i++; |
||
| 1182 | } |
||
| 1183 | } else { |
||
| 1184 | $my_question_list = $my_random_list; |
||
| 1185 | } |
||
| 1186 | return $my_question_list; |
||
| 1187 | }*/ |
||
| 1188 | |||
| 1189 | $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
||
| 1190 | $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
||
| 1191 | |||
| 1192 | $random = isset($this->random) && !empty($this->random) ? $this->random : 0; |
||
| 1193 | |||
| 1194 | $randomLimit = "LIMIT $random"; |
||
| 1195 | // Random all questions so no limit |
||
| 1196 | if ($random == -1) { |
||
| 1197 | $randomLimit = null; |
||
| 1198 | } |
||
| 1199 | |||
| 1200 | $sql = "SELECT e.question_id |
||
| 1201 | FROM $TBL_EXERCISE_QUESTION e |
||
| 1202 | INNER JOIN $TBL_QUESTIONS q |
||
| 1203 | ON (e.question_id= q.iid AND e.c_id = q.c_id) |
||
| 1204 | WHERE e.c_id = {$this->course_id} AND e.exercice_id = '".Database::escape_string($this->id)."' |
||
| 1205 | ORDER BY RAND() |
||
| 1206 | $randomLimit "; |
||
| 1207 | $result = Database::query($sql); |
||
| 1208 | $questionList = array(); |
||
| 1209 | while ($row = Database::fetch_object($result)) { |
||
| 1210 | $questionList[] = $row->question_id; |
||
| 1211 | } |
||
| 1212 | |||
| 1213 | return $questionList; |
||
| 1214 | } |
||
| 1215 | |||
| 1216 | /** |
||
| 1217 | * returns 'true' if the question ID is in the question list |
||
| 1218 | * |
||
| 1219 | * @author Olivier Brouckaert |
||
| 1220 | * @param integer $questionId - question ID |
||
| 1221 | * @return boolean - true if in the list, otherwise false |
||
| 1222 | */ |
||
| 1223 | public function isInList($questionId) |
||
| 1224 | { |
||
| 1225 | if (is_array($this->questionList)) { |
||
| 1226 | return in_array($questionId, $this->questionList); |
||
| 1227 | } else { |
||
| 1228 | return false; |
||
| 1229 | } |
||
| 1230 | } |
||
| 1231 | |||
| 1232 | /** |
||
| 1233 | * changes the exercise title |
||
| 1234 | * |
||
| 1235 | * @author Olivier Brouckaert |
||
| 1236 | * @param string $title - exercise title |
||
| 1237 | */ |
||
| 1238 | public function updateTitle($title) |
||
| 1239 | { |
||
| 1240 | $this->exercise=$title; |
||
| 1241 | } |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * changes the exercise max attempts |
||
| 1245 | * |
||
| 1246 | * @param int $attempts - exercise max attempts |
||
| 1247 | */ |
||
| 1248 | public function updateAttempts($attempts) |
||
| 1249 | { |
||
| 1250 | $this->attempts=$attempts; |
||
| 1251 | } |
||
| 1252 | |||
| 1253 | /** |
||
| 1254 | * changes the exercise feedback type |
||
| 1255 | * |
||
| 1256 | * @param int $feedback_type |
||
| 1257 | */ |
||
| 1258 | public function updateFeedbackType($feedback_type) |
||
| 1259 | { |
||
| 1260 | $this->feedback_type=$feedback_type; |
||
| 1261 | } |
||
| 1262 | |||
| 1263 | /** |
||
| 1264 | * changes the exercise description |
||
| 1265 | * |
||
| 1266 | * @author Olivier Brouckaert |
||
| 1267 | * @param string $description - exercise description |
||
| 1268 | */ |
||
| 1269 | public function updateDescription($description) |
||
| 1270 | { |
||
| 1271 | $this->description=$description; |
||
| 1272 | } |
||
| 1273 | |||
| 1274 | /** |
||
| 1275 | * changes the exercise expired_time |
||
| 1276 | * |
||
| 1277 | * @author Isaac flores |
||
| 1278 | * @param int $expired_time The expired time of the quiz |
||
| 1279 | */ |
||
| 1280 | public function updateExpiredTime($expired_time) |
||
| 1281 | { |
||
| 1282 | $this->expired_time = $expired_time; |
||
| 1283 | } |
||
| 1284 | |||
| 1285 | /** |
||
| 1286 | * @param $value |
||
| 1287 | */ |
||
| 1288 | public function updatePropagateNegative($value) |
||
| 1289 | { |
||
| 1290 | $this->propagate_neg = $value; |
||
| 1291 | } |
||
| 1292 | |||
| 1293 | /** |
||
| 1294 | * @param $value int |
||
| 1295 | */ |
||
| 1296 | public function updateSaveCorrectAnswers($value) |
||
| 1297 | { |
||
| 1298 | $this->saveCorrectAnswers = $value; |
||
| 1299 | } |
||
| 1300 | |||
| 1301 | /** |
||
| 1302 | * @param $value |
||
| 1303 | */ |
||
| 1304 | public function updateReviewAnswers($value) |
||
| 1305 | { |
||
| 1306 | $this->review_answers = isset($value) && $value ? true : false; |
||
| 1307 | } |
||
| 1308 | |||
| 1309 | /** |
||
| 1310 | * @param $value |
||
| 1311 | */ |
||
| 1312 | public function updatePassPercentage($value) |
||
| 1313 | { |
||
| 1314 | $this->pass_percentage = $value; |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | /** |
||
| 1318 | * @param string $text |
||
| 1319 | */ |
||
| 1320 | public function updateEmailNotificationTemplate($text) |
||
| 1321 | { |
||
| 1322 | $this->emailNotificationTemplate = $text; |
||
| 1323 | } |
||
| 1324 | |||
| 1325 | /** |
||
| 1326 | * @param string $text |
||
| 1327 | */ |
||
| 1328 | public function updateEmailNotificationTemplateToUser($text) |
||
| 1329 | { |
||
| 1330 | $this->emailNotificationTemplateToUser = $text; |
||
| 1331 | } |
||
| 1332 | |||
| 1333 | /** |
||
| 1334 | * @param string $value |
||
| 1335 | */ |
||
| 1336 | public function setNotifyUserByEmail($value) |
||
| 1337 | { |
||
| 1338 | $this->notifyUserByEmail = $value; |
||
| 1339 | } |
||
| 1340 | |||
| 1341 | /** |
||
| 1342 | * @param int $value |
||
| 1343 | */ |
||
| 1344 | public function updateEndButton($value) |
||
| 1345 | { |
||
| 1346 | $this->endButton = intval($value); |
||
| 1347 | } |
||
| 1348 | |||
| 1349 | /** |
||
| 1350 | * @param string $value |
||
| 1351 | */ |
||
| 1352 | public function setOnSuccessMessage($value) |
||
| 1353 | { |
||
| 1354 | $this->onSuccessMessage = $value; |
||
| 1355 | } |
||
| 1356 | |||
| 1357 | /** |
||
| 1358 | * @param string $value |
||
| 1359 | */ |
||
| 1360 | public function setOnFailedMessage($value) |
||
| 1361 | { |
||
| 1362 | $this->onFailedMessage = $value; |
||
| 1363 | } |
||
| 1364 | |||
| 1365 | /** |
||
| 1366 | * @param $value |
||
| 1367 | */ |
||
| 1368 | public function setModelType($value) |
||
| 1369 | { |
||
| 1370 | $this->modelType = intval($value); |
||
| 1371 | } |
||
| 1372 | |||
| 1373 | /** |
||
| 1374 | * @param int $value |
||
| 1375 | */ |
||
| 1376 | public function setQuestionSelectionType($value) |
||
| 1377 | { |
||
| 1378 | $this->questionSelectionType = intval($value); |
||
| 1379 | } |
||
| 1380 | |||
| 1381 | /** |
||
| 1382 | * @return int |
||
| 1383 | */ |
||
| 1384 | public function getQuestionSelectionType() |
||
| 1385 | { |
||
| 1386 | return $this->questionSelectionType; |
||
| 1387 | } |
||
| 1388 | |||
| 1389 | /** |
||
| 1390 | * @param array $categories |
||
| 1391 | */ |
||
| 1392 | public function updateCategories($categories) |
||
| 1393 | { |
||
| 1394 | if (!empty($categories)) { |
||
| 1395 | $categories = array_map('intval', $categories); |
||
| 1396 | $this->categories = $categories; |
||
| 1397 | } |
||
| 1398 | } |
||
| 1399 | |||
| 1400 | /** |
||
| 1401 | * changes the exercise sound file |
||
| 1402 | * |
||
| 1403 | * @author Olivier Brouckaert |
||
| 1404 | * @param string $sound - exercise sound file |
||
| 1405 | * @param string $delete - ask to delete the file |
||
| 1406 | */ |
||
| 1407 | public function updateSound($sound,$delete) |
||
| 1408 | { |
||
| 1409 | global $audioPath, $documentPath; |
||
| 1410 | $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT); |
||
| 1411 | |||
| 1412 | if ($sound['size'] && (strstr($sound['type'],'audio') || strstr($sound['type'],'video'))) { |
||
| 1413 | $this->sound=$sound['name']; |
||
| 1414 | |||
| 1415 | if (@move_uploaded_file($sound['tmp_name'],$audioPath.'/'.$this->sound)) { |
||
| 1416 | $sql = "SELECT 1 FROM $TBL_DOCUMENT |
||
| 1417 | WHERE c_id = ".$this->course_id." AND path='".str_replace($documentPath,'',$audioPath).'/'.$this->sound."'"; |
||
| 1418 | $result = Database::query($sql); |
||
| 1419 | |||
| 1420 | if (!Database::num_rows($result)) { |
||
| 1421 | $id = add_document( |
||
| 1422 | $this->course, |
||
| 1423 | str_replace($documentPath,'',$audioPath).'/'.$this->sound, |
||
| 1424 | 'file', |
||
| 1425 | $sound['size'], |
||
| 1426 | $sound['name'] |
||
| 1427 | ); |
||
| 1428 | api_item_property_update( |
||
| 1429 | $this->course, |
||
| 1430 | TOOL_DOCUMENT, |
||
| 1431 | $id, |
||
| 1432 | 'DocumentAdded', |
||
| 1433 | api_get_user_id() |
||
| 1434 | ); |
||
| 1435 | item_property_update_on_folder( |
||
| 1436 | $this->course, |
||
| 1437 | str_replace($documentPath, '', $audioPath), |
||
| 1438 | api_get_user_id() |
||
| 1439 | ); |
||
| 1440 | } |
||
| 1441 | } |
||
| 1442 | } elseif($delete && is_file($audioPath.'/'.$this->sound)) { |
||
| 1443 | $this->sound=''; |
||
| 1444 | } |
||
| 1445 | } |
||
| 1446 | |||
| 1447 | /** |
||
| 1448 | * changes the exercise type |
||
| 1449 | * |
||
| 1450 | * @author Olivier Brouckaert |
||
| 1451 | * @param integer $type - exercise type |
||
| 1452 | */ |
||
| 1453 | public function updateType($type) |
||
| 1454 | { |
||
| 1455 | $this->type = $type; |
||
| 1456 | } |
||
| 1457 | |||
| 1458 | /** |
||
| 1459 | * sets to 0 if questions are not selected randomly |
||
| 1460 | * if questions are selected randomly, sets the draws |
||
| 1461 | * |
||
| 1462 | * @author Olivier Brouckaert |
||
| 1463 | * @param integer $random - 0 if not random, otherwise the draws |
||
| 1464 | */ |
||
| 1465 | public function setRandom($random) |
||
| 1466 | { |
||
| 1467 | /*if ($random == 'all') { |
||
| 1468 | $random = $this->selectNbrQuestions(); |
||
| 1469 | }*/ |
||
| 1470 | $this->random = $random; |
||
| 1471 | } |
||
| 1472 | |||
| 1473 | /** |
||
| 1474 | * sets to 0 if answers are not selected randomly |
||
| 1475 | * if answers are selected randomly |
||
| 1476 | * @author Juan Carlos Rana |
||
| 1477 | * @param integer $random_answers - random answers |
||
| 1478 | */ |
||
| 1479 | public function updateRandomAnswers($random_answers) |
||
| 1480 | { |
||
| 1481 | $this->random_answers = $random_answers; |
||
| 1482 | } |
||
| 1483 | |||
| 1484 | /** |
||
| 1485 | * enables the exercise |
||
| 1486 | * |
||
| 1487 | * @author Olivier Brouckaert |
||
| 1488 | */ |
||
| 1489 | public function enable() |
||
| 1490 | { |
||
| 1491 | $this->active=1; |
||
| 1492 | } |
||
| 1493 | |||
| 1494 | /** |
||
| 1495 | * disables the exercise |
||
| 1496 | * |
||
| 1497 | * @author Olivier Brouckaert |
||
| 1498 | */ |
||
| 1499 | public function disable() |
||
| 1500 | { |
||
| 1501 | $this->active=0; |
||
| 1502 | } |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Set disable results |
||
| 1506 | */ |
||
| 1507 | public function disable_results() |
||
| 1508 | { |
||
| 1509 | $this->results_disabled = true; |
||
| 1510 | } |
||
| 1511 | |||
| 1512 | /** |
||
| 1513 | * Enable results |
||
| 1514 | */ |
||
| 1515 | public function enable_results() |
||
| 1516 | { |
||
| 1517 | $this->results_disabled = false; |
||
| 1518 | } |
||
| 1519 | |||
| 1520 | /** |
||
| 1521 | * @param int $results_disabled |
||
| 1522 | */ |
||
| 1523 | public function updateResultsDisabled($results_disabled) |
||
| 1524 | { |
||
| 1525 | $this->results_disabled = intval($results_disabled); |
||
| 1526 | } |
||
| 1527 | |||
| 1528 | /** |
||
| 1529 | * updates the exercise in the data base |
||
| 1530 | * |
||
| 1531 | * @author Olivier Brouckaert |
||
| 1532 | */ |
||
| 1533 | public function save($type_e = '') |
||
| 1534 | { |
||
| 1535 | $_course = $this->course; |
||
| 1536 | $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); |
||
| 1537 | |||
| 1538 | $id = $this->id; |
||
| 1539 | $exercise = $this->exercise; |
||
| 1540 | $description = $this->description; |
||
| 1541 | $sound = $this->sound; |
||
| 1542 | $type = $this->type; |
||
| 1543 | $attempts = isset($this->attempts) ? $this->attempts : 0; |
||
| 1544 | $feedback_type = isset($this->feedback_type) ? $this->feedback_type : 0; |
||
| 1545 | $random = $this->random; |
||
| 1546 | $random_answers = $this->random_answers; |
||
| 1547 | $active = $this->active; |
||
| 1548 | $propagate_neg = (int) $this->propagate_neg; |
||
| 1549 | $saveCorrectAnswers = isset($this->saveCorrectAnswers) && $this->saveCorrectAnswers ? 1 : 0; |
||
| 1550 | $review_answers = isset($this->review_answers) && $this->review_answers ? 1 : 0; |
||
| 1551 | $randomByCat = intval($this->randomByCat); |
||
| 1552 | $text_when_finished = $this->text_when_finished; |
||
| 1553 | $display_category_name = intval($this->display_category_name); |
||
| 1554 | $pass_percentage = intval($this->pass_percentage); |
||
| 1555 | $session_id = $this->sessionId; |
||
| 1556 | |||
| 1557 | //If direct we do not show results |
||
| 1558 | if ($feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) { |
||
| 1559 | $results_disabled = 0; |
||
| 1560 | } else { |
||
| 1561 | $results_disabled = intval($this->results_disabled); |
||
| 1562 | } |
||
| 1563 | |||
| 1564 | $expired_time = intval($this->expired_time); |
||
| 1565 | |||
| 1566 | // Exercise already exists |
||
| 1567 | if ($id) { |
||
| 1568 | // we prepare date in the database using the api_get_utc_datetime() function |
||
| 1569 | if (!empty($this->start_time)) { |
||
| 1570 | $start_time = $this->start_time; |
||
| 1571 | } else { |
||
| 1572 | $start_time = null; |
||
| 1573 | } |
||
| 1574 | |||
| 1575 | if (!empty($this->end_time)) { |
||
| 1576 | $end_time = $this->end_time; |
||
| 1577 | } else { |
||
| 1578 | $end_time = null; |
||
| 1579 | } |
||
| 1580 | |||
| 1581 | $params = [ |
||
| 1582 | 'title' => $exercise, |
||
| 1583 | 'description' => $description, |
||
| 1584 | ]; |
||
| 1585 | |||
| 1586 | $paramsExtra = []; |
||
| 1587 | if ($type_e != 'simple') { |
||
| 1588 | $paramsExtra = [ |
||
| 1589 | 'sound' => $sound, |
||
| 1590 | 'type' => $type, |
||
| 1591 | 'random' => $random, |
||
| 1592 | 'random_answers' => $random_answers, |
||
| 1593 | 'active' => $active, |
||
| 1594 | 'feedback_type' => $feedback_type, |
||
| 1595 | 'start_time' => $start_time, |
||
| 1596 | 'end_time' => $end_time, |
||
| 1597 | 'max_attempt' => $attempts, |
||
| 1598 | 'expired_time' => $expired_time, |
||
| 1599 | 'propagate_neg' => $propagate_neg, |
||
| 1600 | 'save_correct_answers' => $saveCorrectAnswers, |
||
| 1601 | 'review_answers' => $review_answers, |
||
| 1602 | 'random_by_category' => $randomByCat, |
||
| 1603 | 'text_when_finished' => $text_when_finished, |
||
| 1604 | 'display_category_name' => $display_category_name, |
||
| 1605 | 'pass_percentage' => $pass_percentage, |
||
| 1606 | 'results_disabled' => $results_disabled, |
||
| 1607 | 'question_selection_type' => $this->getQuestionSelectionType(), |
||
| 1608 | 'hide_question_title' => $this->getHideQuestionTitle() |
||
| 1609 | ]; |
||
| 1610 | } |
||
| 1611 | |||
| 1612 | $params = array_merge($params, $paramsExtra); |
||
| 1613 | |||
| 1614 | Database::update( |
||
| 1615 | $TBL_EXERCISES, |
||
| 1616 | $params, |
||
| 1617 | ['c_id = ? AND id = ?' => [$this->course_id, $id]] |
||
| 1618 | ); |
||
| 1619 | |||
| 1620 | // update into the item_property table |
||
| 1621 | api_item_property_update( |
||
| 1622 | $_course, |
||
| 1623 | TOOL_QUIZ, |
||
| 1624 | $id, |
||
| 1625 | 'QuizUpdated', |
||
| 1626 | api_get_user_id() |
||
| 1627 | ); |
||
| 1628 | |||
| 1629 | if (api_get_setting('search_enabled')=='true') { |
||
| 1630 | $this->search_engine_edit(); |
||
| 1631 | } |
||
| 1632 | } else { |
||
| 1633 | // Creates a new exercise |
||
| 1634 | |||
| 1635 | // In this case of new exercise, we don't do the api_get_utc_datetime() |
||
| 1636 | // for date because, bellow, we call function api_set_default_visibility() |
||
| 1637 | // In this function, api_set_default_visibility, |
||
| 1638 | // the Quiz is saved too, with an $id and api_get_utc_datetime() is done. |
||
| 1639 | // If we do it now, it will be done twice (cf. https://support.chamilo.org/issues/6586) |
||
| 1640 | if (!empty($this->start_time)) { |
||
| 1641 | $start_time = $this->start_time; |
||
| 1642 | } else { |
||
| 1643 | $start_time = null; |
||
| 1644 | } |
||
| 1645 | |||
| 1646 | if (!empty($this->end_time)) { |
||
| 1647 | $end_time = $this->end_time; |
||
| 1648 | } else { |
||
| 1649 | $end_time = null; |
||
| 1650 | } |
||
| 1651 | |||
| 1652 | $params = [ |
||
| 1653 | 'c_id' => $this->course_id, |
||
| 1654 | 'start_time' => $start_time, |
||
| 1655 | 'end_time' => $end_time, |
||
| 1656 | 'title' => $exercise, |
||
| 1657 | 'description' => $description, |
||
| 1658 | 'sound' => $sound, |
||
| 1659 | 'type' => $type, |
||
| 1660 | 'random' => $random, |
||
| 1661 | 'random_answers' => $random_answers, |
||
| 1662 | 'active' => $active, |
||
| 1663 | 'results_disabled' => $results_disabled, |
||
| 1664 | 'max_attempt' => $attempts, |
||
| 1665 | 'feedback_type' => $feedback_type, |
||
| 1666 | 'expired_time' => $expired_time, |
||
| 1667 | 'session_id' => $session_id, |
||
| 1668 | 'review_answers' => $review_answers, |
||
| 1669 | 'random_by_category' => $randomByCat, |
||
| 1670 | 'text_when_finished' => $text_when_finished, |
||
| 1671 | 'display_category_name' => $display_category_name, |
||
| 1672 | 'pass_percentage' => $pass_percentage, |
||
| 1673 | 'save_correct_answers' => (int) $saveCorrectAnswers, |
||
| 1674 | 'propagate_neg' => $propagate_neg, |
||
| 1675 | 'hide_question_title' => $this->getHideQuestionTitle() |
||
| 1676 | ]; |
||
| 1677 | |||
| 1678 | $this->id = Database::insert($TBL_EXERCISES, $params); |
||
| 1679 | |||
| 1680 | if ($this->id) { |
||
| 1681 | |||
| 1682 | $sql = "UPDATE $TBL_EXERCISES SET id = iid WHERE iid = {$this->id} "; |
||
| 1683 | Database::query($sql); |
||
| 1684 | |||
| 1685 | $sql = "UPDATE $TBL_EXERCISES |
||
| 1686 | SET question_selection_type= ".intval($this->getQuestionSelectionType())." |
||
| 1687 | WHERE id = ".$this->id." AND c_id = ".$this->course_id; |
||
| 1688 | Database::query($sql); |
||
| 1689 | |||
| 1690 | // insert into the item_property table |
||
| 1691 | api_item_property_update( |
||
| 1692 | $this->course, |
||
| 1693 | TOOL_QUIZ, |
||
| 1694 | $this->id, |
||
| 1695 | 'QuizAdded', |
||
| 1696 | api_get_user_id() |
||
| 1697 | ); |
||
| 1698 | |||
| 1699 | // This function save the quiz again, carefull about start_time |
||
| 1700 | // and end_time if you remove this line (see above) |
||
| 1701 | api_set_default_visibility( |
||
| 1702 | $this->id, |
||
| 1703 | TOOL_QUIZ, |
||
| 1704 | null, |
||
| 1705 | $this->course |
||
| 1706 | ); |
||
| 1707 | |||
| 1708 | if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) { |
||
| 1709 | $this->search_engine_save(); |
||
| 1710 | } |
||
| 1711 | } |
||
| 1712 | } |
||
| 1713 | |||
| 1714 | $this->save_categories_in_exercise($this->categories); |
||
| 1715 | |||
| 1716 | // Updates the question position |
||
| 1717 | $this->update_question_positions(); |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | /** |
||
| 1721 | * Updates question position |
||
| 1722 | */ |
||
| 1723 | public function update_question_positions() |
||
| 1724 | { |
||
| 1725 | $quiz_question_table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); |
||
| 1726 | //Fixes #3483 when updating order |
||
| 1727 | $question_list = $this->selectQuestionList(true); |
||
| 1728 | if (!empty($question_list)) { |
||
| 1729 | foreach ($question_list as $position => $questionId) { |
||
| 1730 | $sql = "UPDATE $quiz_question_table SET |
||
| 1731 | question_order ='".intval($position)."' |
||
| 1732 | WHERE |
||
| 1733 | c_id = ".$this->course_id." AND |
||
| 1734 | question_id = ".intval($questionId)." AND |
||
| 1735 | exercice_id=".intval($this->id); |
||
| 1736 | Database::query($sql); |
||
| 1737 | } |
||
| 1738 | } |
||
| 1739 | } |
||
| 1740 | |||
| 1741 | /** |
||
| 1742 | * Adds a question into the question list |
||
| 1743 | * |
||
| 1744 | * @author Olivier Brouckaert |
||
| 1745 | * @param integer $questionId - question ID |
||
| 1746 | * @return boolean - true if the question has been added, otherwise false |
||
| 1747 | */ |
||
| 1748 | public function addToList($questionId) |
||
| 1749 | { |
||
| 1750 | // checks if the question ID is not in the list |
||
| 1751 | if (!$this->isInList($questionId)) { |
||
| 1752 | // selects the max position |
||
| 1753 | if (!$this->selectNbrQuestions()) { |
||
| 1754 | $pos = 1; |
||
| 1755 | } else { |
||
| 1756 | if (is_array($this->questionList)) { |
||
| 1757 | $pos = max(array_keys($this->questionList)) + 1; |
||
| 1758 | } |
||
| 1759 | } |
||
| 1760 | $this->questionList[$pos] = $questionId; |
||
| 1761 | |||
| 1762 | return true; |
||
| 1763 | } |
||
| 1764 | |||
| 1765 | return false; |
||
| 1766 | } |
||
| 1767 | |||
| 1768 | /** |
||
| 1769 | * removes a question from the question list |
||
| 1770 | * |
||
| 1771 | * @author Olivier Brouckaert |
||
| 1772 | * @param integer $questionId - question ID |
||
| 1773 | * @return boolean - true if the question has been removed, otherwise false |
||
| 1774 | */ |
||
| 1775 | public function removeFromList($questionId) |
||
| 1776 | { |
||
| 1777 | // searches the position of the question ID in the list |
||
| 1778 | $pos = array_search($questionId,$this->questionList); |
||
| 1779 | |||
| 1780 | // question not found |
||
| 1781 | if ($pos === false) { |
||
| 1782 | return false; |
||
| 1783 | } else { |
||
| 1784 | // dont reduce the number of random question if we use random by category option, or if |
||
| 1785 | // random all questions |
||
| 1786 | if ($this->isRandom() && $this->isRandomByCat() == 0) { |
||
| 1787 | if (count($this->questionList) >= $this->random && $this->random > 0) { |
||
| 1788 | $this->random -= 1; |
||
| 1789 | $this->save(); |
||
| 1790 | } |
||
| 1791 | } |
||
| 1792 | // deletes the position from the array containing the wanted question ID |
||
| 1793 | unset($this->questionList[$pos]); |
||
| 1794 | |||
| 1795 | return true; |
||
| 1796 | } |
||
| 1797 | } |
||
| 1798 | |||
| 1799 | /** |
||
| 1800 | * deletes the exercise from the database |
||
| 1801 | * Notice : leaves the question in the data base |
||
| 1802 | * |
||
| 1803 | * @author Olivier Brouckaert |
||
| 1804 | */ |
||
| 1805 | public function delete() |
||
| 1806 | { |
||
| 1807 | $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST); |
||
| 1808 | $sql = "UPDATE $TBL_EXERCISES SET active='-1' |
||
| 1809 | WHERE c_id = ".$this->course_id." AND id = ".intval($this->id); |
||
| 1810 | Database::query($sql); |
||
| 1811 | api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'QuizDeleted', api_get_user_id()); |
||
| 1812 | api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'delete', api_get_user_id()); |
||
| 1813 | |||
| 1814 | if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian') ) { |
||
| 1815 | $this->search_engine_delete(); |
||
| 1816 | } |
||
| 1817 | } |
||
| 1818 | |||
| 1819 | /** |
||
| 1820 | * Creates the form to create / edit an exercise |
||
| 1821 | * @param FormValidator $form |
||
| 1822 | */ |
||
| 1823 | public function createForm($form, $type='full') |
||
| 1824 | { |
||
| 1825 | if (empty($type)) { |
||
| 1826 | $type = 'full'; |
||
| 1827 | } |
||
| 1828 | |||
| 1829 | // form title |
||
| 1830 | if (!empty($_GET['exerciseId'])) { |
||
| 1831 | $form_title = get_lang('ModifyExercise'); |
||
| 1832 | } else { |
||
| 1833 | $form_title = get_lang('NewEx'); |
||
| 1834 | } |
||
| 1835 | |||
| 1836 | $form->addElement('header', $form_title); |
||
| 1837 | |||
| 1838 | // Title. |
||
| 1839 | $form->addElement( |
||
| 1840 | 'text', |
||
| 1841 | 'exerciseTitle', |
||
| 1842 | get_lang('ExerciseName'), |
||
| 1843 | array('id' => 'exercise_title') |
||
| 1844 | ); |
||
| 1845 | |||
| 1846 | $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters')); |
||
| 1847 | $form->addElement('html', '<div id="advanced_params_options" style="display:none">'); |
||
| 1848 | |||
| 1849 | $editor_config = array( |
||
| 1850 | 'ToolbarSet' => 'TestQuestionDescription', |
||
| 1851 | 'Width' => '100%', |
||
| 1852 | 'Height' => '150', |
||
| 1853 | ); |
||
| 1854 | if (is_array($type)){ |
||
| 1855 | $editor_config = array_merge($editor_config, $type); |
||
| 1856 | } |
||
| 1857 | |||
| 1858 | $form->addHtmlEditor( |
||
| 1859 | 'exerciseDescription', |
||
| 1860 | get_lang('ExerciseDescription'), |
||
| 1861 | false, |
||
| 1862 | false, |
||
| 1863 | $editor_config |
||
| 1864 | ); |
||
| 1865 | |||
| 1866 | if ($type == 'full') { |
||
| 1867 | //Can't modify a DirectFeedback question |
||
| 1868 | if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) { |
||
| 1869 | // feedback type |
||
| 1870 | $radios_feedback = array(); |
||
| 1871 | $radios_feedback[] = $form->createElement( |
||
| 1872 | 'radio', |
||
| 1873 | 'exerciseFeedbackType', |
||
| 1874 | null, |
||
| 1875 | get_lang('ExerciseAtTheEndOfTheTest'), |
||
| 1876 | '0', |
||
| 1877 | array( |
||
| 1878 | 'id' => 'exerciseType_0', |
||
| 1879 | 'onclick' => 'check_feedback()', |
||
| 1880 | ) |
||
| 1881 | ); |
||
| 1882 | |||
| 1883 | View Code Duplication | if (api_get_setting('enable_quiz_scenario') == 'true') { |
|
| 1884 | //Can't convert a question from one feedback to another if there is more than 1 question already added |
||
| 1885 | if ($this->selectNbrQuestions() == 0) { |
||
| 1886 | $radios_feedback[] = $form->createElement( |
||
| 1887 | 'radio', |
||
| 1888 | 'exerciseFeedbackType', |
||
| 1889 | null, |
||
| 1890 | get_lang('DirectFeedback'), |
||
| 1891 | '1', |
||
| 1892 | array( |
||
| 1893 | 'id' => 'exerciseType_1', |
||
| 1894 | 'onclick' => 'check_direct_feedback()', |
||
| 1895 | ) |
||
| 1896 | ); |
||
| 1897 | } |
||
| 1898 | } |
||
| 1899 | |||
| 1900 | $radios_feedback[] = $form->createElement( |
||
| 1901 | 'radio', |
||
| 1902 | 'exerciseFeedbackType', |
||
| 1903 | null, |
||
| 1904 | get_lang('NoFeedback'), |
||
| 1905 | '2', |
||
| 1906 | array('id' => 'exerciseType_2') |
||
| 1907 | ); |
||
| 1908 | $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'),get_lang('FeedbackDisplayOptions'))); |
||
| 1909 | |||
| 1910 | // Type of results display on the final page |
||
| 1911 | $radios_results_disabled = array(); |
||
| 1912 | $radios_results_disabled[] = $form->createElement( |
||
| 1913 | 'radio', |
||
| 1914 | 'results_disabled', |
||
| 1915 | null, |
||
| 1916 | get_lang('ShowScoreAndRightAnswer'), |
||
| 1917 | '0', |
||
| 1918 | array('id' => 'result_disabled_0') |
||
| 1919 | ); |
||
| 1920 | $radios_results_disabled[] = $form->createElement( |
||
| 1921 | 'radio', |
||
| 1922 | 'results_disabled', |
||
| 1923 | null, |
||
| 1924 | get_lang('DoNotShowScoreNorRightAnswer'), |
||
| 1925 | '1', |
||
| 1926 | array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()') |
||
| 1927 | ); |
||
| 1928 | $radios_results_disabled[] = $form->createElement( |
||
| 1929 | 'radio', |
||
| 1930 | 'results_disabled', |
||
| 1931 | null, |
||
| 1932 | get_lang('OnlyShowScore'), |
||
| 1933 | '2', |
||
| 1934 | array('id' => 'result_disabled_2') |
||
| 1935 | ); |
||
| 1936 | |||
| 1937 | |||
| 1938 | $radios_results_disabled[] = $form->createElement( |
||
| 1939 | 'radio', |
||
| 1940 | 'results_disabled', |
||
| 1941 | null, |
||
| 1942 | get_lang('ShowScoreEveryAttemptShowAnswersLastAttempt'), |
||
| 1943 | '4', |
||
| 1944 | array('id' => 'result_disabled_4') |
||
| 1945 | ); |
||
| 1946 | |||
| 1947 | $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents')); |
||
| 1948 | |||
| 1949 | // Type of questions disposition on page |
||
| 1950 | $radios = array(); |
||
| 1951 | |||
| 1952 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all')); |
||
| 1953 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one')); |
||
| 1954 | |||
| 1955 | $form->addGroup($radios, null, get_lang('QuestionsPerPage')); |
||
| 1956 | |||
| 1957 | } else { |
||
| 1958 | // if is Directfeedback but has not questions we can allow to modify the question type |
||
| 1959 | if ($this->selectNbrQuestions() == 0) { |
||
| 1960 | |||
| 1961 | // feedback type |
||
| 1962 | $radios_feedback = array(); |
||
| 1963 | $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'),'0',array('id' =>'exerciseType_0', 'onclick' => 'check_feedback()')); |
||
| 1964 | |||
| 1965 | View Code Duplication | if (api_get_setting('enable_quiz_scenario') == 'true') { |
|
| 1966 | $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' =>'exerciseType_1' , 'onclick' => 'check_direct_feedback()')); |
||
| 1967 | } |
||
| 1968 | $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'),'2',array('id' =>'exerciseType_2')); |
||
| 1969 | $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'),get_lang('FeedbackDisplayOptions'))); |
||
| 1970 | |||
| 1971 | //$form->addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"'); |
||
| 1972 | $radios_results_disabled = array(); |
||
| 1973 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0')); |
||
| 1974 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()')); |
||
| 1975 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()')); |
||
| 1976 | $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'),''); |
||
| 1977 | |||
| 1978 | // Type of questions disposition on page |
||
| 1979 | $radios = array(); |
||
| 1980 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1'); |
||
| 1981 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2'); |
||
| 1982 | $form->addGroup($radios, null, get_lang('ExerciseType')); |
||
| 1983 | |||
| 1984 | } else { |
||
| 1985 | //Show options freeze |
||
| 1986 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0')); |
||
| 1987 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()')); |
||
| 1988 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()')); |
||
| 1989 | $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents')); |
||
| 1990 | $result_disable_group->freeze(); |
||
| 1991 | |||
| 1992 | //we force the options to the DirectFeedback exercisetype |
||
| 1993 | $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT); |
||
| 1994 | $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE); |
||
| 1995 | |||
| 1996 | // Type of questions disposition on page |
||
| 1997 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all')); |
||
| 1998 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one')); |
||
| 1999 | |||
| 2000 | $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage')); |
||
| 2001 | $type_group->freeze(); |
||
| 2002 | } |
||
| 2003 | } |
||
| 2004 | |||
| 2005 | if (true) { |
||
| 2006 | $option = array( |
||
| 2007 | EX_Q_SELECTION_ORDERED => get_lang('OrderedByUser'), |
||
| 2008 | // defined by user |
||
| 2009 | EX_Q_SELECTION_RANDOM => get_lang('Random'), |
||
| 2010 | // 1-10, All |
||
| 2011 | 'per_categories' => '--------'.get_lang( |
||
| 2012 | 'UsingCategories' |
||
| 2013 | ).'----------', |
||
| 2014 | |||
| 2015 | // Base (A 123 {3} B 456 {3} C 789{2} D 0{0}) --> Matrix {3, 3, 2, 0} |
||
| 2016 | EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED => get_lang( |
||
| 2017 | 'OrderedCategoriesAlphabeticallyWithQuestionsOrdered' |
||
| 2018 | ), |
||
| 2019 | // A 123 B 456 C 78 (0, 1, all) |
||
| 2020 | EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED => get_lang( |
||
| 2021 | 'RandomCategoriesWithQuestionsOrdered' |
||
| 2022 | ), |
||
| 2023 | // C 78 B 456 A 123 |
||
| 2024 | |||
| 2025 | EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_RANDOM => get_lang( |
||
| 2026 | 'OrderedCategoriesAlphabeticallyWithRandomQuestions' |
||
| 2027 | ), |
||
| 2028 | // A 321 B 654 C 87 |
||
| 2029 | EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM => get_lang( |
||
| 2030 | 'RandomCategoriesWithRandomQuestions' |
||
| 2031 | ), |
||
| 2032 | //C 87 B 654 A 321 |
||
| 2033 | |||
| 2034 | //EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED => get_lang('RandomCategoriesWithQuestionsOrderedNoQuestionGrouped'), |
||
| 2035 | /* B 456 C 78 A 123 |
||
| 2036 | 456 78 123 |
||
| 2037 | 123 456 78 |
||
| 2038 | */ |
||
| 2039 | //EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED => get_lang('RandomCategoriesWithRandomQuestionsNoQuestionGrouped'), |
||
| 2040 | /* |
||
| 2041 | A 123 B 456 C 78 |
||
| 2042 | B 456 C 78 A 123 |
||
| 2043 | B 654 C 87 A 321 |
||
| 2044 | 654 87 321 |
||
| 2045 | 165 842 73 |
||
| 2046 | */ |
||
| 2047 | //EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED => get_lang('OrderedCategoriesByParentWithQuestionsOrdered'), |
||
| 2048 | //EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM => get_lang('OrderedCategoriesByParentWithQuestionsRandom'), |
||
| 2049 | ); |
||
| 2050 | |||
| 2051 | $form->addElement( |
||
| 2052 | 'select', |
||
| 2053 | 'question_selection_type', |
||
| 2054 | array(get_lang('QuestionSelection')), |
||
| 2055 | $option, |
||
| 2056 | array( |
||
| 2057 | 'id' => 'questionSelection', |
||
| 2058 | 'onclick' => 'checkQuestionSelection()' |
||
| 2059 | ) |
||
| 2060 | ); |
||
| 2061 | |||
| 2062 | $displayMatrix = 'none'; |
||
| 2063 | $displayRandom = 'none'; |
||
| 2064 | $selectionType = $this->getQuestionSelectionType(); |
||
| 2065 | switch ($selectionType) { |
||
| 2066 | case EX_Q_SELECTION_RANDOM: |
||
| 2067 | $displayRandom = 'block'; |
||
| 2068 | break; |
||
| 2069 | case $selectionType >= EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED: |
||
| 2070 | $displayMatrix = 'block'; |
||
| 2071 | break; |
||
| 2072 | } |
||
| 2073 | |||
| 2074 | $form->addElement( |
||
| 2075 | 'html', |
||
| 2076 | '<div id="hidden_random" style="display:'.$displayRandom.'">' |
||
| 2077 | ); |
||
| 2078 | // Number of random question. |
||
| 2079 | $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10; |
||
| 2080 | $option = range(0, $max); |
||
| 2081 | $option[0] = get_lang('No'); |
||
| 2082 | $option[-1] = get_lang('AllQuestionsShort'); |
||
| 2083 | $form->addElement( |
||
| 2084 | 'select', |
||
| 2085 | 'randomQuestions', |
||
| 2086 | array( |
||
| 2087 | get_lang('RandomQuestions'), |
||
| 2088 | get_lang('RandomQuestionsHelp') |
||
| 2089 | ), |
||
| 2090 | $option, |
||
| 2091 | array('id' => 'randomQuestions') |
||
| 2092 | ); |
||
| 2093 | $form->addElement('html', '</div>'); |
||
| 2094 | |||
| 2095 | $form->addElement( |
||
| 2096 | 'html', |
||
| 2097 | '<div id="hidden_matrix" style="display:'.$displayMatrix.'">' |
||
| 2098 | ); |
||
| 2099 | |||
| 2100 | // Category selection. |
||
| 2101 | $cat = new TestCategory(); |
||
| 2102 | $cat_form = $cat->returnCategoryForm($this); |
||
| 2103 | $form->addElement('label', null, $cat_form); |
||
| 2104 | $form->addElement('html', '</div>'); |
||
| 2105 | |||
| 2106 | // Category name. |
||
| 2107 | $radio_display_cat_name = array( |
||
| 2108 | $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'), |
||
| 2109 | $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0') |
||
| 2110 | ); |
||
| 2111 | $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName')); |
||
| 2112 | |||
| 2113 | // Random answers. |
||
| 2114 | $radios_random_answers = array( |
||
| 2115 | $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'), |
||
| 2116 | $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0') |
||
| 2117 | ); |
||
| 2118 | $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers')); |
||
| 2119 | |||
| 2120 | // Hide question title. |
||
| 2121 | $group = array( |
||
| 2122 | $form->createElement('radio', 'hide_question_title', null, get_lang('Yes'), '1'), |
||
| 2123 | $form->createElement('radio', 'hide_question_title', null, get_lang('No'), '0') |
||
| 2124 | ); |
||
| 2125 | $form->addGroup($group, null, get_lang('HideQuestionTitle')); |
||
| 2126 | } else { |
||
| 2127 | |||
| 2128 | // number of random question |
||
| 2129 | /* |
||
| 2130 | $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10 ; |
||
| 2131 | $option = range(0, $max); |
||
| 2132 | $option[0] = get_lang('No'); |
||
| 2133 | $option[-1] = get_lang('AllQuestionsShort'); |
||
| 2134 | $form->addElement('select', 'randomQuestions',array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id'=>'randomQuestions')); |
||
| 2135 | |||
| 2136 | // Random answers |
||
| 2137 | $radios_random_answers = array(); |
||
| 2138 | $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'),'1'); |
||
| 2139 | $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('No'),'0'); |
||
| 2140 | $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), ''); |
||
| 2141 | |||
| 2142 | // Random by category |
||
| 2143 | $form->addElement('html','<div class="clear"> </div>'); |
||
| 2144 | $radiocat = array(); |
||
| 2145 | $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesShuffled'),'1'); |
||
| 2146 | $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesSorted'),'2'); |
||
| 2147 | $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('No'),'0'); |
||
| 2148 | $radioCatGroup = $form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'), ''); |
||
| 2149 | $form->addElement('html','<div class="clear"> </div>'); |
||
| 2150 | |||
| 2151 | // add the radio display the category name for student |
||
| 2152 | $radio_display_cat_name = array(); |
||
| 2153 | $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'); |
||
| 2154 | $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0'); |
||
| 2155 | $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');*/ |
||
| 2156 | } |
||
| 2157 | // Attempts |
||
| 2158 | $attempt_option = range(0, 10); |
||
| 2159 | $attempt_option[0] = get_lang('Infinite'); |
||
| 2160 | |||
| 2161 | $form->addElement( |
||
| 2162 | 'select', |
||
| 2163 | 'exerciseAttempts', |
||
| 2164 | get_lang('ExerciseAttempts'), |
||
| 2165 | $attempt_option, |
||
| 2166 | ['id' => 'exerciseAttempts'] |
||
| 2167 | ); |
||
| 2168 | |||
| 2169 | // Exercise time limit |
||
| 2170 | $form->addElement('checkbox', 'activate_start_date_check',null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()')); |
||
| 2171 | |||
| 2172 | $var = Exercise::selectTimeLimit(); |
||
| 2173 | |||
| 2174 | if (!empty($this->start_time)) { |
||
| 2175 | $form->addElement('html', '<div id="start_date_div" style="display:block;">'); |
||
| 2176 | } else { |
||
| 2177 | $form->addElement('html', '<div id="start_date_div" style="display:none;">'); |
||
| 2178 | } |
||
| 2179 | |||
| 2180 | $form->addElement('date_time_picker', 'start_time'); |
||
| 2181 | |||
| 2182 | $form->addElement('html','</div>'); |
||
| 2183 | |||
| 2184 | $form->addElement('checkbox', 'activate_end_date_check', null , get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()')); |
||
| 2185 | |||
| 2186 | if (!empty($this->end_time)) { |
||
| 2187 | $form->addElement('html', '<div id="end_date_div" style="display:block;">'); |
||
| 2188 | } else { |
||
| 2189 | $form->addElement('html', '<div id="end_date_div" style="display:none;">'); |
||
| 2190 | } |
||
| 2191 | |||
| 2192 | $form->addElement('date_time_picker', 'end_time'); |
||
| 2193 | $form->addElement('html','</div>'); |
||
| 2194 | |||
| 2195 | //$check_option=$this->selectType(); |
||
| 2196 | $diplay = 'block'; |
||
| 2197 | $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults')); |
||
| 2198 | $form->addCheckBox( |
||
| 2199 | 'save_correct_answers', |
||
| 2200 | null, |
||
| 2201 | get_lang('SaveTheCorrectAnswersForTheNextAttempt') |
||
| 2202 | ); |
||
| 2203 | $form->addElement('html','<div class="clear"> </div>'); |
||
| 2204 | $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers')); |
||
| 2205 | |||
| 2206 | $form->addElement('html','<div id="divtimecontrol" style="display:'.$diplay.';">'); |
||
| 2207 | |||
| 2208 | //Timer control |
||
| 2209 | //$time_hours_option = range(0,12); |
||
| 2210 | //$time_minutes_option = range(0,59); |
||
| 2211 | $form->addElement( |
||
| 2212 | 'checkbox', |
||
| 2213 | 'enabletimercontrol', |
||
| 2214 | null, |
||
| 2215 | get_lang('EnableTimerControl'), |
||
| 2216 | array( |
||
| 2217 | 'onclick' => 'option_time_expired()', |
||
| 2218 | 'id' => 'enabletimercontrol', |
||
| 2219 | 'onload' => 'check_load_time()', |
||
| 2220 | ) |
||
| 2221 | ); |
||
| 2222 | |||
| 2223 | $expired_date = (int)$this->selectExpiredTime(); |
||
| 2224 | |||
| 2225 | if (($expired_date!='0')) { |
||
| 2226 | $form->addElement('html','<div id="timercontrol" style="display:block;">'); |
||
| 2227 | } else { |
||
| 2228 | $form->addElement('html','<div id="timercontrol" style="display:none;">'); |
||
| 2229 | } |
||
| 2230 | $form->addText( |
||
| 2231 | 'enabletimercontroltotalminutes', |
||
| 2232 | get_lang('ExerciseTotalDurationInMinutes'), |
||
| 2233 | false, |
||
| 2234 | [ |
||
| 2235 | 'id' => 'enabletimercontroltotalminutes', |
||
| 2236 | 'cols-size' => [2, 2, 8] |
||
| 2237 | ] |
||
| 2238 | ); |
||
| 2239 | $form->addElement('html','</div>'); |
||
| 2240 | |||
| 2241 | $form->addElement( |
||
| 2242 | 'text', |
||
| 2243 | 'pass_percentage', |
||
| 2244 | array(get_lang('PassPercentage'), null, '%'), |
||
| 2245 | array('id' => 'pass_percentage') |
||
| 2246 | ); |
||
| 2247 | |||
| 2248 | $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric'); |
||
| 2249 | $form->addRule('pass_percentage', get_lang('ValueTooSmall'), 'min_numeric_length', 0); |
||
| 2250 | $form->addRule('pass_percentage', get_lang('ValueTooBig'), 'max_numeric_length', 100); |
||
| 2251 | |||
| 2252 | // add the text_when_finished textbox |
||
| 2253 | $form->addHtmlEditor( |
||
| 2254 | 'text_when_finished', |
||
| 2255 | get_lang('TextWhenFinished'), |
||
| 2256 | false, |
||
| 2257 | false, |
||
| 2258 | $editor_config |
||
| 2259 | ); |
||
| 2260 | |||
| 2261 | $defaults = array(); |
||
| 2262 | |||
| 2263 | if (api_get_setting('search_enabled') === 'true') { |
||
| 2264 | require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; |
||
| 2265 | |||
| 2266 | $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument')); |
||
| 2267 | $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage')); |
||
| 2268 | |||
| 2269 | $specific_fields = get_specific_field_list(); |
||
| 2270 | |||
| 2271 | foreach ($specific_fields as $specific_field) { |
||
| 2272 | $form->addElement ('text', $specific_field['code'], $specific_field['name']); |
||
| 2273 | $filter = array( |
||
| 2274 | 'c_id' => api_get_course_int_id(), |
||
| 2275 | 'field_id' => $specific_field['id'], |
||
| 2276 | 'ref_id' => $this->id, |
||
| 2277 | 'tool_id' => "'" . TOOL_QUIZ . "'" |
||
| 2278 | ); |
||
| 2279 | $values = get_specific_field_values_list($filter, array('value')); |
||
| 2280 | if ( !empty($values) ) { |
||
| 2281 | $arr_str_values = array(); |
||
| 2282 | foreach ($values as $value) { |
||
| 2283 | $arr_str_values[] = $value['value']; |
||
| 2284 | } |
||
| 2285 | $defaults[$specific_field['code']] = implode(', ', $arr_str_values); |
||
| 2286 | } |
||
| 2287 | } |
||
| 2288 | } |
||
| 2289 | |||
| 2290 | $form->addElement('html','</div>'); //End advanced setting |
||
| 2291 | $form->addElement('html','</div>'); |
||
| 2292 | } |
||
| 2293 | |||
| 2294 | // submit |
||
| 2295 | if (isset($_GET['exerciseId'])) { |
||
| 2296 | $form->addButtonSave(get_lang('ModifyExercise'), 'submitExercise'); |
||
| 2297 | } else { |
||
| 2298 | $form->addButtonUpdate(get_lang('ProcedToQuestions'), 'submitExercise'); |
||
| 2299 | } |
||
| 2300 | |||
| 2301 | $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required'); |
||
| 2302 | |||
| 2303 | if ($type == 'full') { |
||
| 2304 | // rules |
||
| 2305 | $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric'); |
||
| 2306 | $form->addRule('start_time', get_lang('InvalidDate'), 'datetime'); |
||
| 2307 | $form->addRule('end_time', get_lang('InvalidDate'), 'datetime'); |
||
| 2308 | } |
||
| 2309 | |||
| 2310 | // defaults |
||
| 2311 | if ($type=='full') { |
||
| 2312 | if ($this->id > 0) { |
||
| 2313 | if ($this->random > $this->selectNbrQuestions()) { |
||
| 2314 | $defaults['randomQuestions'] = $this->selectNbrQuestions(); |
||
| 2315 | } else { |
||
| 2316 | $defaults['randomQuestions'] = $this->random; |
||
| 2317 | } |
||
| 2318 | |||
| 2319 | $defaults['randomAnswers'] = $this->selectRandomAnswers(); |
||
| 2320 | $defaults['exerciseType'] = $this->selectType(); |
||
| 2321 | $defaults['exerciseTitle'] = $this->get_formated_title(); |
||
| 2322 | $defaults['exerciseDescription'] = $this->selectDescription(); |
||
| 2323 | $defaults['exerciseAttempts'] = $this->selectAttempts(); |
||
| 2324 | $defaults['exerciseFeedbackType'] = $this->selectFeedbackType(); |
||
| 2325 | $defaults['results_disabled'] = $this->selectResultsDisabled(); |
||
| 2326 | $defaults['propagate_neg'] = $this->selectPropagateNeg(); |
||
| 2327 | $defaults['save_correct_answers'] = $this->selectSaveCorrectAnswers(); |
||
| 2328 | $defaults['review_answers'] = $this->review_answers; |
||
| 2329 | $defaults['randomByCat'] = $this->selectRandomByCat(); |
||
| 2330 | $defaults['text_when_finished'] = $this->selectTextWhenFinished(); |
||
| 2331 | $defaults['display_category_name'] = $this->selectDisplayCategoryName(); |
||
| 2332 | $defaults['pass_percentage'] = $this->selectPassPercentage(); |
||
| 2333 | $defaults['question_selection_type'] = $this->getQuestionSelectionType(); |
||
| 2334 | $defaults['hide_question_title'] = $this->getHideQuestionTitle(); |
||
| 2335 | |||
| 2336 | if (!empty($this->start_time)) { |
||
| 2337 | $defaults['activate_start_date_check'] = 1; |
||
| 2338 | } |
||
| 2339 | if (!empty($this->end_time)) { |
||
| 2340 | $defaults['activate_end_date_check'] = 1; |
||
| 2341 | } |
||
| 2342 | |||
| 2343 | $defaults['start_time'] = !empty($this->start_time) ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00'); |
||
| 2344 | $defaults['end_time'] = empty($this->end_time) ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time()+84600); |
||
| 2345 | |||
| 2346 | // Get expired time |
||
| 2347 | if ($this->expired_time != '0') { |
||
| 2348 | $defaults['enabletimercontrol'] = 1; |
||
| 2349 | $defaults['enabletimercontroltotalminutes'] = $this->expired_time; |
||
| 2350 | } else { |
||
| 2351 | $defaults['enabletimercontroltotalminutes'] = 0; |
||
| 2352 | } |
||
| 2353 | } else { |
||
| 2354 | $defaults['exerciseType'] = 2; |
||
| 2355 | $defaults['exerciseAttempts'] = 0; |
||
| 2356 | $defaults['randomQuestions'] = 0; |
||
| 2357 | $defaults['randomAnswers'] = 0; |
||
| 2358 | $defaults['exerciseDescription'] = ''; |
||
| 2359 | $defaults['exerciseFeedbackType'] = 0; |
||
| 2360 | $defaults['results_disabled'] = 0; |
||
| 2361 | $defaults['randomByCat'] = 0; |
||
| 2362 | $defaults['text_when_finished'] = ''; |
||
| 2363 | $defaults['start_time'] = date('Y-m-d 12:00:00'); |
||
| 2364 | $defaults['display_category_name'] = 1; |
||
| 2365 | $defaults['end_time'] = date('Y-m-d 12:00:00', time()+84600); |
||
| 2366 | $defaults['pass_percentage'] = ''; |
||
| 2367 | $defaults['end_button'] = $this->selectEndButton(); |
||
| 2368 | $defaults['question_selection_type'] = 1; |
||
| 2369 | $defaults['hide_question_title'] = 0; |
||
| 2370 | $defaults['on_success_message'] = null; |
||
| 2371 | $defaults['on_failed_message'] = null; |
||
| 2372 | } |
||
| 2373 | } else { |
||
| 2374 | $defaults['exerciseTitle'] = $this->selectTitle(); |
||
| 2375 | $defaults['exerciseDescription'] = $this->selectDescription(); |
||
| 2376 | } |
||
| 2377 | if (api_get_setting('search_enabled') === 'true') { |
||
| 2378 | $defaults['index_document'] = 'checked="checked"'; |
||
| 2379 | } |
||
| 2380 | $form->setDefaults($defaults); |
||
| 2381 | |||
| 2382 | // Freeze some elements. |
||
| 2383 | if ($this->id != 0 && $this->edit_exercise_in_lp == false) { |
||
| 2384 | $elementsToFreeze = array( |
||
| 2385 | 'randomQuestions', |
||
| 2386 | //'randomByCat', |
||
| 2387 | 'exerciseAttempts', |
||
| 2388 | 'propagate_neg', |
||
| 2389 | 'enabletimercontrol', |
||
| 2390 | 'review_answers' |
||
| 2391 | ); |
||
| 2392 | |||
| 2393 | foreach ($elementsToFreeze as $elementName) { |
||
| 2394 | /** @var HTML_QuickForm_element $element */ |
||
| 2395 | $element = $form->getElement($elementName); |
||
| 2396 | $element->freeze(); |
||
| 2397 | } |
||
| 2398 | |||
| 2399 | //$radioCatGroup->freeze(); |
||
| 2400 | } |
||
| 2401 | } |
||
| 2402 | |||
| 2403 | /** |
||
| 2404 | * function which process the creation of exercises |
||
| 2405 | * @param FormValidator $form |
||
| 2406 | * @param string |
||
| 2407 | */ |
||
| 2408 | public function processCreation($form, $type = '') |
||
| 2471 | |||
| 2472 | function search_engine_save() |
||
| 2473 | { |
||
| 2474 | if ($_POST['index_document'] != 1) { |
||
| 2475 | return; |
||
| 2476 | } |
||
| 2477 | $course_id = api_get_course_id(); |
||
| 2478 | |||
| 2479 | require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php'; |
||
| 2480 | require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php'; |
||
| 2481 | require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; |
||
| 2482 | |||
| 2483 | $specific_fields = get_specific_field_list(); |
||
| 2484 | $ic_slide = new IndexableChunk(); |
||
| 2485 | |||
| 2486 | $all_specific_terms = ''; |
||
| 2487 | View Code Duplication | foreach ($specific_fields as $specific_field) { |
|
| 2488 | if (isset($_REQUEST[$specific_field['code']])) { |
||
| 2489 | $sterms = trim($_REQUEST[$specific_field['code']]); |
||
| 2490 | if (!empty($sterms)) { |
||
| 2491 | $all_specific_terms .= ' '. $sterms; |
||
| 2492 | $sterms = explode(',', $sterms); |
||
| 2493 | foreach ($sterms as $sterm) { |
||
| 2494 | $ic_slide->addTerm(trim($sterm), $specific_field['code']); |
||
| 2495 | add_specific_field_value($specific_field['id'], $course_id, TOOL_QUIZ, $this->id, $sterm); |
||
| 2496 | } |
||
| 2497 | } |
||
| 2498 | } |
||
| 2499 | } |
||
| 2500 | |||
| 2501 | // build the chunk to index |
||
| 2502 | $ic_slide->addValue("title", $this->exercise); |
||
| 2503 | $ic_slide->addCourseId($course_id); |
||
| 2504 | $ic_slide->addToolId(TOOL_QUIZ); |
||
| 2505 | $xapian_data = array( |
||
| 2506 | SE_COURSE_ID => $course_id, |
||
| 2507 | SE_TOOL_ID => TOOL_QUIZ, |
||
| 2508 | SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_EXERCISE, 'exercise_id' => (int)$this->id), |
||
| 2509 | SE_USER => (int)api_get_user_id(), |
||
| 2510 | ); |
||
| 2511 | $ic_slide->xapian_data = serialize($xapian_data); |
||
| 2512 | $exercise_description = $all_specific_terms .' '. $this->description; |
||
| 2513 | $ic_slide->addValue("content", $exercise_description); |
||
| 2514 | |||
| 2515 | $di = new ChamiloIndexer(); |
||
| 2516 | isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english'; |
||
| 2517 | $di->connectDb(NULL, NULL, $lang); |
||
| 2518 | $di->addChunk($ic_slide); |
||
| 2519 | |||
| 2520 | //index and return search engine document id |
||
| 2521 | $did = $di->index(); |
||
| 2522 | if ($did) { |
||
| 2523 | // save it to db |
||
| 2524 | $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); |
||
| 2525 | $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did) |
||
| 2526 | VALUES (NULL , \'%s\', \'%s\', %s, %s)'; |
||
| 2527 | $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id, $did); |
||
| 2528 | Database::query($sql); |
||
| 2529 | } |
||
| 2530 | } |
||
| 2531 | |||
| 2532 | function search_engine_edit() |
||
| 2607 | |||
| 2608 | function search_engine_delete() |
||
| 2646 | |||
| 2647 | public function selectExpiredTime() |
||
| 2651 | |||
| 2652 | /** |
||
| 2653 | * Cleans the student's results only for the Exercise tool (Not from the LP) |
||
| 2654 | * The LP results are NOT deleted by default, otherwise put $cleanLpTests = true |
||
| 2655 | * Works with exercises in sessions |
||
| 2656 | * @param bool $cleanLpTests |
||
| 2657 | * @param string $cleanResultBeforeDate |
||
| 2658 | * |
||
| 2659 | * @return int quantity of user's exercises deleted |
||
| 2660 | */ |
||
| 2661 | public function clean_results($cleanLpTests = false, $cleanResultBeforeDate = null) |
||
| 2731 | |||
| 2732 | /** |
||
| 2733 | * Copies an exercise (duplicate all questions and answers) |
||
| 2734 | */ |
||
| 2735 | public function copy_exercise() |
||
| 2769 | |||
| 2770 | /** |
||
| 2771 | * Changes the exercise id |
||
| 2772 | * |
||
| 2773 | * @param int $id - exercise id |
||
| 2774 | */ |
||
| 2775 | private function updateId($id) |
||
| 2779 | |||
| 2780 | /** |
||
| 2781 | * Changes the exercise status |
||
| 2782 | * |
||
| 2783 | * @param string $status - exercise status |
||
| 2784 | */ |
||
| 2785 | function updateStatus($status) |
||
| 2789 | |||
| 2790 | /** |
||
| 2791 | * @param int $lp_id |
||
| 2792 | * @param int $lp_item_id |
||
| 2793 | * @param int $lp_item_view_id |
||
| 2794 | * @param string $status |
||
| 2795 | * @return array |
||
| 2796 | */ |
||
| 2797 | public function get_stat_track_exercise_info( |
||
| 2833 | |||
| 2834 | /** |
||
| 2835 | * Saves a test attempt |
||
| 2836 | * |
||
| 2837 | * @param int clock_expired_time |
||
| 2838 | * @param int int lp id |
||
| 2839 | * @param int int lp item id |
||
| 2840 | * @param int int lp item_view id |
||
| 2841 | * @param float $weight |
||
| 2842 | * @param array question list |
||
| 2843 | */ |
||
| 2844 | public function save_stat_track_exercise_info( |
||
| 2894 | |||
| 2895 | /** |
||
| 2896 | * @param int $question_id |
||
| 2897 | * @param int $questionNum |
||
| 2898 | * @param array $questions_in_media |
||
| 2899 | * @param string $currentAnswer |
||
| 2900 | * @return string |
||
| 2901 | */ |
||
| 2902 | public function show_button($question_id, $questionNum, $questions_in_media = array(), $currentAnswer = '') |
||
| 2988 | |||
| 2989 | /** |
||
| 2990 | * So the time control will work |
||
| 2991 | * |
||
| 2992 | * @param string $time_left |
||
| 2993 | * @return string |
||
| 2994 | */ |
||
| 2995 | public function show_time_control_js($time_left) |
||
| 3083 | |||
| 3084 | /** |
||
| 3085 | * Lp javascript for hotspots |
||
| 3086 | */ |
||
| 3087 | public function show_lp_javascript() |
||
| 3091 | |||
| 3092 | /** |
||
| 3093 | * This function was originally found in the exercise_show.php |
||
| 3094 | * @param int $exeId |
||
| 3095 | * @param int $questionId |
||
| 3096 | * @param int $choice the user selected |
||
| 3097 | * @param string $from function is called from 'exercise_show' or 'exercise_result' |
||
| 3098 | * @param array $exerciseResultCoordinates the hotspot coordinates $hotspot[$question_id] = coordinates |
||
| 3099 | * @param bool $saved_results save results in the DB or just show the reponse |
||
| 3100 | * @param bool $from_database gets information from DB or from the current selection |
||
| 3101 | * @param bool $show_result show results or not |
||
| 3102 | * @param int $propagate_neg |
||
| 3103 | * @param array $hotspot_delineation_result |
||
| 3104 | * @param boolean $showTotalScoreAndUserChoicesInLastAttempt |
||
| 3105 | * @todo reduce parameters of this function |
||
| 3106 | * @return string html code |
||
| 3107 | */ |
||
| 3108 | public function manage_answer( |
||
| 3109 | $exeId, |
||
| 3110 | $questionId, |
||
| 3111 | $choice, |
||
| 3112 | $from = 'exercise_show', |
||
| 3113 | $exerciseResultCoordinates = array(), |
||
| 3114 | $saved_results = true, |
||
| 3115 | $from_database = false, |
||
| 3116 | $show_result = true, |
||
| 3117 | $propagate_neg = 0, |
||
| 3118 | $hotspot_delineation_result = array(), |
||
| 3119 | $showTotalScoreAndUserChoicesInLastAttempt = true |
||
| 3120 | ) { |
||
| 3121 | global $debug; |
||
| 3122 | //needed in order to use in the exercise_attempt() for the time |
||
| 3123 | global $learnpath_id, $learnpath_item_id; |
||
| 3124 | require_once api_get_path(LIBRARY_PATH).'geometry.lib.php'; |
||
| 3125 | |||
| 3126 | $em = Database::getManager(); |
||
| 3127 | |||
| 3128 | $feedback_type = $this->selectFeedbackType(); |
||
| 3129 | $results_disabled = $this->selectResultsDisabled(); |
||
| 3130 | |||
| 3131 | if ($debug) { |
||
| 3132 | error_log("<------ manage_answer ------> "); |
||
| 3133 | error_log('exe_id: '.$exeId); |
||
| 3134 | error_log('$from: '.$from); |
||
| 3135 | error_log('$saved_results: '.intval($saved_results)); |
||
| 3136 | error_log('$from_database: '.intval($from_database)); |
||
| 3137 | error_log('$show_result: '.$show_result); |
||
| 3138 | error_log('$propagate_neg: '.$propagate_neg); |
||
| 3139 | error_log('$exerciseResultCoordinates: '.print_r($exerciseResultCoordinates, 1)); |
||
| 3140 | error_log('$hotspot_delineation_result: '.print_r($hotspot_delineation_result, 1)); |
||
| 3141 | error_log('$learnpath_id: '.$learnpath_id); |
||
| 3142 | error_log('$learnpath_item_id: '.$learnpath_item_id); |
||
| 3143 | error_log('$choice: '.print_r($choice, 1)); |
||
| 3144 | } |
||
| 3145 | |||
| 3146 | $extra_data = array(); |
||
| 3147 | $final_overlap = 0; |
||
| 3148 | $final_missing = 0; |
||
| 3149 | $final_excess = 0; |
||
| 3150 | $overlap_color = 0; |
||
| 3151 | $missing_color = 0; |
||
| 3152 | $excess_color = 0; |
||
| 3153 | $threadhold1 = 0; |
||
| 3154 | $threadhold2 = 0; |
||
| 3155 | $threadhold3 = 0; |
||
| 3156 | |||
| 3157 | $arrques = null; |
||
| 3158 | $arrans = null; |
||
| 3159 | |||
| 3160 | $questionId = intval($questionId); |
||
| 3161 | $exeId = intval($exeId); |
||
| 3162 | $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
||
| 3163 | $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
||
| 3164 | |||
| 3165 | // Creates a temporary Question object |
||
| 3166 | $course_id = $this->course_id; |
||
| 3167 | $objQuestionTmp = Question::read($questionId, $course_id); |
||
| 3168 | |||
| 3169 | if ($objQuestionTmp === false) { |
||
| 3170 | return false; |
||
| 3171 | } |
||
| 3172 | |||
| 3173 | $questionName = $objQuestionTmp->selectTitle(); |
||
| 3174 | $questionWeighting = $objQuestionTmp->selectWeighting(); |
||
| 3175 | $answerType = $objQuestionTmp->selectType(); |
||
| 3176 | $quesId = $objQuestionTmp->selectId(); |
||
| 3177 | $extra = $objQuestionTmp->extra; |
||
| 3178 | |||
| 3179 | $next = 1; //not for now |
||
| 3180 | |||
| 3181 | // Extra information of the question |
||
| 3182 | if (!empty($extra)) { |
||
| 3183 | $extra = explode(':', $extra); |
||
| 3184 | if ($debug) { |
||
| 3185 | error_log(print_r($extra, 1)); |
||
| 3186 | } |
||
| 3187 | // Fixes problems with negatives values using intval |
||
| 3188 | $true_score = floatval(trim($extra[0])); |
||
| 3189 | $false_score = floatval(trim($extra[1])); |
||
| 3190 | $doubt_score = floatval(trim($extra[2])); |
||
| 3191 | } |
||
| 3192 | |||
| 3193 | $totalWeighting = 0; |
||
| 3194 | $totalScore = 0; |
||
| 3195 | |||
| 3196 | // Construction of the Answer object |
||
| 3197 | $objAnswerTmp = new Answer($questionId); |
||
| 3198 | $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); |
||
| 3199 | |||
| 3200 | if ($debug) { |
||
| 3201 | error_log('Count of answers: '.$nbrAnswers); |
||
| 3202 | error_log('$answerType: '.$answerType); |
||
| 3203 | } |
||
| 3204 | |||
| 3205 | if ($answerType == FREE_ANSWER || |
||
| 3206 | $answerType == ORAL_EXPRESSION || |
||
| 3207 | $answerType == CALCULATED_ANSWER |
||
| 3208 | ) { |
||
| 3209 | $nbrAnswers = 1; |
||
| 3210 | } |
||
| 3211 | |||
| 3212 | if ($answerType == ORAL_EXPRESSION) { |
||
| 3213 | $exe_info = Event::get_exercise_results_by_attempt($exeId); |
||
| 3214 | $exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null; |
||
| 3215 | |||
| 3216 | $objQuestionTmp->initFile( |
||
| 3217 | api_get_session_id(), |
||
| 3218 | isset($exe_info['exe_user_id']) ? $exe_info['exe_user_id'] : api_get_user_id(), |
||
| 3219 | isset($exe_info['exe_exo_id']) ? $exe_info['exe_exo_id'] : $this->id, |
||
| 3220 | isset($exe_info['exe_id']) ? $exe_info['exe_id'] : $exeId |
||
| 3221 | ); |
||
| 3222 | |||
| 3223 | //probably this attempt came in an exercise all question by page |
||
| 3224 | if ($feedback_type == 0) { |
||
| 3225 | $objQuestionTmp->replaceWithRealExe($exeId); |
||
| 3226 | } |
||
| 3227 | } |
||
| 3228 | |||
| 3229 | $user_answer = ''; |
||
| 3230 | |||
| 3231 | // Get answer list for matching |
||
| 3232 | $sql = "SELECT id_auto, id, answer |
||
| 3233 | FROM $table_ans |
||
| 3234 | WHERE c_id = $course_id AND question_id = $questionId"; |
||
| 3235 | $res_answer = Database::query($sql); |
||
| 3236 | |||
| 3237 | $answerMatching = array(); |
||
| 3238 | while ($real_answer = Database::fetch_array($res_answer)) { |
||
| 3239 | $answerMatching[$real_answer['id_auto']] = $real_answer['answer']; |
||
| 3240 | } |
||
| 3241 | |||
| 3242 | $real_answers = array(); |
||
| 3243 | $quiz_question_options = Question::readQuestionOption( |
||
| 3244 | $questionId, |
||
| 3245 | $course_id |
||
| 3246 | ); |
||
| 3247 | |||
| 3248 | $organs_at_risk_hit = 0; |
||
| 3249 | $questionScore = 0; |
||
| 3250 | $answer_correct_array = array(); |
||
| 3251 | $orderedHotspots = []; |
||
| 3252 | |||
| 3253 | if ($answerType == HOT_SPOT) { |
||
| 3254 | $orderedHotspots = $em |
||
| 3255 | ->getRepository('ChamiloCoreBundle:TrackEHotspot') |
||
| 3256 | ->findBy([ |
||
| 3257 | 'hotspotQuestionId' => $questionId, |
||
| 3258 | 'cId' => $course_id, |
||
| 3259 | 'hotspotExeId' => $exeId |
||
| 3260 | ], |
||
| 3261 | ['hotspotId' => 'ASC'] |
||
| 3262 | ); |
||
| 3263 | } |
||
| 3264 | |||
| 3265 | if ($debug) error_log('Start answer loop '); |
||
| 3266 | |||
| 3267 | for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
||
| 3268 | $answer = $objAnswerTmp->selectAnswer($answerId); |
||
| 3269 | $answerComment = $objAnswerTmp->selectComment($answerId); |
||
| 3270 | $answerCorrect = $objAnswerTmp->isCorrect($answerId); |
||
| 3271 | $answerWeighting = (float)$objAnswerTmp->selectWeighting($answerId); |
||
| 3272 | $answerAutoId = $objAnswerTmp->selectAutoId($answerId); |
||
| 3273 | $answerIid = isset($objAnswerTmp->iid[$answerId]) ? $objAnswerTmp->iid[$answerId] : ''; |
||
| 3274 | |||
| 3275 | $answer_correct_array[$answerId] = (bool)$answerCorrect; |
||
| 3276 | |||
| 3277 | if ($debug) { |
||
| 3278 | error_log("answer auto id: $answerAutoId "); |
||
| 3279 | error_log("answer correct: $answerCorrect "); |
||
| 3280 | } |
||
| 3281 | |||
| 3282 | // Delineation |
||
| 3283 | $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1); |
||
| 3284 | $answer_delineation_destination=$objAnswerTmp->selectDestination(1); |
||
| 3285 | |||
| 3286 | switch ($answerType) { |
||
| 3287 | // for unique answer |
||
| 3288 | case UNIQUE_ANSWER: |
||
| 3289 | case UNIQUE_ANSWER_IMAGE: |
||
| 3290 | case UNIQUE_ANSWER_NO_OPTION: |
||
| 3291 | if ($from_database) { |
||
| 3292 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3293 | WHERE |
||
| 3294 | exe_id = '".$exeId."' AND |
||
| 3295 | question_id= '".$questionId."'"; |
||
| 3296 | $result = Database::query($sql); |
||
| 3297 | $choice = Database::result($result,0,"answer"); |
||
| 3298 | |||
| 3299 | $studentChoice = $choice == $answerAutoId ? 1 : 0; |
||
| 3300 | if ($studentChoice) { |
||
| 3301 | $questionScore += $answerWeighting; |
||
| 3302 | $totalScore += $answerWeighting; |
||
| 3303 | } |
||
| 3304 | } else { |
||
| 3305 | $studentChoice = $choice == $answerAutoId ? 1 : 0; |
||
| 3306 | if ($studentChoice) { |
||
| 3307 | $questionScore += $answerWeighting; |
||
| 3308 | $totalScore += $answerWeighting; |
||
| 3309 | } |
||
| 3310 | } |
||
| 3311 | break; |
||
| 3312 | // for multiple answers |
||
| 3313 | case MULTIPLE_ANSWER_TRUE_FALSE: |
||
| 3314 | if ($from_database) { |
||
| 3315 | $choice = array(); |
||
| 3316 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3317 | WHERE |
||
| 3318 | exe_id = $exeId AND |
||
| 3319 | question_id = ".$questionId; |
||
| 3320 | |||
| 3321 | $result = Database::query($sql); |
||
| 3322 | View Code Duplication | while ($row = Database::fetch_array($result)) { |
|
| 3323 | $ind = $row['answer']; |
||
| 3324 | $values = explode(':', $ind); |
||
| 3325 | $my_answer_id = isset($values[0]) ? $values[0] : ''; |
||
| 3326 | $option = isset($values[1]) ? $values[1] : ''; |
||
| 3327 | $choice[$my_answer_id] = $option; |
||
| 3328 | } |
||
| 3329 | } |
||
| 3330 | |||
| 3331 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3332 | |||
| 3333 | if (!empty($studentChoice)) { |
||
| 3334 | if ($studentChoice == $answerCorrect) { |
||
| 3335 | $questionScore += $true_score; |
||
| 3336 | } else { |
||
| 3337 | if ($quiz_question_options[$studentChoice]['name'] == "Don't know" || |
||
| 3338 | $quiz_question_options[$studentChoice]['name'] == "DoubtScore" |
||
| 3339 | ) { |
||
| 3340 | $questionScore += $doubt_score; |
||
| 3341 | } else { |
||
| 3342 | $questionScore += $false_score; |
||
| 3343 | } |
||
| 3344 | } |
||
| 3345 | } else { |
||
| 3346 | // If no result then the user just hit don't know |
||
| 3347 | $studentChoice = 3; |
||
| 3348 | $questionScore += $doubt_score; |
||
| 3349 | } |
||
| 3350 | $totalScore = $questionScore; |
||
| 3351 | break; |
||
| 3352 | View Code Duplication | case MULTIPLE_ANSWER: //2 |
|
| 3353 | if ($from_database) { |
||
| 3354 | $choice = array(); |
||
| 3355 | $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3356 | WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; |
||
| 3357 | $resultans = Database::query($sql); |
||
| 3358 | while ($row = Database::fetch_array($resultans)) { |
||
| 3359 | $ind = $row['answer']; |
||
| 3360 | $choice[$ind] = 1; |
||
| 3361 | } |
||
| 3362 | |||
| 3363 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3364 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3365 | |||
| 3366 | if ($studentChoice) { |
||
| 3367 | $questionScore +=$answerWeighting; |
||
| 3368 | } |
||
| 3369 | } else { |
||
| 3370 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3371 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3372 | |||
| 3373 | if (isset($studentChoice)) { |
||
| 3374 | $questionScore += $answerWeighting; |
||
| 3375 | } |
||
| 3376 | } |
||
| 3377 | $totalScore += $answerWeighting; |
||
| 3378 | |||
| 3379 | if ($debug) error_log("studentChoice: $studentChoice"); |
||
| 3380 | break; |
||
| 3381 | View Code Duplication | case GLOBAL_MULTIPLE_ANSWER: |
|
| 3382 | if ($from_database) { |
||
| 3383 | $choice = array(); |
||
| 3384 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3385 | WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; |
||
| 3386 | $resultans = Database::query($sql); |
||
| 3387 | while ($row = Database::fetch_array($resultans)) { |
||
| 3388 | $ind = $row['answer']; |
||
| 3389 | $choice[$ind] = 1; |
||
| 3390 | } |
||
| 3391 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3392 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3393 | if ($studentChoice) { |
||
| 3394 | $questionScore +=$answerWeighting; |
||
| 3395 | } |
||
| 3396 | } else { |
||
| 3397 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3398 | if (isset($studentChoice)) { |
||
| 3399 | $questionScore += $answerWeighting; |
||
| 3400 | } |
||
| 3401 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3402 | } |
||
| 3403 | $totalScore += $answerWeighting; |
||
| 3404 | if ($debug) error_log("studentChoice: $studentChoice"); |
||
| 3405 | break; |
||
| 3406 | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
||
| 3407 | if ($from_database) { |
||
| 3408 | $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3409 | WHERE exe_id = $exeId AND question_id= ".$questionId; |
||
| 3410 | $resultans = Database::query($sql); |
||
| 3411 | View Code Duplication | while ($row = Database::fetch_array($resultans)) { |
|
| 3412 | $ind = $row['answer']; |
||
| 3413 | $result = explode(':',$ind); |
||
| 3414 | if (isset($result[0])) { |
||
| 3415 | $my_answer_id = isset($result[0]) ? $result[0] : ''; |
||
| 3416 | $option = isset($result[1]) ? $result[1] : ''; |
||
| 3417 | $choice[$my_answer_id] = $option; |
||
| 3418 | } |
||
| 3419 | } |
||
| 3420 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : ''; |
||
| 3421 | |||
| 3422 | if ($answerCorrect == $studentChoice) { |
||
| 3423 | //$answerCorrect = 1; |
||
| 3424 | $real_answers[$answerId] = true; |
||
| 3425 | } else { |
||
| 3426 | //$answerCorrect = 0; |
||
| 3427 | $real_answers[$answerId] = false; |
||
| 3428 | } |
||
| 3429 | } else { |
||
| 3430 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : ''; |
||
| 3431 | if ($answerCorrect == $studentChoice) { |
||
| 3432 | //$answerCorrect = 1; |
||
| 3433 | $real_answers[$answerId] = true; |
||
| 3434 | } else { |
||
| 3435 | //$answerCorrect = 0; |
||
| 3436 | $real_answers[$answerId] = false; |
||
| 3437 | } |
||
| 3438 | } |
||
| 3439 | break; |
||
| 3440 | case MULTIPLE_ANSWER_COMBINATION: |
||
| 3441 | if ($from_database) { |
||
| 3442 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3443 | WHERE exe_id = $exeId AND question_id= $questionId"; |
||
| 3444 | $resultans = Database::query($sql); |
||
| 3445 | while ($row = Database::fetch_array($resultans)) { |
||
| 3446 | $ind = $row['answer']; |
||
| 3447 | $choice[$ind] = 1; |
||
| 3448 | } |
||
| 3449 | |||
| 3450 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3451 | |||
| 3452 | View Code Duplication | if ($answerCorrect == 1) { |
|
| 3453 | if ($studentChoice) { |
||
| 3454 | $real_answers[$answerId] = true; |
||
| 3455 | } else { |
||
| 3456 | $real_answers[$answerId] = false; |
||
| 3457 | } |
||
| 3458 | } else { |
||
| 3459 | if ($studentChoice) { |
||
| 3460 | $real_answers[$answerId] = false; |
||
| 3461 | } else { |
||
| 3462 | $real_answers[$answerId] = true; |
||
| 3463 | } |
||
| 3464 | } |
||
| 3465 | } else { |
||
| 3466 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3467 | |||
| 3468 | View Code Duplication | if ($answerCorrect == 1) { |
|
| 3469 | if ($studentChoice) { |
||
| 3470 | $real_answers[$answerId] = true; |
||
| 3471 | } else { |
||
| 3472 | $real_answers[$answerId] = false; |
||
| 3473 | } |
||
| 3474 | } else { |
||
| 3475 | if ($studentChoice) { |
||
| 3476 | $real_answers[$answerId] = false; |
||
| 3477 | } else { |
||
| 3478 | $real_answers[$answerId] = true; |
||
| 3479 | } |
||
| 3480 | } |
||
| 3481 | } |
||
| 3482 | break; |
||
| 3483 | case FILL_IN_BLANKS: |
||
| 3484 | $str = ''; |
||
| 3485 | if ($from_database) { |
||
| 3486 | $sql = "SELECT answer |
||
| 3487 | FROM $TBL_TRACK_ATTEMPT |
||
| 3488 | WHERE |
||
| 3489 | exe_id = $exeId AND |
||
| 3490 | question_id= ".intval($questionId); |
||
| 3491 | $result = Database::query($sql); |
||
| 3492 | $str = Database::result($result, 0, 'answer'); |
||
| 3493 | } |
||
| 3494 | |||
| 3495 | if ($saved_results == false && strpos($str, 'font color') !== false) { |
||
| 3496 | // the question is encoded like this |
||
| 3497 | // [A] B [C] D [E] F::10,10,10@1 |
||
| 3498 | // number 1 before the "@" means that is a switchable fill in blank question |
||
| 3499 | // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 |
||
| 3500 | // means that is a normal fill blank question |
||
| 3501 | // first we explode the "::" |
||
| 3502 | $pre_array = explode('::', $answer); |
||
| 3503 | |||
| 3504 | // is switchable fill blank or not |
||
| 3505 | $last = count($pre_array) - 1; |
||
| 3506 | $is_set_switchable = explode('@', $pre_array[$last]); |
||
| 3507 | $switchable_answer_set = false; |
||
| 3508 | if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) { |
||
| 3509 | $switchable_answer_set = true; |
||
| 3510 | } |
||
| 3511 | $answer = ''; |
||
| 3512 | for ($k = 0; $k < $last; $k++) { |
||
| 3513 | $answer .= $pre_array[$k]; |
||
| 3514 | } |
||
| 3515 | // splits weightings that are joined with a comma |
||
| 3516 | $answerWeighting = explode(',', $is_set_switchable[0]); |
||
| 3517 | // we save the answer because it will be modified |
||
| 3518 | $temp = $answer; |
||
| 3519 | $answer = ''; |
||
| 3520 | $j = 0; |
||
| 3521 | //initialise answer tags |
||
| 3522 | $user_tags = $correct_tags = $real_text = array(); |
||
| 3523 | // the loop will stop at the end of the text |
||
| 3524 | while (1) { |
||
| 3525 | // quits the loop if there are no more blanks (detect '[') |
||
| 3526 | if ($temp == false || ($pos = api_strpos($temp, '[')) === false) { |
||
| 3527 | // adds the end of the text |
||
| 3528 | $answer = $temp; |
||
| 3529 | $real_text[] = $answer; |
||
| 3530 | break; //no more "blanks", quit the loop |
||
| 3531 | } |
||
| 3532 | // adds the piece of text that is before the blank |
||
| 3533 | //and ends with '[' into a general storage array |
||
| 3534 | $real_text[] = api_substr($temp, 0, $pos +1); |
||
| 3535 | $answer .= api_substr($temp, 0, $pos +1); |
||
| 3536 | //take the string remaining (after the last "[" we found) |
||
| 3537 | $temp = api_substr($temp, $pos +1); |
||
| 3538 | // quit the loop if there are no more blanks, and update $pos to the position of next ']' |
||
| 3539 | if (($pos = api_strpos($temp, ']')) === false) { |
||
| 3540 | // adds the end of the text |
||
| 3541 | $answer .= $temp; |
||
| 3542 | break; |
||
| 3543 | } |
||
| 3544 | if ($from_database) { |
||
| 3545 | $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3546 | WHERE |
||
| 3547 | exe_id = '".$exeId."' AND |
||
| 3548 | question_id= ".intval($questionId).""; |
||
| 3549 | $resfill = Database::query($queryfill); |
||
| 3550 | $str = Database::result($resfill, 0, 'answer'); |
||
| 3551 | api_preg_match_all('#\[([^[]*)\]#', $str, $arr); |
||
| 3552 | $str = str_replace('\r\n', '', $str); |
||
| 3553 | |||
| 3554 | $choice = $arr[1]; |
||
| 3555 | if (isset($choice[$j])) { |
||
| 3556 | $tmp = api_strrpos($choice[$j], ' / '); |
||
| 3557 | $choice[$j] = api_substr($choice[$j], 0, $tmp); |
||
| 3558 | $choice[$j] = trim($choice[$j]); |
||
| 3559 | // Needed to let characters ' and " to work as part of an answer |
||
| 3560 | $choice[$j] = stripslashes($choice[$j]); |
||
| 3561 | } else { |
||
| 3562 | $choice[$j] = null; |
||
| 3563 | } |
||
| 3564 | } else { |
||
| 3565 | // This value is the user input, not escaped while correct answer is escaped by fckeditor |
||
| 3566 | $choice[$j] = api_htmlentities(trim($choice[$j])); |
||
| 3567 | } |
||
| 3568 | |||
| 3569 | $user_tags[] = $choice[$j]; |
||
| 3570 | //put the contents of the [] answer tag into correct_tags[] |
||
| 3571 | $correct_tags[] = api_substr($temp, 0, $pos); |
||
| 3572 | $j++; |
||
| 3573 | $temp = api_substr($temp, $pos +1); |
||
| 3574 | } |
||
| 3575 | $answer = ''; |
||
| 3576 | $real_correct_tags = $correct_tags; |
||
| 3577 | $chosen_list = array(); |
||
| 3578 | |||
| 3579 | for ($i = 0; $i < count($real_correct_tags); $i++) { |
||
| 3580 | if ($i == 0) { |
||
| 3581 | $answer .= $real_text[0]; |
||
| 3582 | } |
||
| 3583 | if (!$switchable_answer_set) { |
||
| 3584 | // Needed to parse ' and " characters |
||
| 3585 | $user_tags[$i] = stripslashes($user_tags[$i]); |
||
| 3586 | View Code Duplication | if ($correct_tags[$i] == $user_tags[$i]) { |
|
| 3587 | // gives the related weighting to the student |
||
| 3588 | $questionScore += $answerWeighting[$i]; |
||
| 3589 | // increments total score |
||
| 3590 | $totalScore += $answerWeighting[$i]; |
||
| 3591 | // adds the word in green at the end of the string |
||
| 3592 | $answer .= $correct_tags[$i]; |
||
| 3593 | } elseif (!empty($user_tags[$i])) { |
||
| 3594 | // else if the word entered by the student IS NOT the same as the one defined by the professor |
||
| 3595 | // adds the word in red at the end of the string, and strikes it |
||
| 3596 | $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>'; |
||
| 3597 | } else { |
||
| 3598 | // adds a tabulation if no word has been typed by the student |
||
| 3599 | $answer .= ''; // remove that causes issue |
||
| 3600 | } |
||
| 3601 | } else { |
||
| 3602 | // switchable fill in the blanks |
||
| 3603 | if (in_array($user_tags[$i], $correct_tags)) { |
||
| 3604 | $chosen_list[] = $user_tags[$i]; |
||
| 3605 | $correct_tags = array_diff($correct_tags, $chosen_list); |
||
| 3606 | // gives the related weighting to the student |
||
| 3607 | $questionScore += $answerWeighting[$i]; |
||
| 3608 | // increments total score |
||
| 3609 | $totalScore += $answerWeighting[$i]; |
||
| 3610 | // adds the word in green at the end of the string |
||
| 3611 | $answer .= $user_tags[$i]; |
||
| 3612 | } elseif (!empty ($user_tags[$i])) { |
||
| 3613 | // else if the word entered by the student IS NOT the same as the one defined by the professor |
||
| 3614 | // adds the word in red at the end of the string, and strikes it |
||
| 3615 | $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>'; |
||
| 3616 | } else { |
||
| 3617 | // adds a tabulation if no word has been typed by the student |
||
| 3618 | $answer .= ''; // remove that causes issue |
||
| 3619 | } |
||
| 3620 | } |
||
| 3621 | |||
| 3622 | // adds the correct word, followed by ] to close the blank |
||
| 3623 | $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]'; |
||
| 3624 | if (isset($real_text[$i +1])) { |
||
| 3625 | $answer .= $real_text[$i +1]; |
||
| 3626 | } |
||
| 3627 | } |
||
| 3628 | } else { |
||
| 3629 | // insert the student result in the track_e_attempt table, field answer |
||
| 3630 | // $answer is the answer like in the c_quiz_answer table for the question |
||
| 3631 | // student data are choice[] |
||
| 3632 | $listCorrectAnswers = FillBlanks::getAnswerInfo( |
||
| 3633 | $answer |
||
| 3634 | ); |
||
| 3635 | |||
| 3636 | $switchableAnswerSet = $listCorrectAnswers['switchable']; |
||
| 3637 | $answerWeighting = $listCorrectAnswers['tabweighting']; |
||
| 3638 | // user choices is an array $choice |
||
| 3639 | |||
| 3640 | // get existing user data in n the BDD |
||
| 3641 | if ($from_database) { |
||
| 3642 | $sql = "SELECT answer |
||
| 3643 | FROM $TBL_TRACK_ATTEMPT |
||
| 3644 | WHERE |
||
| 3645 | exe_id = $exeId AND |
||
| 3646 | question_id= ".intval($questionId); |
||
| 3647 | $result = Database::query($sql); |
||
| 3648 | $str = Database::result($result, 0, 'answer'); |
||
| 3649 | $listStudentResults = FillBlanks::getAnswerInfo( |
||
| 3650 | $str, |
||
| 3651 | true |
||
| 3652 | ); |
||
| 3653 | $choice = $listStudentResults['studentanswer']; |
||
| 3654 | } |
||
| 3655 | |||
| 3656 | // loop other all blanks words |
||
| 3657 | if (!$switchableAnswerSet) { |
||
| 3658 | // not switchable answer, must be in the same place than teacher order |
||
| 3659 | for ($i = 0; $i < count($listCorrectAnswers['tabwords']); $i++) { |
||
| 3660 | $studentAnswer = isset($choice[$i]) ? trim($choice[$i]) : ''; |
||
| 3661 | $correctAnswer = $listCorrectAnswers['tabwords'][$i]; |
||
| 3662 | |||
| 3663 | // This value is the user input, not escaped while correct answer is escaped by fckeditor |
||
| 3664 | // Works with cyrillic alphabet and when using ">" chars see #7718 #7610 #7618 |
||
| 3665 | if (!$from_database) { |
||
| 3666 | $studentAnswer = htmlentities( |
||
| 3667 | api_utf8_encode($studentAnswer) |
||
| 3668 | ); |
||
| 3669 | } |
||
| 3670 | |||
| 3671 | $isAnswerCorrect = 0; |
||
| 3672 | View Code Duplication | if (FillBlanks::isGoodStudentAnswer($studentAnswer, $correctAnswer)) { |
|
| 3673 | // gives the related weighting to the student |
||
| 3674 | $questionScore += $answerWeighting[$i]; |
||
| 3675 | // increments total score |
||
| 3676 | $totalScore += $answerWeighting[$i]; |
||
| 3677 | $isAnswerCorrect = 1; |
||
| 3678 | } |
||
| 3679 | $listCorrectAnswers['studentanswer'][$i] = $studentAnswer; |
||
| 3680 | $listCorrectAnswers['studentscore'][$i] = $isAnswerCorrect; |
||
| 3681 | } |
||
| 3682 | } else { |
||
| 3683 | // switchable answer |
||
| 3684 | $listStudentAnswerTemp = $choice; |
||
| 3685 | $listTeacherAnswerTemp = $listCorrectAnswers['tabwords']; |
||
| 3686 | // for every teacher answer, check if there is a student answer |
||
| 3687 | for ($i = 0; $i < count($listStudentAnswerTemp); $i++) { |
||
| 3688 | $studentAnswer = trim( |
||
| 3689 | $listStudentAnswerTemp[$i] |
||
| 3690 | ); |
||
| 3691 | $found = false; |
||
| 3692 | for ($j = 0; $j < count($listTeacherAnswerTemp); $j++) { |
||
| 3693 | $correctAnswer = $listTeacherAnswerTemp[$j]; |
||
| 3694 | if (!$found) { |
||
| 3695 | View Code Duplication | if (FillBlanks::isGoodStudentAnswer( |
|
| 3696 | $studentAnswer, |
||
| 3697 | $correctAnswer |
||
| 3698 | ) |
||
| 3699 | ) { |
||
| 3700 | $questionScore += $answerWeighting[$i]; |
||
| 3701 | $totalScore += $answerWeighting[$i]; |
||
| 3702 | $listTeacherAnswerTemp[$j] = ""; |
||
| 3703 | $found = true; |
||
| 3704 | } |
||
| 3705 | } |
||
| 3706 | } |
||
| 3707 | $listCorrectAnswers['studentanswer'][$i] = $studentAnswer; |
||
| 3708 | if (!$found) { |
||
| 3709 | $listCorrectAnswers['studentscore'][$i] = 0; |
||
| 3710 | } else { |
||
| 3711 | $listCorrectAnswers['studentscore'][$i] = 1; |
||
| 3712 | } |
||
| 3713 | } |
||
| 3714 | } |
||
| 3715 | $answer = FillBlanks::getAnswerInStudentAttempt( |
||
| 3716 | $listCorrectAnswers |
||
| 3717 | ); |
||
| 3718 | } |
||
| 3719 | break; |
||
| 3720 | case CALCULATED_ANSWER: |
||
| 3721 | $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]); |
||
| 3722 | $preArray = explode('@@', $answer); |
||
| 3723 | $last = count($preArray) - 1; |
||
| 3724 | $answer = ''; |
||
| 3725 | for ($k = 0; $k < $last; $k++) { |
||
| 3726 | $answer .= $preArray[$k]; |
||
| 3727 | } |
||
| 3728 | $answerWeighting = array($answerWeighting); |
||
| 3729 | // we save the answer because it will be modified |
||
| 3730 | $temp = $answer; |
||
| 3731 | $answer = ''; |
||
| 3732 | $j = 0; |
||
| 3733 | //initialise answer tags |
||
| 3734 | $userTags = $correctTags = $realText = array(); |
||
| 3735 | // the loop will stop at the end of the text |
||
| 3736 | while (1) { |
||
| 3737 | // quits the loop if there are no more blanks (detect '[') |
||
| 3738 | if ($temp == false || ($pos = api_strpos($temp, '[')) === false) { |
||
| 3739 | // adds the end of the text |
||
| 3740 | $answer = $temp; |
||
| 3741 | $realText[] = $answer; |
||
| 3742 | break; //no more "blanks", quit the loop |
||
| 3743 | } |
||
| 3744 | // adds the piece of text that is before the blank |
||
| 3745 | //and ends with '[' into a general storage array |
||
| 3746 | $realText[] = api_substr($temp, 0, $pos +1); |
||
| 3747 | $answer .= api_substr($temp, 0, $pos +1); |
||
| 3748 | //take the string remaining (after the last "[" we found) |
||
| 3749 | $temp = api_substr($temp, $pos +1); |
||
| 3750 | // quit the loop if there are no more blanks, and update $pos to the position of next ']' |
||
| 3751 | if (($pos = api_strpos($temp, ']')) === false) { |
||
| 3752 | // adds the end of the text |
||
| 3753 | $answer .= $temp; |
||
| 3754 | break; |
||
| 3755 | } |
||
| 3756 | if ($from_database) { |
||
| 3757 | $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3758 | WHERE |
||
| 3759 | exe_id = '".$exeId."' AND |
||
| 3760 | question_id= ".intval($questionId); |
||
| 3761 | $resfill = Database::query($queryfill); |
||
| 3762 | $str = Database::result($resfill, 0, 'answer'); |
||
| 3763 | api_preg_match_all('#\[([^[]*)\]#', $str, $arr); |
||
| 3764 | $str = str_replace('\r\n', '', $str); |
||
| 3765 | $choice = $arr[1]; |
||
| 3766 | if (isset($choice[$j])) { |
||
| 3767 | $tmp = api_strrpos($choice[$j], ' / '); |
||
| 3768 | |||
| 3769 | if ($tmp) { |
||
| 3770 | $choice[$j] = api_substr($choice[$j], 0, $tmp); |
||
| 3771 | } else { |
||
| 3772 | $tmp = ltrim($tmp, '['); |
||
| 3773 | $tmp = rtrim($tmp, ']'); |
||
| 3774 | } |
||
| 3775 | |||
| 3776 | $choice[$j] = trim($choice[$j]); |
||
| 3777 | // Needed to let characters ' and " to work as part of an answer |
||
| 3778 | $choice[$j] = stripslashes($choice[$j]); |
||
| 3779 | } else { |
||
| 3780 | $choice[$j] = null; |
||
| 3781 | } |
||
| 3782 | } else { |
||
| 3783 | // This value is the user input, not escaped while correct answer is escaped by fckeditor |
||
| 3784 | $choice[$j] = api_htmlentities(trim($choice[$j])); |
||
| 3785 | } |
||
| 3786 | $userTags[] = $choice[$j]; |
||
| 3787 | //put the contents of the [] answer tag into correct_tags[] |
||
| 3788 | $correctTags[] = api_substr($temp, 0, $pos); |
||
| 3789 | $j++; |
||
| 3790 | $temp = api_substr($temp, $pos +1); |
||
| 3791 | } |
||
| 3792 | $answer = ''; |
||
| 3793 | $realCorrectTags = $correctTags; |
||
| 3794 | for ($i = 0; $i < count($realCorrectTags); $i++) { |
||
| 3795 | if ($i == 0) { |
||
| 3796 | $answer .= $realText[0]; |
||
| 3797 | } |
||
| 3798 | // Needed to parse ' and " characters |
||
| 3799 | $userTags[$i] = stripslashes($userTags[$i]); |
||
| 3800 | View Code Duplication | if ($correctTags[$i] == $userTags[$i]) { |
|
| 3801 | // gives the related weighting to the student |
||
| 3802 | $questionScore += $answerWeighting[$i]; |
||
| 3803 | // increments total score |
||
| 3804 | $totalScore += $answerWeighting[$i]; |
||
| 3805 | // adds the word in green at the end of the string |
||
| 3806 | $answer .= $correctTags[$i]; |
||
| 3807 | } elseif (!empty($userTags[$i])) { |
||
| 3808 | // else if the word entered by the student IS NOT the same as the one defined by the professor |
||
| 3809 | // adds the word in red at the end of the string, and strikes it |
||
| 3810 | $answer .= '<font color="red"><s>' . $userTags[$i] . '</s></font>'; |
||
| 3811 | } else { |
||
| 3812 | // adds a tabulation if no word has been typed by the student |
||
| 3813 | $answer .= ''; // remove that causes issue |
||
| 3814 | } |
||
| 3815 | // adds the correct word, followed by ] to close the blank |
||
| 3816 | |||
| 3817 | if ( |
||
| 3818 | $this->results_disabled != EXERCISE_FEEDBACK_TYPE_EXAM |
||
| 3819 | ) { |
||
| 3820 | $answer .= ' / <font color="green"><b>' . $realCorrectTags[$i] . '</b></font>'; |
||
| 3821 | } |
||
| 3822 | |||
| 3823 | $answer .= ']'; |
||
| 3824 | |||
| 3825 | if (isset($realText[$i +1])) { |
||
| 3826 | $answer .= $realText[$i +1]; |
||
| 3827 | } |
||
| 3828 | } |
||
| 3829 | break; |
||
| 3830 | case FREE_ANSWER: |
||
| 3831 | if ($from_database) { |
||
| 3832 | $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3833 | WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; |
||
| 3834 | $resq = Database::query($query); |
||
| 3835 | $data = Database::fetch_array($resq); |
||
| 3836 | |||
| 3837 | $choice = $data['answer']; |
||
| 3838 | $choice = str_replace('\r\n', '', $choice); |
||
| 3839 | $choice = stripslashes($choice); |
||
| 3840 | $questionScore = $data['marks']; |
||
| 3841 | |||
| 3842 | if ($questionScore == -1) { |
||
| 3843 | $totalScore+= 0; |
||
| 3844 | } else { |
||
| 3845 | $totalScore+= $questionScore; |
||
| 3846 | } |
||
| 3847 | if ($questionScore == '') { |
||
| 3848 | $questionScore = 0; |
||
| 3849 | } |
||
| 3850 | $arrques = $questionName; |
||
| 3851 | $arrans = $choice; |
||
| 3852 | } else { |
||
| 3853 | $studentChoice = $choice; |
||
| 3854 | if ($studentChoice) { |
||
| 3855 | //Fixing negative puntation see #2193 |
||
| 3856 | $questionScore = 0; |
||
| 3857 | $totalScore += 0; |
||
| 3858 | } |
||
| 3859 | } |
||
| 3860 | break; |
||
| 3861 | case ORAL_EXPRESSION: |
||
| 3862 | if ($from_database) { |
||
| 3863 | $query = "SELECT answer, marks |
||
| 3864 | FROM $TBL_TRACK_ATTEMPT |
||
| 3865 | WHERE |
||
| 3866 | exe_id = $exeId AND |
||
| 3867 | question_id = $questionId |
||
| 3868 | "; |
||
| 3869 | $resq = Database::query($query); |
||
| 3870 | $row = Database::fetch_assoc($resq); |
||
| 3871 | $choice = $row['answer']; |
||
| 3872 | $choice = str_replace('\r\n', '', $choice); |
||
| 3873 | $choice = stripslashes($choice); |
||
| 3874 | $questionScore = $row['marks']; |
||
| 3875 | if ($questionScore == -1) { |
||
| 3876 | $totalScore += 0; |
||
| 3877 | } else { |
||
| 3878 | $totalScore += $questionScore; |
||
| 3879 | } |
||
| 3880 | $arrques = $questionName; |
||
| 3881 | $arrans = $choice; |
||
| 3882 | } else { |
||
| 3883 | $studentChoice = $choice; |
||
| 3884 | if ($studentChoice) { |
||
| 3885 | //Fixing negative puntation see #2193 |
||
| 3886 | $questionScore = 0; |
||
| 3887 | $totalScore += 0; |
||
| 3888 | } |
||
| 3889 | } |
||
| 3890 | break; |
||
| 3891 | case DRAGGABLE: |
||
| 3892 | //no break |
||
| 3893 | case MATCHING_DRAGGABLE: |
||
| 3894 | //no break |
||
| 3895 | case MATCHING: |
||
| 3896 | if ($from_database) { |
||
| 3897 | $sql = "SELECT id, answer, id_auto |
||
| 3898 | FROM $table_ans |
||
| 3899 | WHERE |
||
| 3900 | c_id = $course_id AND |
||
| 3901 | question_id = $questionId AND |
||
| 3902 | correct = 0 |
||
| 3903 | "; |
||
| 3904 | $res_answer = Database::query($sql); |
||
| 3905 | // Getting the real answer |
||
| 3906 | $real_list = array(); |
||
| 3907 | while ($real_answer = Database::fetch_array($res_answer)) { |
||
| 3908 | $real_list[$real_answer['id_auto']] = $real_answer['answer']; |
||
| 3909 | } |
||
| 3910 | |||
| 3911 | $sql = "SELECT id, answer, correct, id_auto, ponderation |
||
| 3912 | FROM $table_ans |
||
| 3913 | WHERE |
||
| 3914 | c_id = $course_id AND |
||
| 3915 | question_id = $questionId AND |
||
| 3916 | correct <> 0 |
||
| 3917 | ORDER BY id_auto"; |
||
| 3918 | $res_answers = Database::query($sql); |
||
| 3919 | |||
| 3920 | $questionScore = 0; |
||
| 3921 | |||
| 3922 | while ($a_answers = Database::fetch_array($res_answers)) { |
||
| 3923 | $i_answer_id = $a_answers['id']; //3 |
||
| 3924 | $s_answer_label = $a_answers['answer']; // your daddy - your mother |
||
| 3925 | $i_answer_correct_answer = $a_answers['correct']; //1 - 2 |
||
| 3926 | $i_answer_id_auto = $a_answers['id_auto']; // 3 - 4 |
||
| 3927 | |||
| 3928 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3929 | WHERE |
||
| 3930 | exe_id = '$exeId' AND |
||
| 3931 | question_id = '$questionId' AND |
||
| 3932 | position = '$i_answer_id_auto'"; |
||
| 3933 | |||
| 3934 | $res_user_answer = Database::query($sql); |
||
| 3935 | |||
| 3936 | if (Database::num_rows($res_user_answer) > 0) { |
||
| 3937 | // rich - good looking |
||
| 3938 | $s_user_answer = Database::result($res_user_answer, 0, 0); |
||
| 3939 | } else { |
||
| 3940 | $s_user_answer = 0; |
||
| 3941 | } |
||
| 3942 | |||
| 3943 | $i_answerWeighting = $a_answers['ponderation']; |
||
| 3944 | |||
| 3945 | $user_answer = ''; |
||
| 3946 | if (!empty($s_user_answer)) { |
||
| 3947 | if ($answerType == DRAGGABLE) { |
||
| 3948 | if ($s_user_answer == $i_answer_correct_answer) { |
||
| 3949 | $questionScore += $i_answerWeighting; |
||
| 3950 | $totalScore += $i_answerWeighting; |
||
| 3951 | $user_answer = Display::label(get_lang('Correct'), 'success'); |
||
| 3952 | } else { |
||
| 3953 | $user_answer = Display::label(get_lang('Incorrect'), 'danger'); |
||
| 3954 | } |
||
| 3955 | } else { |
||
| 3956 | if ($s_user_answer == $i_answer_correct_answer) { |
||
| 3957 | $questionScore += $i_answerWeighting; |
||
| 3958 | $totalScore += $i_answerWeighting; |
||
| 3959 | |||
| 3960 | // Try with id |
||
| 3961 | if (isset($real_list[$i_answer_id])) { |
||
| 3962 | $user_answer = Display::span($real_list[$i_answer_id]); |
||
| 3963 | } |
||
| 3964 | |||
| 3965 | // Try with $i_answer_id_auto |
||
| 3966 | if (empty($user_answer)) { |
||
| 3967 | if (isset($real_list[$i_answer_id_auto])) { |
||
| 3968 | $user_answer = Display::span( |
||
| 3969 | $real_list[$i_answer_id_auto] |
||
| 3970 | ); |
||
| 3971 | } |
||
| 3972 | } |
||
| 3973 | } else { |
||
| 3974 | $user_answer = Display::span( |
||
| 3975 | $real_list[$s_user_answer], |
||
| 3976 | ['style' => 'color: #FF0000; text-decoration: line-through;'] |
||
| 3977 | ); |
||
| 3978 | } |
||
| 3979 | } |
||
| 3980 | } elseif ($answerType == DRAGGABLE) { |
||
| 3981 | $user_answer = Display::label(get_lang('Incorrect'), 'danger'); |
||
| 3982 | } else { |
||
| 3983 | $user_answer = Display::span( |
||
| 3984 | get_lang('Incorrect').' ', |
||
| 3985 | ['style' => 'color: #FF0000; text-decoration: line-through;'] |
||
| 3986 | ); |
||
| 3987 | } |
||
| 3988 | |||
| 3989 | if ($show_result) { |
||
| 3990 | if ($showTotalScoreAndUserChoicesInLastAttempt === false) { |
||
| 3991 | $user_answer = ''; |
||
| 3992 | } |
||
| 3993 | echo '<tr>'; |
||
| 3994 | echo '<td>' . $s_answer_label . '</td>'; |
||
| 3995 | echo '<td>' . $user_answer; |
||
| 3996 | |||
| 3997 | if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
||
| 3998 | if (isset($real_list[$i_answer_correct_answer]) && |
||
| 3999 | $showTotalScoreAndUserChoicesInLastAttempt === true |
||
| 4000 | ) { |
||
| 4001 | echo Display::span( |
||
| 4002 | $real_list[$i_answer_correct_answer], |
||
| 4003 | ['style' => 'color: #008000; font-weight: bold;'] |
||
| 4004 | ); |
||
| 4005 | } |
||
| 4006 | } |
||
| 4007 | echo '</td>'; |
||
| 4008 | echo '</tr>'; |
||
| 4009 | } |
||
| 4010 | } |
||
| 4011 | break(2); // break the switch and the "for" condition |
||
| 4012 | } else { |
||
| 4013 | if ($answerCorrect) { |
||
| 4014 | if (isset($choice[$answerAutoId]) && |
||
| 4015 | $answerCorrect == $choice[$answerAutoId] |
||
| 4016 | ) { |
||
| 4017 | $questionScore += $answerWeighting; |
||
| 4018 | $totalScore += $answerWeighting; |
||
| 4019 | $user_answer = Display::span($answerMatching[$choice[$answerAutoId]]); |
||
| 4020 | } else { |
||
| 4021 | if (isset($answerMatching[$choice[$answerAutoId]])) { |
||
| 4022 | $user_answer = Display::span( |
||
| 4023 | $answerMatching[$choice[$answerAutoId]], |
||
| 4024 | ['style' => 'color: #FF0000; text-decoration: line-through;'] |
||
| 4025 | ); |
||
| 4026 | } |
||
| 4027 | } |
||
| 4028 | $matching[$answerAutoId] = $choice[$answerAutoId]; |
||
| 4029 | } |
||
| 4030 | break; |
||
| 4031 | } |
||
| 4032 | case HOT_SPOT: |
||
| 4033 | if ($from_database) { |
||
| 4034 | $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
||
| 4035 | // Check auto id |
||
| 4036 | $sql = "SELECT hotspot_correct |
||
| 4037 | FROM $TBL_TRACK_HOTSPOT |
||
| 4038 | WHERE |
||
| 4039 | hotspot_exe_id = $exeId AND |
||
| 4040 | hotspot_question_id= $questionId AND |
||
| 4041 | hotspot_answer_id = ".intval($answerAutoId); |
||
| 4042 | $result = Database::query($sql); |
||
| 4043 | if (Database::num_rows($result)) { |
||
| 4044 | $studentChoice = Database::result( |
||
| 4045 | $result, |
||
| 4046 | 0, |
||
| 4047 | 'hotspot_correct' |
||
| 4048 | ); |
||
| 4049 | |||
| 4050 | if ($studentChoice) { |
||
| 4051 | $questionScore += $answerWeighting; |
||
| 4052 | $totalScore += $answerWeighting; |
||
| 4053 | } |
||
| 4054 | } else { |
||
| 4055 | // If answer.id is different: |
||
| 4056 | $sql = "SELECT hotspot_correct |
||
| 4057 | FROM $TBL_TRACK_HOTSPOT |
||
| 4058 | WHERE |
||
| 4059 | hotspot_exe_id = $exeId AND |
||
| 4060 | hotspot_question_id= $questionId AND |
||
| 4061 | hotspot_answer_id = ".intval($answerId); |
||
| 4062 | $result = Database::query($sql); |
||
| 4063 | |||
| 4064 | if (Database::num_rows($result)) { |
||
| 4065 | $studentChoice = Database::result( |
||
| 4066 | $result, |
||
| 4067 | 0, |
||
| 4068 | 'hotspot_correct' |
||
| 4069 | ); |
||
| 4070 | |||
| 4071 | if ($studentChoice) { |
||
| 4072 | $questionScore += $answerWeighting; |
||
| 4073 | $totalScore += $answerWeighting; |
||
| 4074 | } |
||
| 4075 | } else { |
||
| 4076 | // check answer.iid |
||
| 4077 | if (!empty($answerIid)) { |
||
| 4078 | $sql = "SELECT hotspot_correct |
||
| 4079 | FROM $TBL_TRACK_HOTSPOT |
||
| 4080 | WHERE |
||
| 4081 | hotspot_exe_id = $exeId AND |
||
| 4082 | hotspot_question_id= $questionId AND |
||
| 4083 | hotspot_answer_id = ".intval($answerIid); |
||
| 4084 | $result = Database::query($sql); |
||
| 4085 | |||
| 4086 | $studentChoice = Database::result( |
||
| 4087 | $result, |
||
| 4088 | 0, |
||
| 4089 | 'hotspot_correct' |
||
| 4090 | ); |
||
| 4091 | |||
| 4092 | if ($studentChoice) { |
||
| 4093 | $questionScore += $answerWeighting; |
||
| 4094 | $totalScore += $answerWeighting; |
||
| 4095 | } |
||
| 4096 | } |
||
| 4097 | } |
||
| 4098 | } |
||
| 4099 | } else { |
||
| 4100 | if (!isset($choice[$answerAutoId]) && !isset($choice[$answerIid])) { |
||
| 4101 | $choice[$answerAutoId] = 0; |
||
| 4102 | $choice[$answerIid] = 0; |
||
| 4103 | } else { |
||
| 4104 | $studentChoice = $choice[$answerAutoId]; |
||
| 4105 | if (empty($studentChoice)) { |
||
| 4106 | $studentChoice = $choice[$answerIid]; |
||
| 4107 | } |
||
| 4108 | $choiceIsValid = false; |
||
| 4109 | if (!empty($studentChoice)) { |
||
| 4110 | $hotspotType = $objAnswerTmp->selectHotspotType($answerId); |
||
| 4111 | $hotspotCoordinates = $objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4112 | $choicePoint = Geometry::decodePoint($studentChoice); |
||
| 4113 | |||
| 4114 | switch ($hotspotType) { |
||
| 4115 | case 'square': |
||
| 4116 | $hotspotProperties = Geometry::decodeSquare($hotspotCoordinates); |
||
| 4117 | $choiceIsValid = Geometry::pointIsInSquare($hotspotProperties, $choicePoint); |
||
| 4118 | break; |
||
| 4119 | case 'circle': |
||
| 4120 | $hotspotProperties = Geometry::decodeEllipse($hotspotCoordinates); |
||
| 4121 | $choiceIsValid = Geometry::pointIsInEllipse($hotspotProperties, $choicePoint); |
||
| 4122 | break; |
||
| 4123 | case 'poly': |
||
| 4124 | $hotspotProperties = Geometry::decodePolygon($hotspotCoordinates); |
||
| 4125 | $choiceIsValid = Geometry::pointIsInPolygon($hotspotProperties, $choicePoint); |
||
| 4126 | break; |
||
| 4127 | } |
||
| 4128 | } |
||
| 4129 | |||
| 4130 | $choice[$answerAutoId] = 0; |
||
| 4131 | if ($choiceIsValid) { |
||
| 4132 | $questionScore += $answerWeighting; |
||
| 4133 | $totalScore += $answerWeighting; |
||
| 4134 | $choice[$answerAutoId] = 1; |
||
| 4135 | $choice[$answerIid] = 1; |
||
| 4136 | } |
||
| 4137 | } |
||
| 4138 | } |
||
| 4139 | break; |
||
| 4140 | // @todo never added to chamilo |
||
| 4141 | //for hotspot with fixed order |
||
| 4142 | case HOT_SPOT_ORDER: |
||
| 4143 | $studentChoice = $choice['order'][$answerId]; |
||
| 4144 | if ($studentChoice == $answerId) { |
||
| 4145 | $questionScore += $answerWeighting; |
||
| 4146 | $totalScore += $answerWeighting; |
||
| 4147 | $studentChoice = true; |
||
| 4148 | } else { |
||
| 4149 | $studentChoice = false; |
||
| 4150 | } |
||
| 4151 | break; |
||
| 4152 | // for hotspot with delineation |
||
| 4153 | case HOT_SPOT_DELINEATION: |
||
| 4154 | if ($from_database) { |
||
| 4155 | // getting the user answer |
||
| 4156 | $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
||
| 4157 | $query = "SELECT hotspot_correct, hotspot_coordinate |
||
| 4158 | FROM $TBL_TRACK_HOTSPOT |
||
| 4159 | WHERE |
||
| 4160 | hotspot_exe_id = '".$exeId."' AND |
||
| 4161 | hotspot_question_id= '".$questionId."' AND |
||
| 4162 | hotspot_answer_id='1'"; |
||
| 4163 | //by default we take 1 because it's a delineation |
||
| 4164 | $resq = Database::query($query); |
||
| 4165 | $row = Database::fetch_array($resq,'ASSOC'); |
||
| 4166 | |||
| 4167 | $choice = $row['hotspot_correct']; |
||
| 4168 | $user_answer = $row['hotspot_coordinate']; |
||
| 4169 | |||
| 4170 | // THIS is very important otherwise the poly_compile will throw an error!! |
||
| 4171 | // round-up the coordinates |
||
| 4172 | $coords = explode('/',$user_answer); |
||
| 4173 | $user_array = ''; |
||
| 4174 | View Code Duplication | foreach ($coords as $coord) { |
|
| 4175 | list($x,$y) = explode(';',$coord); |
||
| 4176 | $user_array .= round($x).';'.round($y).'/'; |
||
| 4177 | } |
||
| 4178 | $user_array = substr($user_array,0,-1); |
||
| 4179 | } else { |
||
| 4180 | if (!empty($studentChoice)) { |
||
| 4181 | $newquestionList[] = $questionId; |
||
| 4182 | } |
||
| 4183 | |||
| 4184 | if ($answerId === 1) { |
||
| 4185 | $studentChoice = $choice[$answerId]; |
||
| 4186 | $questionScore += $answerWeighting; |
||
| 4187 | |||
| 4188 | if ($hotspot_delineation_result[1]==1) { |
||
| 4189 | $totalScore += $answerWeighting; //adding the total |
||
| 4190 | } |
||
| 4191 | } |
||
| 4192 | } |
||
| 4193 | $_SESSION['hotspot_coord'][1] = $delineation_cord; |
||
| 4194 | $_SESSION['hotspot_dest'][1] = $answer_delineation_destination; |
||
| 4195 | break; |
||
| 4196 | } // end switch Answertype |
||
| 4197 | |||
| 4198 | if ($show_result) { |
||
| 4199 | if ($debug) error_log('Showing questions $from '.$from); |
||
| 4200 | if ($from == 'exercise_result') { |
||
| 4201 | //display answers (if not matching type, or if the answer is correct) |
||
| 4202 | if ( |
||
| 4203 | !in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]) || |
||
| 4204 | $answerCorrect |
||
| 4205 | ) { |
||
| 4206 | if ( |
||
| 4207 | in_array( |
||
| 4208 | $answerType, |
||
| 4209 | array( |
||
| 4210 | UNIQUE_ANSWER, |
||
| 4211 | UNIQUE_ANSWER_IMAGE, |
||
| 4212 | UNIQUE_ANSWER_NO_OPTION, |
||
| 4213 | MULTIPLE_ANSWER, |
||
| 4214 | MULTIPLE_ANSWER_COMBINATION, |
||
| 4215 | GLOBAL_MULTIPLE_ANSWER |
||
| 4216 | ) |
||
| 4217 | ) |
||
| 4218 | ) { |
||
| 4219 | ExerciseShowFunctions::display_unique_or_multiple_answer( |
||
| 4220 | $feedback_type, |
||
| 4221 | $answerType, |
||
| 4222 | $studentChoice, |
||
| 4223 | $answer, |
||
| 4224 | $answerComment, |
||
| 4225 | $answerCorrect, |
||
| 4226 | 0, |
||
| 4227 | 0, |
||
| 4228 | 0, |
||
| 4229 | $results_disabled, |
||
| 4230 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4231 | ); |
||
| 4232 | } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { |
||
| 4233 | ExerciseShowFunctions::display_multiple_answer_true_false( |
||
| 4234 | $feedback_type, |
||
| 4235 | $answerType, |
||
| 4236 | $studentChoice, |
||
| 4237 | $answer, |
||
| 4238 | $answerComment, |
||
| 4239 | $answerCorrect, |
||
| 4240 | 0, |
||
| 4241 | $questionId, |
||
| 4242 | 0, |
||
| 4243 | $results_disabled, |
||
| 4244 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4245 | ); |
||
| 4246 | } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) { |
||
| 4247 | ExerciseShowFunctions::display_multiple_answer_combination_true_false( |
||
| 4248 | $feedback_type, |
||
| 4249 | $answerType, |
||
| 4250 | $studentChoice, |
||
| 4251 | $answer, |
||
| 4252 | $answerComment, |
||
| 4253 | $answerCorrect, |
||
| 4254 | 0, |
||
| 4255 | 0, |
||
| 4256 | 0, |
||
| 4257 | $results_disabled, |
||
| 4258 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4259 | ); |
||
| 4260 | } elseif ($answerType == FILL_IN_BLANKS) { |
||
| 4261 | ExerciseShowFunctions::display_fill_in_blanks_answer( |
||
| 4262 | $feedback_type, |
||
| 4263 | $answer, |
||
| 4264 | 0, |
||
| 4265 | 0, |
||
| 4266 | $results_disabled, |
||
| 4267 | '', |
||
| 4268 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4269 | ); |
||
| 4270 | } elseif ($answerType == CALCULATED_ANSWER) { |
||
| 4271 | ExerciseShowFunctions::display_calculated_answer( |
||
| 4272 | $feedback_type, |
||
| 4273 | $answer, |
||
| 4274 | 0, |
||
| 4275 | 0, |
||
| 4276 | $results_disabled, |
||
| 4277 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4278 | ); |
||
| 4279 | } elseif ($answerType == FREE_ANSWER) { |
||
| 4280 | ExerciseShowFunctions::display_free_answer( |
||
| 4281 | $feedback_type, |
||
| 4282 | $choice, |
||
| 4283 | $exeId, |
||
| 4284 | $questionId, |
||
| 4285 | $questionScore, |
||
| 4286 | $results_disabled |
||
| 4287 | ); |
||
| 4288 | } elseif ($answerType == ORAL_EXPRESSION) { |
||
| 4289 | // to store the details of open questions in an array to be used in mail |
||
| 4290 | /** @var OralExpression $objQuestionTmp */ |
||
| 4291 | ExerciseShowFunctions::display_oral_expression_answer( |
||
| 4292 | $feedback_type, |
||
| 4293 | $choice, |
||
| 4294 | 0, |
||
| 4295 | 0, |
||
| 4296 | $objQuestionTmp->getFileUrl(true), |
||
| 4297 | $results_disabled |
||
| 4298 | ); |
||
| 4299 | } elseif ($answerType == HOT_SPOT) { |
||
| 4300 | foreach ($orderedHotspots as $correctAnswerId => $hotspot) { |
||
| 4301 | if ($hotspot->getHotspotAnswerId() == $answerAutoId) { |
||
| 4302 | break; |
||
| 4303 | } |
||
| 4304 | } |
||
| 4305 | |||
| 4306 | ExerciseShowFunctions::display_hotspot_answer( |
||
| 4307 | $feedback_type, |
||
| 4308 | $answerId, |
||
| 4309 | $answer, |
||
| 4310 | $studentChoice, |
||
| 4311 | $answerComment, |
||
| 4312 | $results_disabled, |
||
| 4313 | $answerId, |
||
| 4314 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4315 | ); |
||
| 4316 | } elseif ($answerType == HOT_SPOT_ORDER) { |
||
| 4317 | ExerciseShowFunctions::display_hotspot_order_answer( |
||
| 4318 | $feedback_type, |
||
| 4319 | $answerId, |
||
| 4320 | $answer, |
||
| 4321 | $studentChoice, |
||
| 4322 | $answerComment |
||
| 4323 | ); |
||
| 4324 | } elseif ($answerType == HOT_SPOT_DELINEATION) { |
||
| 4325 | $user_answer = $_SESSION['exerciseResultCoordinates'][$questionId]; |
||
| 4326 | |||
| 4327 | //round-up the coordinates |
||
| 4328 | $coords = explode('/',$user_answer); |
||
| 4329 | $user_array = ''; |
||
| 4330 | View Code Duplication | foreach ($coords as $coord) { |
|
| 4331 | list($x,$y) = explode(';',$coord); |
||
| 4332 | $user_array .= round($x).';'.round($y).'/'; |
||
| 4333 | } |
||
| 4334 | $user_array = substr($user_array,0,-1); |
||
| 4335 | |||
| 4336 | View Code Duplication | if ($next) { |
|
| 4337 | |||
| 4338 | $user_answer = $user_array; |
||
| 4339 | |||
| 4340 | // we compare only the delineation not the other points |
||
| 4341 | $answer_question = $_SESSION['hotspot_coord'][1]; |
||
| 4342 | $answerDestination = $_SESSION['hotspot_dest'][1]; |
||
| 4343 | |||
| 4344 | //calculating the area |
||
| 4345 | $poly_user = convert_coordinates($user_answer, '/'); |
||
| 4346 | $poly_answer = convert_coordinates($answer_question, '|'); |
||
| 4347 | $max_coord = poly_get_max($poly_user, $poly_answer); |
||
| 4348 | $poly_user_compiled = poly_compile($poly_user, $max_coord); |
||
| 4349 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
||
| 4350 | $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
||
| 4351 | |||
| 4352 | $overlap = $poly_results['both']; |
||
| 4353 | $poly_answer_area = $poly_results['s1']; |
||
| 4354 | $poly_user_area = $poly_results['s2']; |
||
| 4355 | $missing = $poly_results['s1Only']; |
||
| 4356 | $excess = $poly_results['s2Only']; |
||
| 4357 | |||
| 4358 | //$overlap = round(polygons_overlap($poly_answer,$poly_user)); |
||
| 4359 | // //this is an area in pixels |
||
| 4360 | if ($debug > 0) { |
||
| 4361 | error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); |
||
| 4362 | } |
||
| 4363 | |||
| 4364 | if ($overlap < 1) { |
||
| 4365 | //shortcut to avoid complicated calculations |
||
| 4366 | $final_overlap = 0; |
||
| 4367 | $final_missing = 100; |
||
| 4368 | $final_excess = 100; |
||
| 4369 | } else { |
||
| 4370 | // the final overlap is the percentage of the initial polygon |
||
| 4371 | // that is overlapped by the user's polygon |
||
| 4372 | $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
||
| 4373 | if ($debug > 1) { |
||
| 4374 | error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); |
||
| 4375 | } |
||
| 4376 | // the final missing area is the percentage of the initial polygon |
||
| 4377 | // that is not overlapped by the user's polygon |
||
| 4378 | $final_missing = 100 - $final_overlap; |
||
| 4379 | if ($debug > 1) { |
||
| 4380 | error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); |
||
| 4381 | } |
||
| 4382 | // the final excess area is the percentage of the initial polygon's size |
||
| 4383 | // that is covered by the user's polygon outside of the initial polygon |
||
| 4384 | $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
||
| 4385 | if ($debug > 1) { |
||
| 4386 | error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); |
||
| 4387 | } |
||
| 4388 | } |
||
| 4389 | |||
| 4390 | //checking the destination parameters parsing the "@@" |
||
| 4391 | $destination_items= explode('@@', $answerDestination); |
||
| 4392 | $threadhold_total = $destination_items[0]; |
||
| 4393 | $threadhold_items=explode(';',$threadhold_total); |
||
| 4394 | $threadhold1 = $threadhold_items[0]; // overlap |
||
| 4395 | $threadhold2 = $threadhold_items[1]; // excess |
||
| 4396 | $threadhold3 = $threadhold_items[2]; //missing |
||
| 4397 | |||
| 4398 | // if is delineation |
||
| 4399 | if ($answerId===1) { |
||
| 4400 | //setting colors |
||
| 4401 | if ($final_overlap>=$threadhold1) { |
||
| 4402 | $overlap_color=true; //echo 'a'; |
||
| 4403 | } |
||
| 4404 | //echo $excess.'-'.$threadhold2; |
||
| 4405 | if ($final_excess<=$threadhold2) { |
||
| 4406 | $excess_color=true; //echo 'b'; |
||
| 4407 | } |
||
| 4408 | //echo '--------'.$missing.'-'.$threadhold3; |
||
| 4409 | if ($final_missing<=$threadhold3) { |
||
| 4410 | $missing_color=true; //echo 'c'; |
||
| 4411 | } |
||
| 4412 | |||
| 4413 | // if pass |
||
| 4414 | if ( |
||
| 4415 | $final_overlap >= $threadhold1 && |
||
| 4416 | $final_missing <= $threadhold3 && |
||
| 4417 | $final_excess <= $threadhold2 |
||
| 4418 | ) { |
||
| 4419 | $next=1; //go to the oars |
||
| 4420 | $result_comment=get_lang('Acceptable'); |
||
| 4421 | $final_answer = 1; // do not update with update_exercise_attempt |
||
| 4422 | } else { |
||
| 4423 | $next=0; |
||
| 4424 | $result_comment=get_lang('Unacceptable'); |
||
| 4425 | $comment=$answerDestination=$objAnswerTmp->selectComment(1); |
||
| 4426 | $answerDestination=$objAnswerTmp->selectDestination(1); |
||
| 4427 | //checking the destination parameters parsing the "@@" |
||
| 4428 | $destination_items= explode('@@', $answerDestination); |
||
| 4429 | } |
||
| 4430 | } elseif($answerId>1) { |
||
| 4431 | if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
||
| 4432 | if ($debug>0) { |
||
| 4433 | error_log(__LINE__.' - answerId is of type noerror',0); |
||
| 4434 | } |
||
| 4435 | //type no error shouldn't be treated |
||
| 4436 | $next = 1; |
||
| 4437 | continue; |
||
| 4438 | } |
||
| 4439 | if ($debug>0) { |
||
| 4440 | error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0); |
||
| 4441 | } |
||
| 4442 | //check the intersection between the oar and the user |
||
| 4443 | //echo 'user'; print_r($x_user_list); print_r($y_user_list); |
||
| 4444 | //echo 'official';print_r($x_list);print_r($y_list); |
||
| 4445 | //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
||
| 4446 | $inter= $result['success']; |
||
| 4447 | |||
| 4448 | //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4449 | $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4450 | |||
| 4451 | $poly_answer = convert_coordinates($delineation_cord,'|'); |
||
| 4452 | $max_coord = poly_get_max($poly_user,$poly_answer); |
||
| 4453 | $poly_answer_compiled = poly_compile($poly_answer,$max_coord); |
||
| 4454 | $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); |
||
| 4455 | |||
| 4456 | if ($overlap == false) { |
||
| 4457 | //all good, no overlap |
||
| 4458 | $next = 1; |
||
| 4459 | continue; |
||
| 4460 | } else { |
||
| 4461 | if ($debug>0) { |
||
| 4462 | error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0); |
||
| 4463 | } |
||
| 4464 | $organs_at_risk_hit++; |
||
| 4465 | //show the feedback |
||
| 4466 | $next=0; |
||
| 4467 | $comment=$answerDestination=$objAnswerTmp->selectComment($answerId); |
||
| 4468 | $answerDestination=$objAnswerTmp->selectDestination($answerId); |
||
| 4469 | |||
| 4470 | $destination_items= explode('@@', $answerDestination); |
||
| 4471 | $try_hotspot=$destination_items[1]; |
||
| 4472 | $lp_hotspot=$destination_items[2]; |
||
| 4473 | $select_question_hotspot=$destination_items[3]; |
||
| 4474 | $url_hotspot=$destination_items[4]; |
||
| 4475 | } |
||
| 4476 | } |
||
| 4477 | } else { // the first delineation feedback |
||
| 4478 | if ($debug>0) { |
||
| 4479 | error_log(__LINE__.' first',0); |
||
| 4480 | } |
||
| 4481 | } |
||
| 4482 | } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
||
| 4483 | echo '<tr>'; |
||
| 4484 | echo Display::tag('td', $answerMatching[$answerId]); |
||
| 4485 | echo Display::tag( |
||
| 4486 | 'td', |
||
| 4487 | "$user_answer / " . Display::tag( |
||
| 4488 | 'strong', |
||
| 4489 | $answerMatching[$answerCorrect], |
||
| 4490 | ['style' => 'color: #008000; font-weight: bold;'] |
||
| 4491 | ) |
||
| 4492 | ); |
||
| 4493 | echo '</tr>'; |
||
| 4494 | } |
||
| 4495 | } |
||
| 4496 | } else { |
||
| 4497 | if ($debug) error_log('Showing questions $from '.$from); |
||
| 4498 | |||
| 4499 | switch ($answerType) { |
||
| 4500 | case UNIQUE_ANSWER: |
||
| 4501 | case UNIQUE_ANSWER_IMAGE: |
||
| 4502 | case UNIQUE_ANSWER_NO_OPTION: |
||
| 4503 | case MULTIPLE_ANSWER: |
||
| 4504 | case GLOBAL_MULTIPLE_ANSWER : |
||
| 4505 | View Code Duplication | case MULTIPLE_ANSWER_COMBINATION: |
|
| 4506 | if ($answerId == 1) { |
||
| 4507 | ExerciseShowFunctions::display_unique_or_multiple_answer( |
||
| 4508 | $feedback_type, |
||
| 4509 | $answerType, |
||
| 4510 | $studentChoice, |
||
| 4511 | $answer, |
||
| 4512 | $answerComment, |
||
| 4513 | $answerCorrect, |
||
| 4514 | $exeId, |
||
| 4515 | $questionId, |
||
| 4516 | $answerId, |
||
| 4517 | $results_disabled, |
||
| 4518 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4519 | ); |
||
| 4520 | } else { |
||
| 4521 | ExerciseShowFunctions::display_unique_or_multiple_answer( |
||
| 4522 | $feedback_type, |
||
| 4523 | $answerType, |
||
| 4524 | $studentChoice, |
||
| 4525 | $answer, |
||
| 4526 | $answerComment, |
||
| 4527 | $answerCorrect, |
||
| 4528 | $exeId, |
||
| 4529 | $questionId, |
||
| 4530 | '', |
||
| 4531 | $results_disabled, |
||
| 4532 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4533 | ); |
||
| 4534 | } |
||
| 4535 | break; |
||
| 4536 | View Code Duplication | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
|
| 4537 | if ($answerId == 1) { |
||
| 4538 | ExerciseShowFunctions::display_multiple_answer_combination_true_false( |
||
| 4539 | $feedback_type, |
||
| 4540 | $answerType, |
||
| 4541 | $studentChoice, |
||
| 4542 | $answer, |
||
| 4543 | $answerComment, |
||
| 4544 | $answerCorrect, |
||
| 4545 | $exeId, |
||
| 4546 | $questionId, |
||
| 4547 | $answerId, |
||
| 4548 | $results_disabled, |
||
| 4549 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4550 | ); |
||
| 4551 | } else { |
||
| 4552 | ExerciseShowFunctions::display_multiple_answer_combination_true_false( |
||
| 4553 | $feedback_type, |
||
| 4554 | $answerType, |
||
| 4555 | $studentChoice, |
||
| 4556 | $answer, |
||
| 4557 | $answerComment, |
||
| 4558 | $answerCorrect, |
||
| 4559 | $exeId, |
||
| 4560 | $questionId, |
||
| 4561 | '', |
||
| 4562 | $results_disabled, |
||
| 4563 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4564 | ); |
||
| 4565 | } |
||
| 4566 | break; |
||
| 4567 | View Code Duplication | case MULTIPLE_ANSWER_TRUE_FALSE: |
|
| 4568 | if ($answerId == 1) { |
||
| 4569 | ExerciseShowFunctions::display_multiple_answer_true_false( |
||
| 4570 | $feedback_type, |
||
| 4571 | $answerType, |
||
| 4572 | $studentChoice, |
||
| 4573 | $answer, |
||
| 4574 | $answerComment, |
||
| 4575 | $answerCorrect, |
||
| 4576 | $exeId, |
||
| 4577 | $questionId, |
||
| 4578 | $answerId, |
||
| 4579 | $results_disabled, |
||
| 4580 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4581 | ); |
||
| 4582 | } else { |
||
| 4583 | ExerciseShowFunctions::display_multiple_answer_true_false( |
||
| 4584 | $feedback_type, |
||
| 4585 | $answerType, |
||
| 4586 | $studentChoice, |
||
| 4587 | $answer, |
||
| 4588 | $answerComment, |
||
| 4589 | $answerCorrect, |
||
| 4590 | $exeId, |
||
| 4591 | $questionId, |
||
| 4592 | '', |
||
| 4593 | $results_disabled, |
||
| 4594 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4595 | ); |
||
| 4596 | } |
||
| 4597 | break; |
||
| 4598 | case FILL_IN_BLANKS: |
||
| 4599 | ExerciseShowFunctions::display_fill_in_blanks_answer( |
||
| 4600 | $feedback_type, |
||
| 4601 | $answer, |
||
| 4602 | $exeId, |
||
| 4603 | $questionId, |
||
| 4604 | $results_disabled, |
||
| 4605 | $str, |
||
| 4606 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4607 | ); |
||
| 4608 | break; |
||
| 4609 | case CALCULATED_ANSWER: |
||
| 4610 | ExerciseShowFunctions::display_calculated_answer( |
||
| 4611 | $feedback_type, |
||
| 4612 | $answer, |
||
| 4613 | $exeId, |
||
| 4614 | $questionId, |
||
| 4615 | $results_disabled, |
||
| 4616 | '', |
||
| 4617 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4618 | ); |
||
| 4619 | break; |
||
| 4620 | case FREE_ANSWER: |
||
| 4621 | echo ExerciseShowFunctions::display_free_answer( |
||
| 4622 | $feedback_type, |
||
| 4623 | $choice, |
||
| 4624 | $exeId, |
||
| 4625 | $questionId, |
||
| 4626 | $questionScore, |
||
| 4627 | $results_disabled |
||
| 4628 | ); |
||
| 4629 | break; |
||
| 4630 | case ORAL_EXPRESSION: |
||
| 4631 | echo '<tr> |
||
| 4632 | <td valign="top">' . ExerciseShowFunctions::display_oral_expression_answer( |
||
| 4633 | $feedback_type, |
||
| 4634 | $choice, |
||
| 4635 | $exeId, |
||
| 4636 | $questionId, |
||
| 4637 | $objQuestionTmp->getFileUrl(), |
||
| 4638 | $results_disabled |
||
| 4639 | ) . '</td> |
||
| 4640 | </tr> |
||
| 4641 | </table>'; |
||
| 4642 | break; |
||
| 4643 | case HOT_SPOT: |
||
| 4644 | ExerciseShowFunctions::display_hotspot_answer( |
||
| 4645 | $feedback_type, |
||
| 4646 | $answerId, |
||
| 4647 | $answer, |
||
| 4648 | $studentChoice, |
||
| 4649 | $answerComment, |
||
| 4650 | $results_disabled, |
||
| 4651 | $answerId, |
||
| 4652 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4653 | ); |
||
| 4654 | break; |
||
| 4655 | case HOT_SPOT_DELINEATION: |
||
| 4656 | $user_answer = $user_array; |
||
| 4657 | View Code Duplication | if ($next) { |
|
| 4658 | //$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
||
| 4659 | // Save into db |
||
| 4660 | /* $sql = "INSERT INTO $tbl_track_e_hotspot ( |
||
| 4661 | * hotspot_user_id, |
||
| 4662 | * hotspot_course_code, |
||
| 4663 | * hotspot_exe_id, |
||
| 4664 | * hotspot_question_id, |
||
| 4665 | * hotspot_answer_id, |
||
| 4666 | * hotspot_correct, |
||
| 4667 | * hotspot_coordinate |
||
| 4668 | * ) |
||
| 4669 | VALUES ( |
||
| 4670 | * '".Database::escape_string($_user['user_id'])."', |
||
| 4671 | * '".Database::escape_string($_course['id'])."', |
||
| 4672 | * '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', |
||
| 4673 | * '".Database::escape_string($answerId)."', |
||
| 4674 | * '".Database::escape_string($studentChoice)."', |
||
| 4675 | * '".Database::escape_string($user_array)."')"; |
||
| 4676 | $result = Database::query($sql,__FILE__,__LINE__); |
||
| 4677 | */ |
||
| 4678 | $user_answer = $user_array; |
||
| 4679 | |||
| 4680 | // we compare only the delineation not the other points |
||
| 4681 | $answer_question = $_SESSION['hotspot_coord'][1]; |
||
| 4682 | $answerDestination = $_SESSION['hotspot_dest'][1]; |
||
| 4683 | |||
| 4684 | //calculating the area |
||
| 4685 | $poly_user = convert_coordinates($user_answer, '/'); |
||
| 4686 | $poly_answer = convert_coordinates($answer_question, '|'); |
||
| 4687 | |||
| 4688 | $max_coord = poly_get_max($poly_user, $poly_answer); |
||
| 4689 | $poly_user_compiled = poly_compile($poly_user, $max_coord); |
||
| 4690 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
||
| 4691 | $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
||
| 4692 | |||
| 4693 | $overlap = $poly_results['both']; |
||
| 4694 | $poly_answer_area = $poly_results['s1']; |
||
| 4695 | $poly_user_area = $poly_results['s2']; |
||
| 4696 | $missing = $poly_results['s1Only']; |
||
| 4697 | $excess = $poly_results['s2Only']; |
||
| 4698 | |||
| 4699 | //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels |
||
| 4700 | if ($debug > 0) { |
||
| 4701 | error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); |
||
| 4702 | } |
||
| 4703 | if ($overlap < 1) { |
||
| 4704 | //shortcut to avoid complicated calculations |
||
| 4705 | $final_overlap = 0; |
||
| 4706 | $final_missing = 100; |
||
| 4707 | $final_excess = 100; |
||
| 4708 | } else { |
||
| 4709 | // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon |
||
| 4710 | $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
||
| 4711 | if ($debug > 1) { |
||
| 4712 | error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); |
||
| 4713 | } |
||
| 4714 | // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon |
||
| 4715 | $final_missing = 100 - $final_overlap; |
||
| 4716 | if ($debug > 1) { |
||
| 4717 | error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); |
||
| 4718 | } |
||
| 4719 | // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon |
||
| 4720 | $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
||
| 4721 | if ($debug > 1) { |
||
| 4722 | error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); |
||
| 4723 | } |
||
| 4724 | } |
||
| 4725 | |||
| 4726 | //checking the destination parameters parsing the "@@" |
||
| 4727 | $destination_items = explode('@@', $answerDestination); |
||
| 4728 | $threadhold_total = $destination_items[0]; |
||
| 4729 | $threadhold_items = explode(';', $threadhold_total); |
||
| 4730 | $threadhold1 = $threadhold_items[0]; // overlap |
||
| 4731 | $threadhold2 = $threadhold_items[1]; // excess |
||
| 4732 | $threadhold3 = $threadhold_items[2]; //missing |
||
| 4733 | // if is delineation |
||
| 4734 | if ($answerId === 1) { |
||
| 4735 | //setting colors |
||
| 4736 | if ($final_overlap >= $threadhold1) { |
||
| 4737 | $overlap_color = true; //echo 'a'; |
||
| 4738 | } |
||
| 4739 | //echo $excess.'-'.$threadhold2; |
||
| 4740 | if ($final_excess <= $threadhold2) { |
||
| 4741 | $excess_color = true; //echo 'b'; |
||
| 4742 | } |
||
| 4743 | //echo '--------'.$missing.'-'.$threadhold3; |
||
| 4744 | if ($final_missing <= $threadhold3) { |
||
| 4745 | $missing_color = true; //echo 'c'; |
||
| 4746 | } |
||
| 4747 | |||
| 4748 | // if pass |
||
| 4749 | if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) { |
||
| 4750 | $next = 1; //go to the oars |
||
| 4751 | $result_comment = get_lang('Acceptable'); |
||
| 4752 | $final_answer = 1; // do not update with update_exercise_attempt |
||
| 4753 | } else { |
||
| 4754 | $next = 0; |
||
| 4755 | $result_comment = get_lang('Unacceptable'); |
||
| 4756 | $comment = $answerDestination = $objAnswerTmp->selectComment(1); |
||
| 4757 | $answerDestination = $objAnswerTmp->selectDestination(1); |
||
| 4758 | //checking the destination parameters parsing the "@@" |
||
| 4759 | $destination_items = explode('@@', $answerDestination); |
||
| 4760 | } |
||
| 4761 | } elseif ($answerId > 1) { |
||
| 4762 | if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
||
| 4763 | if ($debug > 0) { |
||
| 4764 | error_log(__LINE__ . ' - answerId is of type noerror', 0); |
||
| 4765 | } |
||
| 4766 | //type no error shouldn't be treated |
||
| 4767 | $next = 1; |
||
| 4768 | continue; |
||
| 4769 | } |
||
| 4770 | if ($debug > 0) { |
||
| 4771 | error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0); |
||
| 4772 | } |
||
| 4773 | //check the intersection between the oar and the user |
||
| 4774 | //echo 'user'; print_r($x_user_list); print_r($y_user_list); |
||
| 4775 | //echo 'official';print_r($x_list);print_r($y_list); |
||
| 4776 | //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
||
| 4777 | $inter = $result['success']; |
||
| 4778 | |||
| 4779 | //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4780 | $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4781 | |||
| 4782 | $poly_answer = convert_coordinates($delineation_cord, '|'); |
||
| 4783 | $max_coord = poly_get_max($poly_user, $poly_answer); |
||
| 4784 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
||
| 4785 | $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); |
||
| 4786 | |||
| 4787 | if ($overlap == false) { |
||
| 4788 | //all good, no overlap |
||
| 4789 | $next = 1; |
||
| 4790 | continue; |
||
| 4791 | } else { |
||
| 4792 | if ($debug > 0) { |
||
| 4793 | error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0); |
||
| 4794 | } |
||
| 4795 | $organs_at_risk_hit++; |
||
| 4796 | //show the feedback |
||
| 4797 | $next = 0; |
||
| 4798 | $comment = $answerDestination = $objAnswerTmp->selectComment($answerId); |
||
| 4799 | $answerDestination = $objAnswerTmp->selectDestination($answerId); |
||
| 4800 | |||
| 4801 | $destination_items = explode('@@', $answerDestination); |
||
| 4802 | $try_hotspot = $destination_items[1]; |
||
| 4803 | $lp_hotspot = $destination_items[2]; |
||
| 4804 | $select_question_hotspot = $destination_items[3]; |
||
| 4805 | $url_hotspot=$destination_items[4]; |
||
| 4806 | } |
||
| 4807 | } |
||
| 4808 | } else { // the first delineation feedback |
||
| 4809 | if ($debug > 0) { |
||
| 4810 | error_log(__LINE__ . ' first', 0); |
||
| 4811 | } |
||
| 4812 | } |
||
| 4813 | break; |
||
| 4814 | case HOT_SPOT_ORDER: |
||
| 4815 | ExerciseShowFunctions::display_hotspot_order_answer( |
||
| 4816 | $feedback_type, |
||
| 4817 | $answerId, |
||
| 4818 | $answer, |
||
| 4819 | $studentChoice, |
||
| 4820 | $answerComment |
||
| 4821 | ); |
||
| 4822 | break; |
||
| 4823 | case DRAGGABLE: |
||
| 4824 | //no break |
||
| 4825 | case MATCHING_DRAGGABLE: |
||
| 4826 | //no break |
||
| 4827 | case MATCHING: |
||
| 4828 | echo '<tr>'; |
||
| 4829 | echo Display::tag('td', $answerMatching[$answerId]); |
||
| 4830 | echo Display::tag( |
||
| 4831 | 'td', |
||
| 4832 | "$user_answer / " . Display::tag( |
||
| 4833 | 'strong', |
||
| 4834 | $answerMatching[$answerCorrect], |
||
| 4835 | ['style' => 'color: #008000; font-weight: bold;'] |
||
| 4836 | ) |
||
| 4837 | ); |
||
| 4838 | echo '</tr>'; |
||
| 4839 | |||
| 4840 | break; |
||
| 4841 | } |
||
| 4842 | } |
||
| 4843 | } |
||
| 4844 | if ($debug) error_log(' ------ '); |
||
| 4845 | } // end for that loops over all answers of the current question |
||
| 4846 | |||
| 4847 | if ($debug) error_log('-- end answer loop --'); |
||
| 4848 | |||
| 4849 | $final_answer = true; |
||
| 4850 | |||
| 4851 | foreach ($real_answers as $my_answer) { |
||
| 4852 | if (!$my_answer) { |
||
| 4853 | $final_answer = false; |
||
| 4854 | } |
||
| 4855 | } |
||
| 4856 | |||
| 4857 | //we add the total score after dealing with the answers |
||
| 4858 | if ($answerType == MULTIPLE_ANSWER_COMBINATION || |
||
| 4859 | $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE |
||
| 4860 | ) { |
||
| 4861 | if ($final_answer) { |
||
| 4862 | //getting only the first score where we save the weight of all the question |
||
| 4863 | $answerWeighting = $objAnswerTmp->selectWeighting(1); |
||
| 4864 | $questionScore += $answerWeighting; |
||
| 4865 | $totalScore += $answerWeighting; |
||
| 4866 | } |
||
| 4867 | } |
||
| 4868 | |||
| 4869 | //Fixes multiple answer question in order to be exact |
||
| 4870 | //if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 4871 | /* if ($answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 4872 | $diff = @array_diff($answer_correct_array, $real_answers); |
||
| 4873 | |||
| 4874 | // All good answers or nothing works like exact |
||
| 4875 | |||
| 4876 | $counter = 1; |
||
| 4877 | $correct_answer = true; |
||
| 4878 | foreach ($real_answers as $my_answer) { |
||
| 4879 | if ($debug) |
||
| 4880 | error_log(" my_answer: $my_answer answer_correct_array[counter]: ".$answer_correct_array[$counter]); |
||
| 4881 | if ($my_answer != $answer_correct_array[$counter]) { |
||
| 4882 | $correct_answer = false; |
||
| 4883 | break; |
||
| 4884 | } |
||
| 4885 | $counter++; |
||
| 4886 | } |
||
| 4887 | |||
| 4888 | if ($debug) error_log(" answer_correct_array: ".print_r($answer_correct_array, 1).""); |
||
| 4889 | if ($debug) error_log(" real_answers: ".print_r($real_answers, 1).""); |
||
| 4890 | if ($debug) error_log(" correct_answer: ".$correct_answer); |
||
| 4891 | |||
| 4892 | if ($correct_answer == false) { |
||
| 4893 | $questionScore = 0; |
||
| 4894 | } |
||
| 4895 | |||
| 4896 | // This makes the result non exact |
||
| 4897 | if (!empty($diff)) { |
||
| 4898 | $questionScore = 0; |
||
| 4899 | } |
||
| 4900 | }*/ |
||
| 4901 | |||
| 4902 | $extra_data = array( |
||
| 4903 | 'final_overlap' => $final_overlap, |
||
| 4904 | 'final_missing'=>$final_missing, |
||
| 4905 | 'final_excess'=> $final_excess, |
||
| 4906 | 'overlap_color' => $overlap_color, |
||
| 4907 | 'missing_color'=>$missing_color, |
||
| 4908 | 'excess_color'=> $excess_color, |
||
| 4909 | 'threadhold1' => $threadhold1, |
||
| 4910 | 'threadhold2'=>$threadhold2, |
||
| 4911 | 'threadhold3'=> $threadhold3, |
||
| 4912 | ); |
||
| 4913 | if ($from == 'exercise_result') { |
||
| 4914 | // if answer is hotspot. To the difference of exercise_show.php, |
||
| 4915 | // we use the results from the session (from_db=0) |
||
| 4916 | // TODO Change this, because it is wrong to show the user |
||
| 4917 | // some results that haven't been stored in the database yet |
||
| 4918 | if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION ) { |
||
| 4919 | |||
| 4920 | if ($debug) error_log('$from AND this is a hotspot kind of question '); |
||
| 4921 | |||
| 4922 | $my_exe_id = 0; |
||
| 4923 | $from_database = 0; |
||
| 4924 | if ($answerType == HOT_SPOT_DELINEATION) { |
||
| 4925 | if (0) { |
||
| 4926 | if ($overlap_color) { |
||
| 4927 | $overlap_color='green'; |
||
| 4928 | } else { |
||
| 4929 | $overlap_color='red'; |
||
| 4930 | } |
||
| 4931 | if ($missing_color) { |
||
| 4932 | $missing_color='green'; |
||
| 4933 | } else { |
||
| 4934 | $missing_color='red'; |
||
| 4935 | } |
||
| 4936 | if ($excess_color) { |
||
| 4937 | $excess_color='green'; |
||
| 4938 | } else { |
||
| 4939 | $excess_color='red'; |
||
| 4940 | } |
||
| 4941 | if (!is_numeric($final_overlap)) { |
||
| 4942 | $final_overlap = 0; |
||
| 4943 | } |
||
| 4944 | if (!is_numeric($final_missing)) { |
||
| 4945 | $final_missing = 0; |
||
| 4946 | } |
||
| 4947 | if (!is_numeric($final_excess)) { |
||
| 4948 | $final_excess = 0; |
||
| 4949 | } |
||
| 4950 | |||
| 4951 | if ($final_overlap>100) { |
||
| 4952 | $final_overlap = 100; |
||
| 4953 | } |
||
| 4954 | |||
| 4955 | $table_resume='<table class="data_table"> |
||
| 4956 | <tr class="row_odd" > |
||
| 4957 | <td></td> |
||
| 4958 | <td ><b>' . get_lang('Requirements') . '</b></td> |
||
| 4959 | <td><b>' . get_lang('YourAnswer') . '</b></td> |
||
| 4960 | </tr> |
||
| 4961 | <tr class="row_even"> |
||
| 4962 | <td><b>' . get_lang('Overlap') . '</b></td> |
||
| 4963 | <td>' . get_lang('Min') . ' ' . $threadhold1 . '</td> |
||
| 4964 | <td><div style="color:' . $overlap_color . '">' |
||
| 4965 | . (($final_overlap < 0) ? 0 : intval($final_overlap)) . '</div></td> |
||
| 4966 | </tr> |
||
| 4967 | <tr> |
||
| 4968 | <td><b>' . get_lang('Excess') . '</b></td> |
||
| 4969 | <td>' . get_lang('Max') . ' ' . $threadhold2 . '</td> |
||
| 4970 | <td><div style="color:' . $excess_color . '">' |
||
| 4971 | . (($final_excess < 0) ? 0 : intval($final_excess)) . '</div></td> |
||
| 4972 | </tr> |
||
| 4973 | <tr class="row_even"> |
||
| 4974 | <td><b>' . get_lang('Missing') . '</b></td> |
||
| 4975 | <td>' . get_lang('Max') . ' ' . $threadhold3 . '</td> |
||
| 4976 | <td><div style="color:' . $missing_color . '">' |
||
| 4977 | . (($final_missing < 0) ? 0 : intval($final_missing)) . '</div></td> |
||
| 4978 | </tr> |
||
| 4979 | </table>'; |
||
| 4980 | View Code Duplication | if ($next == 0) { |
|
| 4981 | $try = $try_hotspot; |
||
| 4982 | $lp = $lp_hotspot; |
||
| 4983 | $destinationid = $select_question_hotspot; |
||
| 4984 | $url = $url_hotspot; |
||
| 4985 | } else { |
||
| 4986 | //show if no error |
||
| 4987 | //echo 'no error'; |
||
| 4988 | $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers); |
||
| 4989 | $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers); |
||
| 4990 | } |
||
| 4991 | |||
| 4992 | echo '<h1><div style="color:#333;">' . get_lang('Feedback') . '</div></h1> |
||
| 4993 | <p style="text-align:center">'; |
||
| 4994 | |||
| 4995 | $message = '<p>' . get_lang('YourDelineation') . '</p>'; |
||
| 4996 | $message .= $table_resume; |
||
| 4997 | $message .= '<br />' . get_lang('ResultIs') . ' ' . $result_comment . '<br />'; |
||
| 4998 | if ($organs_at_risk_hit > 0) { |
||
| 4999 | $message .= '<p><b>' . get_lang('OARHit') . '</b></p>'; |
||
| 5000 | } |
||
| 5001 | $message .='<p>' . $comment . '</p>'; |
||
| 5002 | echo $message; |
||
| 5003 | } else { |
||
| 5004 | echo $hotspot_delineation_result[0]; //prints message |
||
| 5005 | $from_database = 1; // the hotspot_solution.swf needs this variable |
||
| 5006 | } |
||
| 5007 | |||
| 5008 | //save the score attempts |
||
| 5009 | |||
| 5010 | if (1) { |
||
| 5011 | //getting the answer 1 or 0 comes from exercise_submit_modal.php |
||
| 5012 | $final_answer = $hotspot_delineation_result[1]; |
||
| 5013 | if ($final_answer == 0) { |
||
| 5014 | $questionScore = 0; |
||
| 5015 | } |
||
| 5016 | // we always insert the answer_id 1 = delineation |
||
| 5017 | Event::saveQuestionAttempt($questionScore, 1, $quesId, $exeId, 0); |
||
| 5018 | //in delineation mode, get the answer from $hotspot_delineation_result[1] |
||
| 5019 | $hotspotValue = (int) $hotspot_delineation_result[1] === 1 ? 1 : 0; |
||
| 5020 | Event::saveExerciseAttemptHotspot( |
||
| 5021 | $exeId, |
||
| 5022 | $quesId, |
||
| 5023 | 1, |
||
| 5024 | $hotspotValue, |
||
| 5025 | $exerciseResultCoordinates[$quesId] |
||
| 5026 | ); |
||
| 5027 | } else { |
||
| 5028 | if ($final_answer==0) { |
||
| 5029 | $questionScore = 0; |
||
| 5030 | $answer=0; |
||
| 5031 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0); |
||
| 5032 | if (is_array($exerciseResultCoordinates[$quesId])) { |
||
| 5033 | foreach($exerciseResultCoordinates[$quesId] as $idx => $val) { |
||
| 5034 | Event::saveExerciseAttemptHotspot( |
||
| 5035 | $exeId, |
||
| 5036 | $quesId, |
||
| 5037 | $idx, |
||
| 5038 | 0, |
||
| 5039 | $val |
||
| 5040 | ); |
||
| 5041 | } |
||
| 5042 | } |
||
| 5043 | } else { |
||
| 5044 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0); |
||
| 5045 | if (is_array($exerciseResultCoordinates[$quesId])) { |
||
| 5046 | foreach($exerciseResultCoordinates[$quesId] as $idx => $val) { |
||
| 5047 | $hotspotValue = (int) $choice[$idx] === 1 ? 1 : 0; |
||
| 5048 | Event::saveExerciseAttemptHotspot( |
||
| 5049 | $exeId, |
||
| 5050 | $quesId, |
||
| 5051 | $idx, |
||
| 5052 | $hotspotValue, |
||
| 5053 | $val |
||
| 5054 | ); |
||
| 5055 | } |
||
| 5056 | } |
||
| 5057 | } |
||
| 5058 | } |
||
| 5059 | $my_exe_id = $exeId; |
||
| 5060 | } |
||
| 5061 | } |
||
| 5062 | |||
| 5063 | if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) { |
||
| 5064 | // We made an extra table for the answers |
||
| 5065 | |||
| 5066 | if ($show_result) { |
||
| 5067 | $relPath = api_get_path(WEB_CODE_PATH); |
||
| 5068 | // if ($origin != 'learnpath') { |
||
| 5069 | echo '</table></td></tr>'; |
||
| 5070 | echo " |
||
| 5071 | <tr> |
||
| 5072 | <td colspan=\"2\"> |
||
| 5073 | <p><em>" . get_lang('HotSpot') . "</em></p> |
||
| 5074 | <div id=\"hotspot-solution-$questionId\"></div> |
||
| 5075 | <script> |
||
| 5076 | $(document).on('ready', function () { |
||
| 5077 | new HotspotQuestion({ |
||
| 5078 | questionId: $questionId, |
||
| 5079 | exerciseId: $exeId, |
||
| 5080 | selector: '#hotspot-solution-$questionId', |
||
| 5081 | for: 'solution', |
||
| 5082 | relPath: '$relPath' |
||
| 5083 | }); |
||
| 5084 | }); |
||
| 5085 | </script> |
||
| 5086 | </td> |
||
| 5087 | </tr> |
||
| 5088 | "; |
||
| 5089 | // } |
||
| 5090 | } |
||
| 5091 | } |
||
| 5092 | |||
| 5093 | //if ($origin != 'learnpath') { |
||
| 5094 | if ($show_result) { |
||
| 5095 | echo '</table>'; |
||
| 5096 | } |
||
| 5097 | // } |
||
| 5098 | } |
||
| 5099 | unset ($objAnswerTmp); |
||
| 5100 | |||
| 5101 | $totalWeighting += $questionWeighting; |
||
| 5102 | // Store results directly in the database |
||
| 5103 | // For all in one page exercises, the results will be |
||
| 5104 | // stored by exercise_results.php (using the session) |
||
| 5105 | |||
| 5106 | if ($saved_results) { |
||
| 5107 | if ($debug) error_log("Save question results $saved_results"); |
||
| 5108 | if ($debug) error_log(print_r($choice ,1 )); |
||
| 5109 | |||
| 5110 | if (empty($choice)) { |
||
| 5111 | $choice = 0; |
||
| 5112 | } |
||
| 5113 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { |
||
| 5114 | if ($choice != 0) { |
||
| 5115 | $reply = array_keys($choice); |
||
| 5116 | for ($i = 0; $i < sizeof($reply); $i++) { |
||
| 5117 | $ans = $reply[$i]; |
||
| 5118 | Event::saveQuestionAttempt( |
||
| 5119 | $questionScore, |
||
| 5120 | $ans . ':' . $choice[$ans], |
||
| 5121 | $quesId, |
||
| 5122 | $exeId, |
||
| 5123 | $i, |
||
| 5124 | $this->id |
||
| 5125 | ); |
||
| 5126 | if ($debug) { |
||
| 5127 | error_log('result =>' . $questionScore . ' ' . $ans . ':' . $choice[$ans]); |
||
| 5128 | } |
||
| 5129 | } |
||
| 5130 | } else { |
||
| 5131 | Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); |
||
| 5132 | } |
||
| 5133 | } elseif ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 5134 | if ($choice != 0) { |
||
| 5135 | $reply = array_keys($choice); |
||
| 5136 | |||
| 5137 | if ($debug) { |
||
| 5138 | error_log("reply " . print_r($reply, 1) . ""); |
||
| 5139 | } |
||
| 5140 | View Code Duplication | for ($i = 0; $i < sizeof($reply); $i++) { |
|
| 5141 | $ans = $reply[$i]; |
||
| 5142 | Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id); |
||
| 5143 | } |
||
| 5144 | } else { |
||
| 5145 | Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); |
||
| 5146 | } |
||
| 5147 | } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) { |
||
| 5148 | if ($choice != 0) { |
||
| 5149 | $reply = array_keys($choice); |
||
| 5150 | View Code Duplication | for ($i = 0; $i < sizeof($reply); $i++) { |
|
| 5151 | $ans = $reply[$i]; |
||
| 5152 | Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id); |
||
| 5153 | } |
||
| 5154 | } else { |
||
| 5155 | Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); |
||
| 5156 | } |
||
| 5157 | } elseif (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) { |
||
| 5158 | if (isset($matching)) { |
||
| 5159 | foreach ($matching as $j => $val) { |
||
| 5160 | Event::saveQuestionAttempt($questionScore, $val, $quesId, $exeId, $j, $this->id); |
||
| 5161 | } |
||
| 5162 | } |
||
| 5163 | } elseif ($answerType == FREE_ANSWER) { |
||
| 5164 | $answer = $choice; |
||
| 5165 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); |
||
| 5166 | } elseif ($answerType == ORAL_EXPRESSION) { |
||
| 5167 | $answer = $choice; |
||
| 5168 | Event::saveQuestionAttempt( |
||
| 5169 | $questionScore, |
||
| 5170 | $answer, |
||
| 5171 | $quesId, |
||
| 5172 | $exeId, |
||
| 5173 | 0, |
||
| 5174 | $this->id, |
||
| 5175 | false, |
||
| 5176 | $objQuestionTmp->getAbsoluteFilePath() |
||
| 5177 | ); |
||
| 5178 | } elseif (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION])) { |
||
| 5179 | $answer = $choice; |
||
| 5180 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); |
||
| 5181 | // } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { |
||
| 5182 | } elseif ($answerType == HOT_SPOT) { |
||
| 5183 | $answer = []; |
||
| 5184 | if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) { |
||
| 5185 | Database::delete( |
||
| 5186 | Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT), |
||
| 5187 | [ |
||
| 5188 | 'hotspot_exe_id = ? AND hotspot_question_id = ? AND c_id = ?' => [ |
||
| 5189 | $exeId, |
||
| 5190 | $questionId, |
||
| 5191 | api_get_course_int_id() |
||
| 5192 | ] |
||
| 5193 | ] |
||
| 5194 | ); |
||
| 5195 | |||
| 5196 | foreach ($exerciseResultCoordinates[$questionId] as $idx => $val) { |
||
| 5197 | $answer[] = $val; |
||
| 5198 | $hotspotValue = (int) $choice[$idx] === 1 ? 1 : 0; |
||
| 5199 | Event::saveExerciseAttemptHotspot( |
||
| 5200 | $exeId, |
||
| 5201 | $quesId, |
||
| 5202 | $idx, |
||
| 5203 | $hotspotValue, |
||
| 5204 | $val, |
||
| 5205 | false, |
||
| 5206 | $this->id |
||
| 5207 | ); |
||
| 5208 | } |
||
| 5209 | } |
||
| 5210 | |||
| 5211 | Event::saveQuestionAttempt($questionScore, implode('|', $answer), $quesId, $exeId, 0, $this->id); |
||
| 5212 | } else { |
||
| 5213 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0,$this->id); |
||
| 5214 | } |
||
| 5215 | } |
||
| 5216 | |||
| 5217 | if ($propagate_neg == 0 && $questionScore < 0) { |
||
| 5218 | $questionScore = 0; |
||
| 5219 | } |
||
| 5220 | |||
| 5221 | if ($saved_results) { |
||
| 5222 | $stat_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
||
| 5223 | $sql = 'UPDATE ' . $stat_table . ' SET |
||
| 5224 | exe_result = exe_result + ' . floatval($questionScore) . ' |
||
| 5225 | WHERE exe_id = ' . $exeId; |
||
| 5226 | Database::query($sql); |
||
| 5227 | } |
||
| 5228 | |||
| 5229 | $return_array = array( |
||
| 5230 | 'score' => $questionScore, |
||
| 5231 | 'weight' => $questionWeighting, |
||
| 5232 | 'extra' => $extra_data, |
||
| 5233 | 'open_question' => $arrques, |
||
| 5234 | 'open_answer' => $arrans, |
||
| 5235 | 'answer_type' => $answerType |
||
| 5236 | ); |
||
| 5237 | |||
| 5238 | return $return_array; |
||
| 5239 | } |
||
| 5240 | |||
| 5241 | /** |
||
| 5242 | * Sends a notification when a user ends an examn |
||
| 5243 | * |
||
| 5244 | * @param array $question_list_answers |
||
| 5245 | * @param string $origin |
||
| 5246 | * @param int $exe_id |
||
| 5247 | * @param float $score |
||
| 5248 | * @param float $weight |
||
| 5249 | * @return bool |
||
| 5250 | */ |
||
| 5251 | public function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id, $score, $weight) |
||
| 5346 | |||
| 5347 | /** |
||
| 5348 | * Sends a notification when a user ends an examn |
||
| 5349 | * |
||
| 5350 | * @param integer $exe_id |
||
| 5351 | */ |
||
| 5352 | public function send_notification_for_open_questions($question_list_answers, $origin, $exe_id) |
||
| 5447 | |||
| 5448 | function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id) |
||
| 5538 | |||
| 5539 | /** |
||
| 5540 | * @param array $user_data result of api_get_user_info() |
||
| 5541 | * @param string $start_date |
||
| 5542 | * @param null $duration |
||
| 5543 | * @param string $ip Optional. The user IP |
||
| 5544 | * @return string |
||
| 5545 | */ |
||
| 5546 | public function show_exercise_result_header($user_data, $start_date = null, $duration = null, $ip = null) |
||
| 5587 | |||
| 5588 | /** |
||
| 5589 | * Create a quiz from quiz data |
||
| 5590 | * @param string Title |
||
| 5591 | * @param int Time before it expires (in minutes) |
||
| 5592 | * @param int Type of exercise |
||
| 5593 | * @param int Whether it's randomly picked questions (1) or not (0) |
||
| 5594 | * @param int Whether the exercise is visible to the user (1) or not (0) |
||
| 5595 | * @param int Whether the results are show to the user (0) or not (1) |
||
| 5596 | * @param int Maximum number of attempts (0 if no limit) |
||
| 5597 | * @param int Feedback type |
||
| 5598 | * @todo this was function was added due the import exercise via CSV |
||
| 5599 | * @return int New exercise ID |
||
| 5600 | */ |
||
| 5601 | public function createExercise( |
||
| 5666 | |||
| 5667 | function process_geometry() |
||
| 5671 | |||
| 5672 | /** |
||
| 5673 | * Returns the exercise result |
||
| 5674 | * @param int attempt id |
||
| 5675 | * @return float exercise result |
||
| 5676 | */ |
||
| 5677 | public function get_exercise_result($exe_id) |
||
| 5714 | |||
| 5715 | /** |
||
| 5716 | * Checks if the exercise is visible due a lot of conditions |
||
| 5717 | * visibility, time limits, student attempts |
||
| 5718 | * Return associative array |
||
| 5719 | * value : true if execise visible |
||
| 5720 | * message : HTML formated message |
||
| 5721 | * rawMessage : text message |
||
| 5722 | * @param int $lpId |
||
| 5723 | * @param int $lpItemId |
||
| 5724 | * @param int $lpItemViewId |
||
| 5725 | * @param bool $filterByAdmin |
||
| 5726 | * @return array |
||
| 5727 | */ |
||
| 5728 | public function is_visible( |
||
| 5916 | |||
| 5917 | public function added_in_lp() |
||
| 5928 | |||
| 5929 | /** |
||
| 5930 | * Returns an array with the media list |
||
| 5931 | * @param array question list |
||
| 5932 | * @example there's 1 question with iid 5 that belongs to the media question with iid = 100 |
||
| 5933 | * <code> |
||
| 5934 | * array (size=2) |
||
| 5935 | * 999 => |
||
| 5936 | * array (size=3) |
||
| 5937 | * 0 => int 7 |
||
| 5938 | * 1 => int 6 |
||
| 5939 | * 2 => int 3254 |
||
| 5940 | * 100 => |
||
| 5941 | * array (size=1) |
||
| 5942 | * 0 => int 5 |
||
| 5943 | * </code> |
||
| 5944 | * @return array |
||
| 5945 | */ |
||
| 5946 | private function setMediaList($questionList) |
||
| 5964 | |||
| 5965 | /** |
||
| 5966 | * Returns an array with this form |
||
| 5967 | * @example |
||
| 5968 | * <code> |
||
| 5969 | * array (size=3) |
||
| 5970 | 999 => |
||
| 5971 | array (size=3) |
||
| 5972 | 0 => int 3422 |
||
| 5973 | 1 => int 3423 |
||
| 5974 | 2 => int 3424 |
||
| 5975 | 100 => |
||
| 5976 | array (size=2) |
||
| 5977 | 0 => int 3469 |
||
| 5978 | 1 => int 3470 |
||
| 5979 | 101 => |
||
| 5980 | array (size=1) |
||
| 5981 | 0 => int 3482 |
||
| 5982 | * </code> |
||
| 5983 | * The array inside the key 999 means the question list that belongs to the media id = 999, |
||
| 5984 | * this case is special because 999 means "no media". |
||
| 5985 | * @return array |
||
| 5986 | */ |
||
| 5987 | public function getMediaList() |
||
| 5991 | |||
| 5992 | /** |
||
| 5993 | * Is media question activated? |
||
| 5994 | * @return bool |
||
| 5995 | */ |
||
| 5996 | public function mediaIsActivated() |
||
| 6015 | |||
| 6016 | /** |
||
| 6017 | * Gets question list from the exercise |
||
| 6018 | * |
||
| 6019 | * @return array |
||
| 6020 | */ |
||
| 6021 | public function getQuestionList() |
||
| 6025 | |||
| 6026 | /** |
||
| 6027 | * Question list with medias compressed like this |
||
| 6028 | * @example |
||
| 6029 | * <code> |
||
| 6030 | * array( |
||
| 6031 | * question_id_1, |
||
| 6032 | * question_id_2, |
||
| 6033 | * media_id, <- this media id contains question ids |
||
| 6034 | * question_id_3, |
||
| 6035 | * ) |
||
| 6036 | * </code> |
||
| 6037 | * @return array |
||
| 6038 | */ |
||
| 6039 | public function getQuestionListWithMediasCompressed() |
||
| 6043 | |||
| 6044 | /** |
||
| 6045 | * Question list with medias uncompressed like this |
||
| 6046 | * @example |
||
| 6047 | * <code> |
||
| 6048 | * array( |
||
| 6049 | * question_id, |
||
| 6050 | * question_id, |
||
| 6051 | * question_id, <- belongs to a media id |
||
| 6052 | * question_id, <- belongs to a media id |
||
| 6053 | * question_id, |
||
| 6054 | * ) |
||
| 6055 | * </code> |
||
| 6056 | * @return array |
||
| 6057 | */ |
||
| 6058 | public function getQuestionListWithMediasUncompressed() |
||
| 6062 | |||
| 6063 | /** |
||
| 6064 | * Sets the question list when the exercise->read() is executed |
||
| 6065 | */ |
||
| 6066 | public function setQuestionList() |
||
| 6076 | |||
| 6077 | /** |
||
| 6078 | * |
||
| 6079 | * @params array question list |
||
| 6080 | * @params bool expand or not question list (true show all questions, false show media question id instead of the question ids) |
||
| 6081 | * |
||
| 6082 | **/ |
||
| 6083 | View Code Duplication | public function transformQuestionListWithMedias($question_list, $expand_media_questions = false) |
|
| 6126 | |||
| 6127 | function get_validated_question_list() |
||
| 6189 | |||
| 6190 | function get_question_list($expand_media_questions = false) |
||
| 6196 | |||
| 6197 | View Code Duplication | function transform_question_list_with_medias($question_list, $expand_media_questions = false) |
|
| 6238 | |||
| 6239 | /** |
||
| 6240 | * @param int $exe_id |
||
| 6241 | * @return array|mixed |
||
| 6242 | */ |
||
| 6243 | public function get_stat_track_exercise_info_by_exe_id($exe_id) |
||
| 6273 | |||
| 6274 | public function edit_question_to_remind($exe_id, $question_id, $action = 'add') |
||
| 6321 | |||
| 6322 | public function fill_in_blank_answer_to_array($answer) |
||
| 6328 | |||
| 6329 | public function fill_in_blank_answer_to_string($answer) |
||
| 6350 | |||
| 6351 | function return_time_left_div() |
||
| 6367 | |||
| 6368 | function get_count_question_list() |
||
| 6378 | |||
| 6379 | function get_exercise_list_ordered() |
||
| 6380 | { |
||
| 6381 | $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER); |
||
| 6382 | $course_id = api_get_course_int_id(); |
||
| 6383 | $session_id = api_get_session_id(); |
||
| 6384 | $sql = "SELECT exercise_id, exercise_order |
||
| 6385 | FROM $table_exercise_order |
||
| 6386 | WHERE c_id = $course_id AND session_id = $session_id |
||
| 6387 | ORDER BY exercise_order"; |
||
| 6388 | $result = Database::query($sql); |
||
| 6389 | $list = array(); |
||
| 6390 | if (Database::num_rows($result)) { |
||
| 6391 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 6392 | $list[$row['exercise_order']] = $row['exercise_id']; |
||
| 6393 | } |
||
| 6394 | } |
||
| 6395 | return $list; |
||
| 6396 | } |
||
| 6397 | |||
| 6398 | /** |
||
| 6399 | * Get categories added in the exercise--category matrix |
||
| 6400 | * @return bool |
||
| 6401 | */ |
||
| 6402 | public function get_categories_in_exercise() |
||
| 6419 | |||
| 6420 | /** |
||
| 6421 | * @param null $order |
||
| 6422 | * @return bool |
||
| 6423 | */ |
||
| 6424 | public function get_categories_with_name_in_exercise($order = null) |
||
| 6444 | |||
| 6445 | /** |
||
| 6446 | * Get total number of question that will be parsed when using the category/exercise |
||
| 6447 | */ |
||
| 6448 | View Code Duplication | public function getNumberQuestionExerciseCategory() |
|
| 6449 | { |
||
| 6450 | $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); |
||
| 6451 | if (!empty($this->id)) { |
||
| 6452 | $sql = "SELECT SUM(count_questions) count_questions |
||
| 6453 | FROM $table |
||
| 6454 | WHERE exercise_id = {$this->id} AND c_id = {$this->course_id}"; |
||
| 6455 | $result = Database::query($sql); |
||
| 6456 | if (Database::num_rows($result)) { |
||
| 6457 | $row = Database::fetch_array($result); |
||
| 6458 | return $row['count_questions']; |
||
| 6459 | } |
||
| 6460 | } |
||
| 6461 | return 0; |
||
| 6462 | } |
||
| 6463 | |||
| 6464 | /** |
||
| 6465 | * Save categories in the TABLE_QUIZ_REL_CATEGORY table |
||
| 6466 | * @param array $categories |
||
| 6467 | */ |
||
| 6468 | public function save_categories_in_exercise($categories) |
||
| 6488 | |||
| 6489 | /** |
||
| 6490 | * @param array $questionList |
||
| 6491 | * @param int $currentQuestion |
||
| 6492 | * @param array $conditions |
||
| 6493 | * @param string $link |
||
| 6494 | * @return string |
||
| 6495 | */ |
||
| 6496 | public function progressExercisePaginationBar($questionList, $currentQuestion, $conditions, $link) |
||
| 6544 | |||
| 6545 | |||
| 6546 | /** |
||
| 6547 | * Shows a list of numbers that represents the question to answer in a exercise |
||
| 6548 | * |
||
| 6549 | * @param array $categories |
||
| 6550 | * @param int $current |
||
| 6551 | * @param array $conditions |
||
| 6552 | * @param string $link |
||
| 6553 | * @return string |
||
| 6554 | */ |
||
| 6555 | public function progressExercisePaginationBarWithCategories( |
||
| 6678 | |||
| 6679 | /** |
||
| 6680 | * Renders a question list |
||
| 6681 | * |
||
| 6682 | * @param array $questionList (with media questions compressed) |
||
| 6683 | * @param int $currentQuestion |
||
| 6684 | * @param array $exerciseResult |
||
| 6685 | * @param array $attemptList |
||
| 6686 | * @param array $remindList |
||
| 6687 | */ |
||
| 6688 | public function renderQuestionList($questionList, $currentQuestion, $exerciseResult, $attemptList, $remindList) |
||
| 6781 | |||
| 6782 | /** |
||
| 6783 | * @param int $questionId |
||
| 6784 | * @param array $attemptList |
||
| 6785 | * @param array $remindList |
||
| 6786 | * @param int $i |
||
| 6787 | * @param int $current_question |
||
| 6788 | * @param array $questions_in_media |
||
| 6789 | * @param bool $last_question_in_media |
||
| 6790 | * @param array $realQuestionList |
||
| 6791 | * @param bool $generateJS |
||
| 6792 | * @return null |
||
| 6793 | */ |
||
| 6794 | public function renderQuestion( |
||
| 6921 | |||
| 6922 | /** |
||
| 6923 | * Shows a question |
||
| 6924 | * @param Question $objQuestionTmp |
||
| 6925 | * @param bool $only_questions if true only show the questions, no exercise title |
||
| 6926 | * @param bool $origin origin i.e = learnpath |
||
| 6927 | * @param string $current_item current item from the list of questions |
||
| 6928 | * @param bool $show_title |
||
| 6929 | * @param bool $freeze |
||
| 6930 | * @param array $user_choice |
||
| 6931 | * @param bool $show_comment |
||
| 6932 | * @param null $exercise_feedback |
||
| 6933 | * @param bool $show_answers |
||
| 6934 | * @param null $modelType |
||
| 6935 | * @param bool $categoryMinusOne |
||
| 6936 | * @return bool|null|string |
||
| 6937 | */ |
||
| 6938 | public function showQuestion( |
||
| 7820 | |||
| 7821 | /** |
||
| 7822 | * @param int $exeId |
||
| 7823 | * @return array |
||
| 7824 | */ |
||
| 7825 | public function returnQuestionListByAttempt($exeId) |
||
| 7829 | |||
| 7830 | /** |
||
| 7831 | * Display the exercise results |
||
| 7832 | * @param int $exe_id |
||
| 7833 | * @param bool $saveUserResult save users results (true) or just show the results (false) |
||
| 7834 | * @param bool $returnExerciseResult return array with exercise result info |
||
| 7835 | * @return mixed |
||
| 7836 | */ |
||
| 7837 | public function displayQuestionListByAttempt($exe_id, $saveUserResult = false, $returnExerciseResult = false) |
||
| 8101 | |||
| 8102 | /** |
||
| 8103 | * Returns an HTML ribbon to show on top of the exercise result, with |
||
| 8104 | * colouring depending on the success or failure of the student |
||
| 8105 | * @param integer $score |
||
| 8106 | * @param integer $weight |
||
| 8107 | * @param bool $check_pass_percentage |
||
| 8108 | * @return string |
||
| 8109 | */ |
||
| 8110 | public function get_question_ribbon($score, $weight, $check_pass_percentage = false) |
||
| 8147 | |||
| 8148 | /** |
||
| 8149 | * Returns an array of categories details for the questions of the current |
||
| 8150 | * exercise. |
||
| 8151 | * @return array |
||
| 8152 | */ |
||
| 8153 | public function getQuestionWithCategories() |
||
| 8179 | |||
| 8180 | /** |
||
| 8181 | * Calculate the max_score of the quiz, depending of question inside, and quiz advanced option |
||
| 8182 | */ |
||
| 8183 | public function get_max_score() |
||
| 8234 | |||
| 8235 | /** |
||
| 8236 | * @return string |
||
| 8237 | */ |
||
| 8238 | public function get_formated_title() |
||
| 8242 | |||
| 8243 | /** |
||
| 8244 | * @param $in_title |
||
| 8245 | * @return string |
||
| 8246 | */ |
||
| 8247 | public static function get_formated_title_variable($in_title) |
||
| 8251 | |||
| 8252 | /** |
||
| 8253 | * @return string |
||
| 8254 | */ |
||
| 8255 | public function format_title() |
||
| 8259 | |||
| 8260 | /** |
||
| 8261 | * @param $in_title |
||
| 8262 | * @return string |
||
| 8263 | */ |
||
| 8264 | public static function format_title_variable($in_title) |
||
| 8268 | |||
| 8269 | /** |
||
| 8270 | * @param int $courseId |
||
| 8271 | * @param int $sessionId |
||
| 8272 | * @return array exercises |
||
| 8273 | */ |
||
| 8274 | View Code Duplication | public function getExercisesByCouseSession($courseId, $sessionId) |
|
| 8297 | |||
| 8298 | /** |
||
| 8299 | * |
||
| 8300 | * @param int $courseId |
||
| 8301 | * @param int $sessionId |
||
| 8302 | * @param array $quizId |
||
| 8303 | * @return array exercises |
||
| 8304 | */ |
||
| 8305 | public function getExerciseAndResult($courseId, $sessionId, $quizId = array()) |
||
| 8344 | |||
| 8345 | /** |
||
| 8346 | * @param $exeId |
||
| 8347 | * @param $exercise_stat_info |
||
| 8348 | * @param $remindList |
||
| 8349 | * @param $currentQuestion |
||
| 8350 | * @return int|null |
||
| 8351 | */ |
||
| 8352 | public static function getNextQuestionId($exeId, $exercise_stat_info, $remindList, $currentQuestion) |
||
| 8423 | |||
| 8424 | /** |
||
| 8425 | * Gets the position of a questionId in the question list |
||
| 8426 | * @param $questionId |
||
| 8427 | * @return int |
||
| 8428 | */ |
||
| 8429 | public function getPositionInCompressedQuestionList($questionId) |
||
| 8452 | |||
| 8453 | /** |
||
| 8454 | * Get the correct answers in all attempts |
||
| 8455 | * @param int $learnPathId |
||
| 8456 | * @param int $learnPathItemId |
||
| 8457 | * @return array |
||
| 8458 | */ |
||
| 8459 | public function getCorrectAnswersInAllAttempts($learnPathId = 0, $learnPathItemId = 0) |
||
| 8495 | } |
||
| 8496 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.