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(true); |
||
| 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() |
|
| 707 | |||
| 708 | /** |
||
| 709 | * Gets the question list ordered by the question_order setting (drag and drop) |
||
| 710 | * @return array |
||
| 711 | */ |
||
| 712 | private function getQuestionOrderedList() |
||
| 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( |
||
| 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) |
||
| 1082 | |||
| 1083 | /** |
||
| 1084 | * returns the array with the question ID list |
||
| 1085 | * @param bool $from_db Whether the results should be fetched in the database or just from memory |
||
| 1086 | * @param bool $adminView Whether we should return all questions (admin view) or just a list limited by the max number of random questions |
||
| 1087 | * @author Olivier Brouckaert |
||
| 1088 | * @return array - question ID list |
||
| 1089 | */ |
||
| 1090 | public function selectQuestionList($from_db = false, $adminView = false) |
||
| 1124 | |||
| 1125 | /** |
||
| 1126 | * returns the number of questions in this exercise |
||
| 1127 | * |
||
| 1128 | * @author Olivier Brouckaert |
||
| 1129 | * @return integer - number of questions |
||
| 1130 | */ |
||
| 1131 | public function selectNbrQuestions() |
||
| 1135 | |||
| 1136 | /** |
||
| 1137 | * @return int |
||
| 1138 | */ |
||
| 1139 | public function selectPropagateNeg() |
||
| 1143 | |||
| 1144 | /** |
||
| 1145 | * @return int |
||
| 1146 | */ |
||
| 1147 | public function selectSaveCorrectAnswers() |
||
| 1151 | |||
| 1152 | /** |
||
| 1153 | * Selects questions randomly in the question list |
||
| 1154 | * |
||
| 1155 | * @author Olivier Brouckaert |
||
| 1156 | * @author Hubert Borderiou 15 nov 2011 |
||
| 1157 | * @param bool $adminView Whether we should return all questions (admin view) or just a list limited by the max number of random questions |
||
| 1158 | * @return array - if the exercise is not set to take questions randomly, returns the question list |
||
| 1159 | * without randomizing, otherwise, returns the list with questions selected randomly |
||
| 1160 | */ |
||
| 1161 | public function selectRandomList($adminView = false) |
||
| 1217 | |||
| 1218 | /** |
||
| 1219 | * returns 'true' if the question ID is in the question list |
||
| 1220 | * |
||
| 1221 | * @author Olivier Brouckaert |
||
| 1222 | * @param integer $questionId - question ID |
||
| 1223 | * @return boolean - true if in the list, otherwise false |
||
| 1224 | */ |
||
| 1225 | public function isInList($questionId) |
||
| 1233 | |||
| 1234 | /** |
||
| 1235 | * changes the exercise title |
||
| 1236 | * |
||
| 1237 | * @author Olivier Brouckaert |
||
| 1238 | * @param string $title - exercise title |
||
| 1239 | */ |
||
| 1240 | public function updateTitle($title) |
||
| 1244 | |||
| 1245 | /** |
||
| 1246 | * changes the exercise max attempts |
||
| 1247 | * |
||
| 1248 | * @param int $attempts - exercise max attempts |
||
| 1249 | */ |
||
| 1250 | public function updateAttempts($attempts) |
||
| 1254 | |||
| 1255 | /** |
||
| 1256 | * changes the exercise feedback type |
||
| 1257 | * |
||
| 1258 | * @param int $feedback_type |
||
| 1259 | */ |
||
| 1260 | public function updateFeedbackType($feedback_type) |
||
| 1264 | |||
| 1265 | /** |
||
| 1266 | * changes the exercise description |
||
| 1267 | * |
||
| 1268 | * @author Olivier Brouckaert |
||
| 1269 | * @param string $description - exercise description |
||
| 1270 | */ |
||
| 1271 | public function updateDescription($description) |
||
| 1275 | |||
| 1276 | /** |
||
| 1277 | * changes the exercise expired_time |
||
| 1278 | * |
||
| 1279 | * @author Isaac flores |
||
| 1280 | * @param int $expired_time The expired time of the quiz |
||
| 1281 | */ |
||
| 1282 | public function updateExpiredTime($expired_time) |
||
| 1286 | |||
| 1287 | /** |
||
| 1288 | * @param $value |
||
| 1289 | */ |
||
| 1290 | public function updatePropagateNegative($value) |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * @param $value int |
||
| 1297 | */ |
||
| 1298 | public function updateSaveCorrectAnswers($value) |
||
| 1302 | |||
| 1303 | /** |
||
| 1304 | * @param $value |
||
| 1305 | */ |
||
| 1306 | public function updateReviewAnswers($value) |
||
| 1310 | |||
| 1311 | /** |
||
| 1312 | * @param $value |
||
| 1313 | */ |
||
| 1314 | public function updatePassPercentage($value) |
||
| 1318 | |||
| 1319 | /** |
||
| 1320 | * @param string $text |
||
| 1321 | */ |
||
| 1322 | public function updateEmailNotificationTemplate($text) |
||
| 1326 | |||
| 1327 | /** |
||
| 1328 | * @param string $text |
||
| 1329 | */ |
||
| 1330 | public function updateEmailNotificationTemplateToUser($text) |
||
| 1334 | |||
| 1335 | /** |
||
| 1336 | * @param string $value |
||
| 1337 | */ |
||
| 1338 | public function setNotifyUserByEmail($value) |
||
| 1342 | |||
| 1343 | /** |
||
| 1344 | * @param int $value |
||
| 1345 | */ |
||
| 1346 | public function updateEndButton($value) |
||
| 1350 | |||
| 1351 | /** |
||
| 1352 | * @param string $value |
||
| 1353 | */ |
||
| 1354 | public function setOnSuccessMessage($value) |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * @param string $value |
||
| 1361 | */ |
||
| 1362 | public function setOnFailedMessage($value) |
||
| 1366 | |||
| 1367 | /** |
||
| 1368 | * @param $value |
||
| 1369 | */ |
||
| 1370 | public function setModelType($value) |
||
| 1374 | |||
| 1375 | /** |
||
| 1376 | * @param int $value |
||
| 1377 | */ |
||
| 1378 | public function setQuestionSelectionType($value) |
||
| 1382 | |||
| 1383 | /** |
||
| 1384 | * @return int |
||
| 1385 | */ |
||
| 1386 | public function getQuestionSelectionType() |
||
| 1390 | |||
| 1391 | /** |
||
| 1392 | * @param array $categories |
||
| 1393 | */ |
||
| 1394 | public function updateCategories($categories) |
||
| 1401 | |||
| 1402 | /** |
||
| 1403 | * changes the exercise sound file |
||
| 1404 | * |
||
| 1405 | * @author Olivier Brouckaert |
||
| 1406 | * @param string $sound - exercise sound file |
||
| 1407 | * @param string $delete - ask to delete the file |
||
| 1408 | */ |
||
| 1409 | public function updateSound($sound,$delete) |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * changes the exercise type |
||
| 1451 | * |
||
| 1452 | * @author Olivier Brouckaert |
||
| 1453 | * @param integer $type - exercise type |
||
| 1454 | */ |
||
| 1455 | public function updateType($type) |
||
| 1459 | |||
| 1460 | /** |
||
| 1461 | * sets to 0 if questions are not selected randomly |
||
| 1462 | * if questions are selected randomly, sets the draws |
||
| 1463 | * |
||
| 1464 | * @author Olivier Brouckaert |
||
| 1465 | * @param integer $random - 0 if not random, otherwise the draws |
||
| 1466 | */ |
||
| 1467 | public function setRandom($random) |
||
| 1474 | |||
| 1475 | /** |
||
| 1476 | * sets to 0 if answers are not selected randomly |
||
| 1477 | * if answers are selected randomly |
||
| 1478 | * @author Juan Carlos Rana |
||
| 1479 | * @param integer $random_answers - random answers |
||
| 1480 | */ |
||
| 1481 | public function updateRandomAnswers($random_answers) |
||
| 1485 | |||
| 1486 | /** |
||
| 1487 | * enables the exercise |
||
| 1488 | * |
||
| 1489 | * @author Olivier Brouckaert |
||
| 1490 | */ |
||
| 1491 | public function enable() |
||
| 1495 | |||
| 1496 | /** |
||
| 1497 | * disables the exercise |
||
| 1498 | * |
||
| 1499 | * @author Olivier Brouckaert |
||
| 1500 | */ |
||
| 1501 | public function disable() |
||
| 1505 | |||
| 1506 | /** |
||
| 1507 | * Set disable results |
||
| 1508 | */ |
||
| 1509 | public function disable_results() |
||
| 1513 | |||
| 1514 | /** |
||
| 1515 | * Enable results |
||
| 1516 | */ |
||
| 1517 | public function enable_results() |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * @param int $results_disabled |
||
| 1524 | */ |
||
| 1525 | public function updateResultsDisabled($results_disabled) |
||
| 1529 | |||
| 1530 | /** |
||
| 1531 | * updates the exercise in the data base |
||
| 1532 | * |
||
| 1533 | * @author Olivier Brouckaert |
||
| 1534 | */ |
||
| 1535 | public function save($type_e = '') |
||
| 1721 | |||
| 1722 | /** |
||
| 1723 | * Updates question position |
||
| 1724 | */ |
||
| 1725 | public function update_question_positions() |
||
| 1742 | |||
| 1743 | /** |
||
| 1744 | * Adds a question into the question list |
||
| 1745 | * |
||
| 1746 | * @author Olivier Brouckaert |
||
| 1747 | * @param integer $questionId - question ID |
||
| 1748 | * @return boolean - true if the question has been added, otherwise false |
||
| 1749 | */ |
||
| 1750 | public function addToList($questionId) |
||
| 1769 | |||
| 1770 | /** |
||
| 1771 | * removes a question from the question list |
||
| 1772 | * |
||
| 1773 | * @author Olivier Brouckaert |
||
| 1774 | * @param integer $questionId - question ID |
||
| 1775 | * @return boolean - true if the question has been removed, otherwise false |
||
| 1776 | */ |
||
| 1777 | public function removeFromList($questionId) |
||
| 1800 | |||
| 1801 | /** |
||
| 1802 | * deletes the exercise from the database |
||
| 1803 | * Notice : leaves the question in the data base |
||
| 1804 | * |
||
| 1805 | * @author Olivier Brouckaert |
||
| 1806 | */ |
||
| 1807 | public function delete() |
||
| 1820 | |||
| 1821 | /** |
||
| 1822 | * Creates the form to create / edit an exercise |
||
| 1823 | * @param FormValidator $form |
||
| 1824 | */ |
||
| 1825 | public function createForm($form, $type='full') |
||
| 1826 | { |
||
| 1827 | if (empty($type)) { |
||
| 1828 | $type = 'full'; |
||
| 1829 | } |
||
| 1830 | |||
| 1831 | // form title |
||
| 1832 | if (!empty($_GET['exerciseId'])) { |
||
| 1833 | $form_title = get_lang('ModifyExercise'); |
||
| 1834 | } else { |
||
| 1835 | $form_title = get_lang('NewEx'); |
||
| 1836 | } |
||
| 1837 | |||
| 1838 | $form->addElement('header', $form_title); |
||
| 1839 | |||
| 1840 | // Title. |
||
| 1841 | $form->addElement( |
||
| 1842 | 'text', |
||
| 1843 | 'exerciseTitle', |
||
| 1844 | get_lang('ExerciseName'), |
||
| 1845 | array('id' => 'exercise_title') |
||
| 1846 | ); |
||
| 1847 | |||
| 1848 | $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters')); |
||
| 1849 | $form->addElement('html', '<div id="advanced_params_options" style="display:none">'); |
||
| 1850 | |||
| 1851 | $editor_config = array( |
||
| 1852 | 'ToolbarSet' => 'TestQuestionDescription', |
||
| 1853 | 'Width' => '100%', |
||
| 1854 | 'Height' => '150', |
||
| 1855 | ); |
||
| 1856 | if (is_array($type)){ |
||
| 1857 | $editor_config = array_merge($editor_config, $type); |
||
| 1858 | } |
||
| 1859 | |||
| 1860 | $form->addHtmlEditor( |
||
| 1861 | 'exerciseDescription', |
||
| 1862 | get_lang('ExerciseDescription'), |
||
| 1863 | false, |
||
| 1864 | false, |
||
| 1865 | $editor_config |
||
| 1866 | ); |
||
| 1867 | |||
| 1868 | if ($type == 'full') { |
||
| 1869 | //Can't modify a DirectFeedback question |
||
| 1870 | if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) { |
||
| 1871 | // feedback type |
||
| 1872 | $radios_feedback = array(); |
||
| 1873 | $radios_feedback[] = $form->createElement( |
||
| 1874 | 'radio', |
||
| 1875 | 'exerciseFeedbackType', |
||
| 1876 | null, |
||
| 1877 | get_lang('ExerciseAtTheEndOfTheTest'), |
||
| 1878 | '0', |
||
| 1879 | array( |
||
| 1880 | 'id' => 'exerciseType_0', |
||
| 1881 | 'onclick' => 'check_feedback()', |
||
| 1882 | ) |
||
| 1883 | ); |
||
| 1884 | |||
| 1885 | View Code Duplication | if (api_get_setting('enable_quiz_scenario') == 'true') { |
|
| 1886 | //Can't convert a question from one feedback to another if there is more than 1 question already added |
||
| 1887 | if ($this->selectNbrQuestions() == 0) { |
||
| 1888 | $radios_feedback[] = $form->createElement( |
||
| 1889 | 'radio', |
||
| 1890 | 'exerciseFeedbackType', |
||
| 1891 | null, |
||
| 1892 | get_lang('DirectFeedback'), |
||
| 1893 | '1', |
||
| 1894 | array( |
||
| 1895 | 'id' => 'exerciseType_1', |
||
| 1896 | 'onclick' => 'check_direct_feedback()', |
||
| 1897 | ) |
||
| 1898 | ); |
||
| 1899 | } |
||
| 1900 | } |
||
| 1901 | |||
| 1902 | $radios_feedback[] = $form->createElement( |
||
| 1903 | 'radio', |
||
| 1904 | 'exerciseFeedbackType', |
||
| 1905 | null, |
||
| 1906 | get_lang('NoFeedback'), |
||
| 1907 | '2', |
||
| 1908 | array('id' => 'exerciseType_2') |
||
| 1909 | ); |
||
| 1910 | $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'),get_lang('FeedbackDisplayOptions'))); |
||
| 1911 | |||
| 1912 | // Type of results display on the final page |
||
| 1913 | $radios_results_disabled = array(); |
||
| 1914 | $radios_results_disabled[] = $form->createElement( |
||
| 1915 | 'radio', |
||
| 1916 | 'results_disabled', |
||
| 1917 | null, |
||
| 1918 | get_lang('ShowScoreAndRightAnswer'), |
||
| 1919 | '0', |
||
| 1920 | array('id' => 'result_disabled_0') |
||
| 1921 | ); |
||
| 1922 | $radios_results_disabled[] = $form->createElement( |
||
| 1923 | 'radio', |
||
| 1924 | 'results_disabled', |
||
| 1925 | null, |
||
| 1926 | get_lang('DoNotShowScoreNorRightAnswer'), |
||
| 1927 | '1', |
||
| 1928 | array('id' => 'result_disabled_1', 'onclick' => 'check_results_disabled()') |
||
| 1929 | ); |
||
| 1930 | $radios_results_disabled[] = $form->createElement( |
||
| 1931 | 'radio', |
||
| 1932 | 'results_disabled', |
||
| 1933 | null, |
||
| 1934 | get_lang('OnlyShowScore'), |
||
| 1935 | '2', |
||
| 1936 | array('id' => 'result_disabled_2') |
||
| 1937 | ); |
||
| 1938 | |||
| 1939 | |||
| 1940 | $radios_results_disabled[] = $form->createElement( |
||
| 1941 | 'radio', |
||
| 1942 | 'results_disabled', |
||
| 1943 | null, |
||
| 1944 | get_lang('ShowScoreEveryAttemptShowAnswersLastAttempt'), |
||
| 1945 | '4', |
||
| 1946 | array('id' => 'result_disabled_4') |
||
| 1947 | ); |
||
| 1948 | |||
| 1949 | $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents')); |
||
| 1950 | |||
| 1951 | // Type of questions disposition on page |
||
| 1952 | $radios = array(); |
||
| 1953 | |||
| 1954 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all')); |
||
| 1955 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one')); |
||
| 1956 | |||
| 1957 | $form->addGroup($radios, null, get_lang('QuestionsPerPage')); |
||
| 1958 | |||
| 1959 | } else { |
||
| 1960 | // if is Directfeedback but has not questions we can allow to modify the question type |
||
| 1961 | if ($this->selectNbrQuestions() == 0) { |
||
| 1962 | |||
| 1963 | // feedback type |
||
| 1964 | $radios_feedback = array(); |
||
| 1965 | $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'),'0',array('id' =>'exerciseType_0', 'onclick' => 'check_feedback()')); |
||
| 1966 | |||
| 1967 | View Code Duplication | if (api_get_setting('enable_quiz_scenario') == 'true') { |
|
| 1968 | $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' =>'exerciseType_1' , 'onclick' => 'check_direct_feedback()')); |
||
| 1969 | } |
||
| 1970 | $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'),'2',array('id' =>'exerciseType_2')); |
||
| 1971 | $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'),get_lang('FeedbackDisplayOptions'))); |
||
| 1972 | |||
| 1973 | //$form->addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"'); |
||
| 1974 | $radios_results_disabled = array(); |
||
| 1975 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0')); |
||
| 1976 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()')); |
||
| 1977 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()')); |
||
| 1978 | $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'),''); |
||
| 1979 | |||
| 1980 | // Type of questions disposition on page |
||
| 1981 | $radios = array(); |
||
| 1982 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1'); |
||
| 1983 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2'); |
||
| 1984 | $form->addGroup($radios, null, get_lang('ExerciseType')); |
||
| 1985 | |||
| 1986 | } else { |
||
| 1987 | //Show options freeze |
||
| 1988 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0')); |
||
| 1989 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()')); |
||
| 1990 | $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()')); |
||
| 1991 | $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents')); |
||
| 1992 | $result_disable_group->freeze(); |
||
| 1993 | |||
| 1994 | //we force the options to the DirectFeedback exercisetype |
||
| 1995 | $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT); |
||
| 1996 | $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE); |
||
| 1997 | |||
| 1998 | // Type of questions disposition on page |
||
| 1999 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all')); |
||
| 2000 | $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one')); |
||
| 2001 | |||
| 2002 | $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage')); |
||
| 2003 | $type_group->freeze(); |
||
| 2004 | } |
||
| 2005 | } |
||
| 2006 | |||
| 2007 | if (true) { |
||
| 2008 | $option = array( |
||
| 2009 | EX_Q_SELECTION_ORDERED => get_lang('OrderedByUser'), |
||
| 2010 | // defined by user |
||
| 2011 | EX_Q_SELECTION_RANDOM => get_lang('Random'), |
||
| 2012 | // 1-10, All |
||
| 2013 | 'per_categories' => '--------'.get_lang( |
||
| 2014 | 'UsingCategories' |
||
| 2015 | ).'----------', |
||
| 2016 | |||
| 2017 | // Base (A 123 {3} B 456 {3} C 789{2} D 0{0}) --> Matrix {3, 3, 2, 0} |
||
| 2018 | EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED => get_lang( |
||
| 2019 | 'OrderedCategoriesAlphabeticallyWithQuestionsOrdered' |
||
| 2020 | ), |
||
| 2021 | // A 123 B 456 C 78 (0, 1, all) |
||
| 2022 | EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED => get_lang( |
||
| 2023 | 'RandomCategoriesWithQuestionsOrdered' |
||
| 2024 | ), |
||
| 2025 | // C 78 B 456 A 123 |
||
| 2026 | |||
| 2027 | EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_RANDOM => get_lang( |
||
| 2028 | 'OrderedCategoriesAlphabeticallyWithRandomQuestions' |
||
| 2029 | ), |
||
| 2030 | // A 321 B 654 C 87 |
||
| 2031 | EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM => get_lang( |
||
| 2032 | 'RandomCategoriesWithRandomQuestions' |
||
| 2033 | ), |
||
| 2034 | //C 87 B 654 A 321 |
||
| 2035 | |||
| 2036 | //EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_ORDERED_NO_GROUPED => get_lang('RandomCategoriesWithQuestionsOrderedNoQuestionGrouped'), |
||
| 2037 | /* B 456 C 78 A 123 |
||
| 2038 | 456 78 123 |
||
| 2039 | 123 456 78 |
||
| 2040 | */ |
||
| 2041 | //EX_Q_SELECTION_CATEGORIES_RANDOM_QUESTIONS_RANDOM_NO_GROUPED => get_lang('RandomCategoriesWithRandomQuestionsNoQuestionGrouped'), |
||
| 2042 | /* |
||
| 2043 | A 123 B 456 C 78 |
||
| 2044 | B 456 C 78 A 123 |
||
| 2045 | B 654 C 87 A 321 |
||
| 2046 | 654 87 321 |
||
| 2047 | 165 842 73 |
||
| 2048 | */ |
||
| 2049 | //EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_ORDERED => get_lang('OrderedCategoriesByParentWithQuestionsOrdered'), |
||
| 2050 | //EX_Q_SELECTION_CATEGORIES_ORDERED_BY_PARENT_QUESTIONS_RANDOM => get_lang('OrderedCategoriesByParentWithQuestionsRandom'), |
||
| 2051 | ); |
||
| 2052 | |||
| 2053 | $form->addElement( |
||
| 2054 | 'select', |
||
| 2055 | 'question_selection_type', |
||
| 2056 | array(get_lang('QuestionSelection')), |
||
| 2057 | $option, |
||
| 2058 | array( |
||
| 2059 | 'id' => 'questionSelection', |
||
| 2060 | 'onchange' => 'checkQuestionSelection()' |
||
| 2061 | ) |
||
| 2062 | ); |
||
| 2063 | |||
| 2064 | $displayMatrix = 'none'; |
||
| 2065 | $displayRandom = 'none'; |
||
| 2066 | $selectionType = $this->getQuestionSelectionType(); |
||
| 2067 | switch ($selectionType) { |
||
| 2068 | case EX_Q_SELECTION_RANDOM: |
||
| 2069 | $displayRandom = 'block'; |
||
| 2070 | break; |
||
| 2071 | case $selectionType >= EX_Q_SELECTION_CATEGORIES_ORDERED_QUESTIONS_ORDERED: |
||
| 2072 | $displayMatrix = 'block'; |
||
| 2073 | break; |
||
| 2074 | } |
||
| 2075 | |||
| 2076 | $form->addElement( |
||
| 2077 | 'html', |
||
| 2078 | '<div id="hidden_random" style="display:'.$displayRandom.'">' |
||
| 2079 | ); |
||
| 2080 | // Number of random question. |
||
| 2081 | $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10; |
||
| 2082 | $option = range(0, $max); |
||
| 2083 | $option[0] = get_lang('No'); |
||
| 2084 | $option[-1] = get_lang('AllQuestionsShort'); |
||
| 2085 | $form->addElement( |
||
| 2086 | 'select', |
||
| 2087 | 'randomQuestions', |
||
| 2088 | array( |
||
| 2089 | get_lang('RandomQuestions'), |
||
| 2090 | get_lang('RandomQuestionsHelp') |
||
| 2091 | ), |
||
| 2092 | $option, |
||
| 2093 | array('id' => 'randomQuestions') |
||
| 2094 | ); |
||
| 2095 | $form->addElement('html', '</div>'); |
||
| 2096 | |||
| 2097 | $form->addElement( |
||
| 2098 | 'html', |
||
| 2099 | '<div id="hidden_matrix" style="display:'.$displayMatrix.'">' |
||
| 2100 | ); |
||
| 2101 | |||
| 2102 | // Category selection. |
||
| 2103 | $cat = new TestCategory(); |
||
| 2104 | $cat_form = $cat->returnCategoryForm($this); |
||
| 2105 | if (empty($cat_form)) { |
||
| 2106 | $cat_form = '<span class="label label-warning">' . get_lang('NoCategoriesDefined') . '</span>'; |
||
| 2107 | } |
||
| 2108 | $form->addElement('label', null, $cat_form); |
||
| 2109 | $form->addElement('html', '</div>'); |
||
| 2110 | |||
| 2111 | // Category name. |
||
| 2112 | $radio_display_cat_name = array( |
||
| 2113 | $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'), |
||
| 2114 | $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0') |
||
| 2115 | ); |
||
| 2116 | $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName')); |
||
| 2117 | |||
| 2118 | // Random answers. |
||
| 2119 | $radios_random_answers = array( |
||
| 2120 | $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'), '1'), |
||
| 2121 | $form->createElement('radio', 'randomAnswers', null, get_lang('No'), '0') |
||
| 2122 | ); |
||
| 2123 | $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers')); |
||
| 2124 | |||
| 2125 | // Hide question title. |
||
| 2126 | $group = array( |
||
| 2127 | $form->createElement('radio', 'hide_question_title', null, get_lang('Yes'), '1'), |
||
| 2128 | $form->createElement('radio', 'hide_question_title', null, get_lang('No'), '0') |
||
| 2129 | ); |
||
| 2130 | $form->addGroup($group, null, get_lang('HideQuestionTitle')); |
||
| 2131 | } else { |
||
| 2132 | |||
| 2133 | // number of random question |
||
| 2134 | /* |
||
| 2135 | $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10 ; |
||
| 2136 | $option = range(0, $max); |
||
| 2137 | $option[0] = get_lang('No'); |
||
| 2138 | $option[-1] = get_lang('AllQuestionsShort'); |
||
| 2139 | $form->addElement('select', 'randomQuestions',array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id'=>'randomQuestions')); |
||
| 2140 | |||
| 2141 | // Random answers |
||
| 2142 | $radios_random_answers = array(); |
||
| 2143 | $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'),'1'); |
||
| 2144 | $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('No'),'0'); |
||
| 2145 | $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), ''); |
||
| 2146 | |||
| 2147 | // Random by category |
||
| 2148 | $form->addElement('html','<div class="clear"> </div>'); |
||
| 2149 | $radiocat = array(); |
||
| 2150 | $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesShuffled'),'1'); |
||
| 2151 | $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesSorted'),'2'); |
||
| 2152 | $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('No'),'0'); |
||
| 2153 | $radioCatGroup = $form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'), ''); |
||
| 2154 | $form->addElement('html','<div class="clear"> </div>'); |
||
| 2155 | |||
| 2156 | // add the radio display the category name for student |
||
| 2157 | $radio_display_cat_name = array(); |
||
| 2158 | $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1'); |
||
| 2159 | $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0'); |
||
| 2160 | $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');*/ |
||
| 2161 | } |
||
| 2162 | // Attempts |
||
| 2163 | $attempt_option = range(0, 10); |
||
| 2164 | $attempt_option[0] = get_lang('Infinite'); |
||
| 2165 | |||
| 2166 | $form->addElement( |
||
| 2167 | 'select', |
||
| 2168 | 'exerciseAttempts', |
||
| 2169 | get_lang('ExerciseAttempts'), |
||
| 2170 | $attempt_option, |
||
| 2171 | ['id' => 'exerciseAttempts'] |
||
| 2172 | ); |
||
| 2173 | |||
| 2174 | // Exercise time limit |
||
| 2175 | $form->addElement('checkbox', 'activate_start_date_check',null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()')); |
||
| 2176 | |||
| 2177 | $var = Exercise::selectTimeLimit(); |
||
| 2178 | |||
| 2179 | if (!empty($this->start_time)) { |
||
| 2180 | $form->addElement('html', '<div id="start_date_div" style="display:block;">'); |
||
| 2181 | } else { |
||
| 2182 | $form->addElement('html', '<div id="start_date_div" style="display:none;">'); |
||
| 2183 | } |
||
| 2184 | |||
| 2185 | $form->addElement('date_time_picker', 'start_time'); |
||
| 2186 | |||
| 2187 | $form->addElement('html','</div>'); |
||
| 2188 | |||
| 2189 | $form->addElement('checkbox', 'activate_end_date_check', null , get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()')); |
||
| 2190 | |||
| 2191 | if (!empty($this->end_time)) { |
||
| 2192 | $form->addElement('html', '<div id="end_date_div" style="display:block;">'); |
||
| 2193 | } else { |
||
| 2194 | $form->addElement('html', '<div id="end_date_div" style="display:none;">'); |
||
| 2195 | } |
||
| 2196 | |||
| 2197 | $form->addElement('date_time_picker', 'end_time'); |
||
| 2198 | $form->addElement('html','</div>'); |
||
| 2199 | |||
| 2200 | //$check_option=$this->selectType(); |
||
| 2201 | $diplay = 'block'; |
||
| 2202 | $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults')); |
||
| 2203 | $form->addCheckBox( |
||
| 2204 | 'save_correct_answers', |
||
| 2205 | null, |
||
| 2206 | get_lang('SaveTheCorrectAnswersForTheNextAttempt') |
||
| 2207 | ); |
||
| 2208 | $form->addElement('html','<div class="clear"> </div>'); |
||
| 2209 | $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers')); |
||
| 2210 | |||
| 2211 | $form->addElement('html','<div id="divtimecontrol" style="display:'.$diplay.';">'); |
||
| 2212 | |||
| 2213 | //Timer control |
||
| 2214 | //$time_hours_option = range(0,12); |
||
| 2215 | //$time_minutes_option = range(0,59); |
||
| 2216 | $form->addElement( |
||
| 2217 | 'checkbox', |
||
| 2218 | 'enabletimercontrol', |
||
| 2219 | null, |
||
| 2220 | get_lang('EnableTimerControl'), |
||
| 2221 | array( |
||
| 2222 | 'onclick' => 'option_time_expired()', |
||
| 2223 | 'id' => 'enabletimercontrol', |
||
| 2224 | 'onload' => 'check_load_time()', |
||
| 2225 | ) |
||
| 2226 | ); |
||
| 2227 | |||
| 2228 | $expired_date = (int)$this->selectExpiredTime(); |
||
| 2229 | |||
| 2230 | if (($expired_date!='0')) { |
||
| 2231 | $form->addElement('html','<div id="timercontrol" style="display:block;">'); |
||
| 2232 | } else { |
||
| 2233 | $form->addElement('html','<div id="timercontrol" style="display:none;">'); |
||
| 2234 | } |
||
| 2235 | $form->addText( |
||
| 2236 | 'enabletimercontroltotalminutes', |
||
| 2237 | get_lang('ExerciseTotalDurationInMinutes'), |
||
| 2238 | false, |
||
| 2239 | [ |
||
| 2240 | 'id' => 'enabletimercontroltotalminutes', |
||
| 2241 | 'cols-size' => [2, 2, 8] |
||
| 2242 | ] |
||
| 2243 | ); |
||
| 2244 | $form->addElement('html','</div>'); |
||
| 2245 | |||
| 2246 | $form->addElement( |
||
| 2247 | 'text', |
||
| 2248 | 'pass_percentage', |
||
| 2249 | array(get_lang('PassPercentage'), null, '%'), |
||
| 2250 | array('id' => 'pass_percentage') |
||
| 2251 | ); |
||
| 2252 | |||
| 2253 | $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric'); |
||
| 2254 | $form->addRule('pass_percentage', get_lang('ValueTooSmall'), 'min_numeric_length', 0); |
||
| 2255 | $form->addRule('pass_percentage', get_lang('ValueTooBig'), 'max_numeric_length', 100); |
||
| 2256 | |||
| 2257 | // add the text_when_finished textbox |
||
| 2258 | $form->addHtmlEditor( |
||
| 2259 | 'text_when_finished', |
||
| 2260 | get_lang('TextWhenFinished'), |
||
| 2261 | false, |
||
| 2262 | false, |
||
| 2263 | $editor_config |
||
| 2264 | ); |
||
| 2265 | |||
| 2266 | $defaults = array(); |
||
| 2267 | |||
| 2268 | if (api_get_setting('search_enabled') === 'true') { |
||
| 2269 | require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; |
||
| 2270 | |||
| 2271 | $form->addElement('checkbox', 'index_document', '', get_lang('SearchFeatureDoIndexDocument')); |
||
| 2272 | $form->addElement('select_language', 'language', get_lang('SearchFeatureDocumentLanguage')); |
||
| 2273 | |||
| 2274 | $specific_fields = get_specific_field_list(); |
||
| 2275 | |||
| 2276 | foreach ($specific_fields as $specific_field) { |
||
| 2277 | $form->addElement ('text', $specific_field['code'], $specific_field['name']); |
||
| 2278 | $filter = array( |
||
| 2279 | 'c_id' => api_get_course_int_id(), |
||
| 2280 | 'field_id' => $specific_field['id'], |
||
| 2281 | 'ref_id' => $this->id, |
||
| 2282 | 'tool_id' => "'" . TOOL_QUIZ . "'" |
||
| 2283 | ); |
||
| 2284 | $values = get_specific_field_values_list($filter, array('value')); |
||
| 2285 | if ( !empty($values) ) { |
||
| 2286 | $arr_str_values = array(); |
||
| 2287 | foreach ($values as $value) { |
||
| 2288 | $arr_str_values[] = $value['value']; |
||
| 2289 | } |
||
| 2290 | $defaults[$specific_field['code']] = implode(', ', $arr_str_values); |
||
| 2291 | } |
||
| 2292 | } |
||
| 2293 | } |
||
| 2294 | |||
| 2295 | $form->addElement('html','</div>'); //End advanced setting |
||
| 2296 | $form->addElement('html','</div>'); |
||
| 2297 | } |
||
| 2298 | |||
| 2299 | // submit |
||
| 2300 | if (isset($_GET['exerciseId'])) { |
||
| 2301 | $form->addButtonSave(get_lang('ModifyExercise'), 'submitExercise'); |
||
| 2302 | } else { |
||
| 2303 | $form->addButtonUpdate(get_lang('ProcedToQuestions'), 'submitExercise'); |
||
| 2304 | } |
||
| 2305 | |||
| 2306 | $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required'); |
||
| 2307 | |||
| 2308 | if ($type == 'full') { |
||
| 2309 | // rules |
||
| 2310 | $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric'); |
||
| 2311 | $form->addRule('start_time', get_lang('InvalidDate'), 'datetime'); |
||
| 2312 | $form->addRule('end_time', get_lang('InvalidDate'), 'datetime'); |
||
| 2313 | } |
||
| 2314 | |||
| 2315 | // defaults |
||
| 2316 | if ($type=='full') { |
||
| 2317 | if ($this->id > 0) { |
||
| 2318 | if ($this->random > $this->selectNbrQuestions()) { |
||
| 2319 | $defaults['randomQuestions'] = $this->selectNbrQuestions(); |
||
| 2320 | } else { |
||
| 2321 | $defaults['randomQuestions'] = $this->random; |
||
| 2322 | } |
||
| 2323 | |||
| 2324 | $defaults['randomAnswers'] = $this->selectRandomAnswers(); |
||
| 2325 | $defaults['exerciseType'] = $this->selectType(); |
||
| 2326 | $defaults['exerciseTitle'] = $this->get_formated_title(); |
||
| 2327 | $defaults['exerciseDescription'] = $this->selectDescription(); |
||
| 2328 | $defaults['exerciseAttempts'] = $this->selectAttempts(); |
||
| 2329 | $defaults['exerciseFeedbackType'] = $this->selectFeedbackType(); |
||
| 2330 | $defaults['results_disabled'] = $this->selectResultsDisabled(); |
||
| 2331 | $defaults['propagate_neg'] = $this->selectPropagateNeg(); |
||
| 2332 | $defaults['save_correct_answers'] = $this->selectSaveCorrectAnswers(); |
||
| 2333 | $defaults['review_answers'] = $this->review_answers; |
||
| 2334 | $defaults['randomByCat'] = $this->selectRandomByCat(); |
||
| 2335 | $defaults['text_when_finished'] = $this->selectTextWhenFinished(); |
||
| 2336 | $defaults['display_category_name'] = $this->selectDisplayCategoryName(); |
||
| 2337 | $defaults['pass_percentage'] = $this->selectPassPercentage(); |
||
| 2338 | $defaults['question_selection_type'] = $this->getQuestionSelectionType(); |
||
| 2339 | $defaults['hide_question_title'] = $this->getHideQuestionTitle(); |
||
| 2340 | |||
| 2341 | if (!empty($this->start_time)) { |
||
| 2342 | $defaults['activate_start_date_check'] = 1; |
||
| 2343 | } |
||
| 2344 | if (!empty($this->end_time)) { |
||
| 2345 | $defaults['activate_end_date_check'] = 1; |
||
| 2346 | } |
||
| 2347 | |||
| 2348 | $defaults['start_time'] = !empty($this->start_time) ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00'); |
||
| 2349 | $defaults['end_time'] = empty($this->end_time) ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time()+84600); |
||
| 2350 | |||
| 2351 | // Get expired time |
||
| 2352 | if ($this->expired_time != '0') { |
||
| 2353 | $defaults['enabletimercontrol'] = 1; |
||
| 2354 | $defaults['enabletimercontroltotalminutes'] = $this->expired_time; |
||
| 2355 | } else { |
||
| 2356 | $defaults['enabletimercontroltotalminutes'] = 0; |
||
| 2357 | } |
||
| 2358 | } else { |
||
| 2359 | $defaults['exerciseType'] = 2; |
||
| 2360 | $defaults['exerciseAttempts'] = 0; |
||
| 2361 | $defaults['randomQuestions'] = 0; |
||
| 2362 | $defaults['randomAnswers'] = 0; |
||
| 2363 | $defaults['exerciseDescription'] = ''; |
||
| 2364 | $defaults['exerciseFeedbackType'] = 0; |
||
| 2365 | $defaults['results_disabled'] = 0; |
||
| 2366 | $defaults['randomByCat'] = 0; |
||
| 2367 | $defaults['text_when_finished'] = ''; |
||
| 2368 | $defaults['start_time'] = date('Y-m-d 12:00:00'); |
||
| 2369 | $defaults['display_category_name'] = 1; |
||
| 2370 | $defaults['end_time'] = date('Y-m-d 12:00:00', time()+84600); |
||
| 2371 | $defaults['pass_percentage'] = ''; |
||
| 2372 | $defaults['end_button'] = $this->selectEndButton(); |
||
| 2373 | $defaults['question_selection_type'] = 1; |
||
| 2374 | $defaults['hide_question_title'] = 0; |
||
| 2375 | $defaults['on_success_message'] = null; |
||
| 2376 | $defaults['on_failed_message'] = null; |
||
| 2377 | } |
||
| 2378 | } else { |
||
| 2379 | $defaults['exerciseTitle'] = $this->selectTitle(); |
||
| 2380 | $defaults['exerciseDescription'] = $this->selectDescription(); |
||
| 2381 | } |
||
| 2382 | if (api_get_setting('search_enabled') === 'true') { |
||
| 2383 | $defaults['index_document'] = 'checked="checked"'; |
||
| 2384 | } |
||
| 2385 | $form->setDefaults($defaults); |
||
| 2386 | |||
| 2387 | // Freeze some elements. |
||
| 2388 | if ($this->id != 0 && $this->edit_exercise_in_lp == false) { |
||
| 2389 | $elementsToFreeze = array( |
||
| 2390 | 'randomQuestions', |
||
| 2391 | //'randomByCat', |
||
| 2392 | 'exerciseAttempts', |
||
| 2393 | 'propagate_neg', |
||
| 2394 | 'enabletimercontrol', |
||
| 2395 | 'review_answers' |
||
| 2396 | ); |
||
| 2397 | |||
| 2398 | foreach ($elementsToFreeze as $elementName) { |
||
| 2399 | /** @var HTML_QuickForm_element $element */ |
||
| 2400 | $element = $form->getElement($elementName); |
||
| 2401 | $element->freeze(); |
||
| 2402 | } |
||
| 2403 | |||
| 2404 | //$radioCatGroup->freeze(); |
||
| 2405 | } |
||
| 2406 | } |
||
| 2407 | |||
| 2408 | /** |
||
| 2409 | * function which process the creation of exercises |
||
| 2410 | * @param FormValidator $form |
||
| 2411 | * @param string |
||
| 2412 | */ |
||
| 2413 | public function processCreation($form, $type = '') |
||
| 2476 | |||
| 2477 | function search_engine_save() |
||
| 2478 | { |
||
| 2479 | if ($_POST['index_document'] != 1) { |
||
| 2480 | return; |
||
| 2481 | } |
||
| 2482 | $course_id = api_get_course_id(); |
||
| 2483 | |||
| 2484 | require_once api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.class.php'; |
||
| 2485 | require_once api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php'; |
||
| 2486 | require_once api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php'; |
||
| 2487 | |||
| 2488 | $specific_fields = get_specific_field_list(); |
||
| 2489 | $ic_slide = new IndexableChunk(); |
||
| 2490 | |||
| 2491 | $all_specific_terms = ''; |
||
| 2492 | View Code Duplication | foreach ($specific_fields as $specific_field) { |
|
| 2493 | if (isset($_REQUEST[$specific_field['code']])) { |
||
| 2494 | $sterms = trim($_REQUEST[$specific_field['code']]); |
||
| 2495 | if (!empty($sterms)) { |
||
| 2496 | $all_specific_terms .= ' '. $sterms; |
||
| 2497 | $sterms = explode(',', $sterms); |
||
| 2498 | foreach ($sterms as $sterm) { |
||
| 2499 | $ic_slide->addTerm(trim($sterm), $specific_field['code']); |
||
| 2500 | add_specific_field_value($specific_field['id'], $course_id, TOOL_QUIZ, $this->id, $sterm); |
||
| 2501 | } |
||
| 2502 | } |
||
| 2503 | } |
||
| 2504 | } |
||
| 2505 | |||
| 2506 | // build the chunk to index |
||
| 2507 | $ic_slide->addValue("title", $this->exercise); |
||
| 2508 | $ic_slide->addCourseId($course_id); |
||
| 2509 | $ic_slide->addToolId(TOOL_QUIZ); |
||
| 2510 | $xapian_data = array( |
||
| 2511 | SE_COURSE_ID => $course_id, |
||
| 2512 | SE_TOOL_ID => TOOL_QUIZ, |
||
| 2513 | SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_EXERCISE, 'exercise_id' => (int)$this->id), |
||
| 2514 | SE_USER => (int)api_get_user_id(), |
||
| 2515 | ); |
||
| 2516 | $ic_slide->xapian_data = serialize($xapian_data); |
||
| 2517 | $exercise_description = $all_specific_terms .' '. $this->description; |
||
| 2518 | $ic_slide->addValue("content", $exercise_description); |
||
| 2519 | |||
| 2520 | $di = new ChamiloIndexer(); |
||
| 2521 | isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english'; |
||
| 2522 | $di->connectDb(NULL, NULL, $lang); |
||
| 2523 | $di->addChunk($ic_slide); |
||
| 2524 | |||
| 2525 | //index and return search engine document id |
||
| 2526 | $did = $di->index(); |
||
| 2527 | if ($did) { |
||
| 2528 | // save it to db |
||
| 2529 | $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); |
||
| 2530 | $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did) |
||
| 2531 | VALUES (NULL , \'%s\', \'%s\', %s, %s)'; |
||
| 2532 | $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id, $did); |
||
| 2533 | Database::query($sql); |
||
| 2534 | } |
||
| 2535 | } |
||
| 2536 | |||
| 2537 | function search_engine_edit() |
||
| 2612 | |||
| 2613 | function search_engine_delete() |
||
| 2651 | |||
| 2652 | public function selectExpiredTime() |
||
| 2656 | |||
| 2657 | /** |
||
| 2658 | * Cleans the student's results only for the Exercise tool (Not from the LP) |
||
| 2659 | * The LP results are NOT deleted by default, otherwise put $cleanLpTests = true |
||
| 2660 | * Works with exercises in sessions |
||
| 2661 | * @param bool $cleanLpTests |
||
| 2662 | * @param string $cleanResultBeforeDate |
||
| 2663 | * |
||
| 2664 | * @return int quantity of user's exercises deleted |
||
| 2665 | */ |
||
| 2666 | public function clean_results($cleanLpTests = false, $cleanResultBeforeDate = null) |
||
| 2736 | |||
| 2737 | /** |
||
| 2738 | * Copies an exercise (duplicate all questions and answers) |
||
| 2739 | */ |
||
| 2740 | public function copy_exercise() |
||
| 2774 | |||
| 2775 | /** |
||
| 2776 | * Changes the exercise id |
||
| 2777 | * |
||
| 2778 | * @param int $id - exercise id |
||
| 2779 | */ |
||
| 2780 | private function updateId($id) |
||
| 2784 | |||
| 2785 | /** |
||
| 2786 | * Changes the exercise status |
||
| 2787 | * |
||
| 2788 | * @param string $status - exercise status |
||
| 2789 | */ |
||
| 2790 | function updateStatus($status) |
||
| 2794 | |||
| 2795 | /** |
||
| 2796 | * @param int $lp_id |
||
| 2797 | * @param int $lp_item_id |
||
| 2798 | * @param int $lp_item_view_id |
||
| 2799 | * @param string $status |
||
| 2800 | * @return array |
||
| 2801 | */ |
||
| 2802 | public function get_stat_track_exercise_info( |
||
| 2838 | |||
| 2839 | /** |
||
| 2840 | * Saves a test attempt |
||
| 2841 | * |
||
| 2842 | * @param int clock_expired_time |
||
| 2843 | * @param int int lp id |
||
| 2844 | * @param int int lp item id |
||
| 2845 | * @param int int lp item_view id |
||
| 2846 | * @param float $weight |
||
| 2847 | * @param array question list |
||
| 2848 | */ |
||
| 2849 | public function save_stat_track_exercise_info( |
||
| 2899 | |||
| 2900 | /** |
||
| 2901 | * @param int $question_id |
||
| 2902 | * @param int $questionNum |
||
| 2903 | * @param array $questions_in_media |
||
| 2904 | * @param string $currentAnswer |
||
| 2905 | * @return string |
||
| 2906 | */ |
||
| 2907 | public function show_button($question_id, $questionNum, $questions_in_media = array(), $currentAnswer = '') |
||
| 2993 | |||
| 2994 | /** |
||
| 2995 | * So the time control will work |
||
| 2996 | * |
||
| 2997 | * @param string $time_left |
||
| 2998 | * @return string |
||
| 2999 | */ |
||
| 3000 | public function show_time_control_js($time_left) |
||
| 3088 | |||
| 3089 | /** |
||
| 3090 | * Lp javascript for hotspots |
||
| 3091 | */ |
||
| 3092 | public function show_lp_javascript() |
||
| 3096 | |||
| 3097 | /** |
||
| 3098 | * This function was originally found in the exercise_show.php |
||
| 3099 | * @param int $exeId |
||
| 3100 | * @param int $questionId |
||
| 3101 | * @param int $choice the user selected |
||
| 3102 | * @param string $from function is called from 'exercise_show' or 'exercise_result' |
||
| 3103 | * @param array $exerciseResultCoordinates the hotspot coordinates $hotspot[$question_id] = coordinates |
||
| 3104 | * @param bool $saved_results save results in the DB or just show the reponse |
||
| 3105 | * @param bool $from_database gets information from DB or from the current selection |
||
| 3106 | * @param bool $show_result show results or not |
||
| 3107 | * @param int $propagate_neg |
||
| 3108 | * @param array $hotspot_delineation_result |
||
| 3109 | * @param boolean $showTotalScoreAndUserChoicesInLastAttempt |
||
| 3110 | * @todo reduce parameters of this function |
||
| 3111 | * @return string html code |
||
| 3112 | */ |
||
| 3113 | public function manage_answer( |
||
| 3114 | $exeId, |
||
| 3115 | $questionId, |
||
| 3116 | $choice, |
||
| 3117 | $from = 'exercise_show', |
||
| 3118 | $exerciseResultCoordinates = array(), |
||
| 3119 | $saved_results = true, |
||
| 3120 | $from_database = false, |
||
| 3121 | $show_result = true, |
||
| 3122 | $propagate_neg = 0, |
||
| 3123 | $hotspot_delineation_result = array(), |
||
| 3124 | $showTotalScoreAndUserChoicesInLastAttempt = true |
||
| 3125 | ) { |
||
| 3126 | global $debug; |
||
| 3127 | //needed in order to use in the exercise_attempt() for the time |
||
| 3128 | global $learnpath_id, $learnpath_item_id; |
||
| 3129 | require_once api_get_path(LIBRARY_PATH).'geometry.lib.php'; |
||
| 3130 | |||
| 3131 | $em = Database::getManager(); |
||
| 3132 | |||
| 3133 | $feedback_type = $this->selectFeedbackType(); |
||
| 3134 | $results_disabled = $this->selectResultsDisabled(); |
||
| 3135 | |||
| 3136 | if ($debug) { |
||
| 3137 | error_log("<------ manage_answer ------> "); |
||
| 3138 | error_log('exe_id: '.$exeId); |
||
| 3139 | error_log('$from: '.$from); |
||
| 3140 | error_log('$saved_results: '.intval($saved_results)); |
||
| 3141 | error_log('$from_database: '.intval($from_database)); |
||
| 3142 | error_log('$show_result: '.$show_result); |
||
| 3143 | error_log('$propagate_neg: '.$propagate_neg); |
||
| 3144 | error_log('$exerciseResultCoordinates: '.print_r($exerciseResultCoordinates, 1)); |
||
| 3145 | error_log('$hotspot_delineation_result: '.print_r($hotspot_delineation_result, 1)); |
||
| 3146 | error_log('$learnpath_id: '.$learnpath_id); |
||
| 3147 | error_log('$learnpath_item_id: '.$learnpath_item_id); |
||
| 3148 | error_log('$choice: '.print_r($choice, 1)); |
||
| 3149 | } |
||
| 3150 | |||
| 3151 | $extra_data = array(); |
||
| 3152 | $final_overlap = 0; |
||
| 3153 | $final_missing = 0; |
||
| 3154 | $final_excess = 0; |
||
| 3155 | $overlap_color = 0; |
||
| 3156 | $missing_color = 0; |
||
| 3157 | $excess_color = 0; |
||
| 3158 | $threadhold1 = 0; |
||
| 3159 | $threadhold2 = 0; |
||
| 3160 | $threadhold3 = 0; |
||
| 3161 | |||
| 3162 | $arrques = null; |
||
| 3163 | $arrans = null; |
||
| 3164 | |||
| 3165 | $questionId = intval($questionId); |
||
| 3166 | $exeId = intval($exeId); |
||
| 3167 | $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); |
||
| 3168 | $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER); |
||
| 3169 | |||
| 3170 | // Creates a temporary Question object |
||
| 3171 | $course_id = $this->course_id; |
||
| 3172 | $objQuestionTmp = Question::read($questionId, $course_id); |
||
| 3173 | |||
| 3174 | if ($objQuestionTmp === false) { |
||
| 3175 | return false; |
||
| 3176 | } |
||
| 3177 | |||
| 3178 | $questionName = $objQuestionTmp->selectTitle(); |
||
| 3179 | $questionWeighting = $objQuestionTmp->selectWeighting(); |
||
| 3180 | $answerType = $objQuestionTmp->selectType(); |
||
| 3181 | $quesId = $objQuestionTmp->selectId(); |
||
| 3182 | $extra = $objQuestionTmp->extra; |
||
| 3183 | |||
| 3184 | $next = 1; //not for now |
||
| 3185 | |||
| 3186 | // Extra information of the question |
||
| 3187 | if (!empty($extra)) { |
||
| 3188 | $extra = explode(':', $extra); |
||
| 3189 | if ($debug) { |
||
| 3190 | error_log(print_r($extra, 1)); |
||
| 3191 | } |
||
| 3192 | // Fixes problems with negatives values using intval |
||
| 3193 | $true_score = floatval(trim($extra[0])); |
||
| 3194 | $false_score = floatval(trim($extra[1])); |
||
| 3195 | $doubt_score = floatval(trim($extra[2])); |
||
| 3196 | } |
||
| 3197 | |||
| 3198 | $totalWeighting = 0; |
||
| 3199 | $totalScore = 0; |
||
| 3200 | |||
| 3201 | // Construction of the Answer object |
||
| 3202 | $objAnswerTmp = new Answer($questionId); |
||
| 3203 | $nbrAnswers = $objAnswerTmp->selectNbrAnswers(); |
||
| 3204 | |||
| 3205 | if ($debug) { |
||
| 3206 | error_log('Count of answers: '.$nbrAnswers); |
||
| 3207 | error_log('$answerType: '.$answerType); |
||
| 3208 | } |
||
| 3209 | |||
| 3210 | if ($answerType == FREE_ANSWER || |
||
| 3211 | $answerType == ORAL_EXPRESSION || |
||
| 3212 | $answerType == CALCULATED_ANSWER |
||
| 3213 | ) { |
||
| 3214 | $nbrAnswers = 1; |
||
| 3215 | } |
||
| 3216 | |||
| 3217 | if ($answerType == ORAL_EXPRESSION) { |
||
| 3218 | $exe_info = Event::get_exercise_results_by_attempt($exeId); |
||
| 3219 | $exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null; |
||
| 3220 | |||
| 3221 | $objQuestionTmp->initFile( |
||
| 3222 | api_get_session_id(), |
||
| 3223 | isset($exe_info['exe_user_id']) ? $exe_info['exe_user_id'] : api_get_user_id(), |
||
| 3224 | isset($exe_info['exe_exo_id']) ? $exe_info['exe_exo_id'] : $this->id, |
||
| 3225 | isset($exe_info['exe_id']) ? $exe_info['exe_id'] : $exeId |
||
| 3226 | ); |
||
| 3227 | |||
| 3228 | //probably this attempt came in an exercise all question by page |
||
| 3229 | if ($feedback_type == 0) { |
||
| 3230 | $objQuestionTmp->replaceWithRealExe($exeId); |
||
| 3231 | } |
||
| 3232 | } |
||
| 3233 | |||
| 3234 | $user_answer = ''; |
||
| 3235 | |||
| 3236 | // Get answer list for matching |
||
| 3237 | $sql = "SELECT id_auto, id, answer |
||
| 3238 | FROM $table_ans |
||
| 3239 | WHERE c_id = $course_id AND question_id = $questionId"; |
||
| 3240 | $res_answer = Database::query($sql); |
||
| 3241 | |||
| 3242 | $answerMatching = array(); |
||
| 3243 | while ($real_answer = Database::fetch_array($res_answer)) { |
||
| 3244 | $answerMatching[$real_answer['id_auto']] = $real_answer['answer']; |
||
| 3245 | } |
||
| 3246 | |||
| 3247 | $real_answers = array(); |
||
| 3248 | $quiz_question_options = Question::readQuestionOption( |
||
| 3249 | $questionId, |
||
| 3250 | $course_id |
||
| 3251 | ); |
||
| 3252 | |||
| 3253 | $organs_at_risk_hit = 0; |
||
| 3254 | $questionScore = 0; |
||
| 3255 | $answer_correct_array = array(); |
||
| 3256 | $orderedHotspots = []; |
||
| 3257 | |||
| 3258 | if ($answerType == HOT_SPOT) { |
||
| 3259 | $orderedHotspots = $em |
||
| 3260 | ->getRepository('ChamiloCoreBundle:TrackEHotspot') |
||
| 3261 | ->findBy([ |
||
| 3262 | 'hotspotQuestionId' => $questionId, |
||
| 3263 | 'cId' => $course_id, |
||
| 3264 | 'hotspotExeId' => $exeId |
||
| 3265 | ], |
||
| 3266 | ['hotspotId' => 'ASC'] |
||
| 3267 | ); |
||
| 3268 | } |
||
| 3269 | |||
| 3270 | if ($debug) error_log('Start answer loop '); |
||
| 3271 | |||
| 3272 | for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) { |
||
| 3273 | $answer = $objAnswerTmp->selectAnswer($answerId); |
||
| 3274 | $answerComment = $objAnswerTmp->selectComment($answerId); |
||
| 3275 | $answerCorrect = $objAnswerTmp->isCorrect($answerId); |
||
| 3276 | $answerWeighting = (float)$objAnswerTmp->selectWeighting($answerId); |
||
| 3277 | $answerAutoId = $objAnswerTmp->selectAutoId($answerId); |
||
| 3278 | $answerIid = isset($objAnswerTmp->iid[$answerId]) ? $objAnswerTmp->iid[$answerId] : ''; |
||
| 3279 | |||
| 3280 | $answer_correct_array[$answerId] = (bool)$answerCorrect; |
||
| 3281 | |||
| 3282 | if ($debug) { |
||
| 3283 | error_log("answer auto id: $answerAutoId "); |
||
| 3284 | error_log("answer correct: $answerCorrect "); |
||
| 3285 | } |
||
| 3286 | |||
| 3287 | // Delineation |
||
| 3288 | $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1); |
||
| 3289 | $answer_delineation_destination=$objAnswerTmp->selectDestination(1); |
||
| 3290 | |||
| 3291 | switch ($answerType) { |
||
| 3292 | // for unique answer |
||
| 3293 | case UNIQUE_ANSWER: |
||
| 3294 | case UNIQUE_ANSWER_IMAGE: |
||
| 3295 | case UNIQUE_ANSWER_NO_OPTION: |
||
| 3296 | if ($from_database) { |
||
| 3297 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3298 | WHERE |
||
| 3299 | exe_id = '".$exeId."' AND |
||
| 3300 | question_id= '".$questionId."'"; |
||
| 3301 | $result = Database::query($sql); |
||
| 3302 | $choice = Database::result($result,0,"answer"); |
||
| 3303 | |||
| 3304 | $studentChoice = $choice == $answerAutoId ? 1 : 0; |
||
| 3305 | if ($studentChoice) { |
||
| 3306 | $questionScore += $answerWeighting; |
||
| 3307 | $totalScore += $answerWeighting; |
||
| 3308 | } |
||
| 3309 | } else { |
||
| 3310 | $studentChoice = $choice == $answerAutoId ? 1 : 0; |
||
| 3311 | if ($studentChoice) { |
||
| 3312 | $questionScore += $answerWeighting; |
||
| 3313 | $totalScore += $answerWeighting; |
||
| 3314 | } |
||
| 3315 | } |
||
| 3316 | break; |
||
| 3317 | // for multiple answers |
||
| 3318 | case MULTIPLE_ANSWER_TRUE_FALSE: |
||
| 3319 | if ($from_database) { |
||
| 3320 | $choice = array(); |
||
| 3321 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3322 | WHERE |
||
| 3323 | exe_id = $exeId AND |
||
| 3324 | question_id = ".$questionId; |
||
| 3325 | |||
| 3326 | $result = Database::query($sql); |
||
| 3327 | View Code Duplication | while ($row = Database::fetch_array($result)) { |
|
| 3328 | $ind = $row['answer']; |
||
| 3329 | $values = explode(':', $ind); |
||
| 3330 | $my_answer_id = isset($values[0]) ? $values[0] : ''; |
||
| 3331 | $option = isset($values[1]) ? $values[1] : ''; |
||
| 3332 | $choice[$my_answer_id] = $option; |
||
| 3333 | } |
||
| 3334 | } |
||
| 3335 | |||
| 3336 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3337 | |||
| 3338 | if (!empty($studentChoice)) { |
||
| 3339 | if ($studentChoice == $answerCorrect) { |
||
| 3340 | $questionScore += $true_score; |
||
| 3341 | } else { |
||
| 3342 | if ($quiz_question_options[$studentChoice]['name'] == "Don't know" || |
||
| 3343 | $quiz_question_options[$studentChoice]['name'] == "DoubtScore" |
||
| 3344 | ) { |
||
| 3345 | $questionScore += $doubt_score; |
||
| 3346 | } else { |
||
| 3347 | $questionScore += $false_score; |
||
| 3348 | } |
||
| 3349 | } |
||
| 3350 | } else { |
||
| 3351 | // If no result then the user just hit don't know |
||
| 3352 | $studentChoice = 3; |
||
| 3353 | $questionScore += $doubt_score; |
||
| 3354 | } |
||
| 3355 | $totalScore = $questionScore; |
||
| 3356 | break; |
||
| 3357 | View Code Duplication | case MULTIPLE_ANSWER: //2 |
|
| 3358 | if ($from_database) { |
||
| 3359 | $choice = array(); |
||
| 3360 | $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3361 | WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; |
||
| 3362 | $resultans = Database::query($sql); |
||
| 3363 | while ($row = Database::fetch_array($resultans)) { |
||
| 3364 | $ind = $row['answer']; |
||
| 3365 | $choice[$ind] = 1; |
||
| 3366 | } |
||
| 3367 | |||
| 3368 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3369 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3370 | |||
| 3371 | if ($studentChoice) { |
||
| 3372 | $questionScore +=$answerWeighting; |
||
| 3373 | } |
||
| 3374 | } else { |
||
| 3375 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3376 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3377 | |||
| 3378 | if (isset($studentChoice)) { |
||
| 3379 | $questionScore += $answerWeighting; |
||
| 3380 | } |
||
| 3381 | } |
||
| 3382 | $totalScore += $answerWeighting; |
||
| 3383 | |||
| 3384 | if ($debug) error_log("studentChoice: $studentChoice"); |
||
| 3385 | break; |
||
| 3386 | View Code Duplication | case GLOBAL_MULTIPLE_ANSWER: |
|
| 3387 | if ($from_database) { |
||
| 3388 | $choice = array(); |
||
| 3389 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3390 | WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; |
||
| 3391 | $resultans = Database::query($sql); |
||
| 3392 | while ($row = Database::fetch_array($resultans)) { |
||
| 3393 | $ind = $row['answer']; |
||
| 3394 | $choice[$ind] = 1; |
||
| 3395 | } |
||
| 3396 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3397 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3398 | if ($studentChoice) { |
||
| 3399 | $questionScore +=$answerWeighting; |
||
| 3400 | } |
||
| 3401 | } else { |
||
| 3402 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3403 | if (isset($studentChoice)) { |
||
| 3404 | $questionScore += $answerWeighting; |
||
| 3405 | } |
||
| 3406 | $real_answers[$answerId] = (bool)$studentChoice; |
||
| 3407 | } |
||
| 3408 | $totalScore += $answerWeighting; |
||
| 3409 | if ($debug) error_log("studentChoice: $studentChoice"); |
||
| 3410 | break; |
||
| 3411 | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
||
| 3412 | if ($from_database) { |
||
| 3413 | $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3414 | WHERE exe_id = $exeId AND question_id= ".$questionId; |
||
| 3415 | $resultans = Database::query($sql); |
||
| 3416 | View Code Duplication | while ($row = Database::fetch_array($resultans)) { |
|
| 3417 | $ind = $row['answer']; |
||
| 3418 | $result = explode(':',$ind); |
||
| 3419 | if (isset($result[0])) { |
||
| 3420 | $my_answer_id = isset($result[0]) ? $result[0] : ''; |
||
| 3421 | $option = isset($result[1]) ? $result[1] : ''; |
||
| 3422 | $choice[$my_answer_id] = $option; |
||
| 3423 | } |
||
| 3424 | } |
||
| 3425 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : ''; |
||
| 3426 | |||
| 3427 | if ($answerCorrect == $studentChoice) { |
||
| 3428 | //$answerCorrect = 1; |
||
| 3429 | $real_answers[$answerId] = true; |
||
| 3430 | } else { |
||
| 3431 | //$answerCorrect = 0; |
||
| 3432 | $real_answers[$answerId] = false; |
||
| 3433 | } |
||
| 3434 | } else { |
||
| 3435 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : ''; |
||
| 3436 | if ($answerCorrect == $studentChoice) { |
||
| 3437 | //$answerCorrect = 1; |
||
| 3438 | $real_answers[$answerId] = true; |
||
| 3439 | } else { |
||
| 3440 | //$answerCorrect = 0; |
||
| 3441 | $real_answers[$answerId] = false; |
||
| 3442 | } |
||
| 3443 | } |
||
| 3444 | break; |
||
| 3445 | case MULTIPLE_ANSWER_COMBINATION: |
||
| 3446 | if ($from_database) { |
||
| 3447 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3448 | WHERE exe_id = $exeId AND question_id= $questionId"; |
||
| 3449 | $resultans = Database::query($sql); |
||
| 3450 | while ($row = Database::fetch_array($resultans)) { |
||
| 3451 | $ind = $row['answer']; |
||
| 3452 | $choice[$ind] = 1; |
||
| 3453 | } |
||
| 3454 | |||
| 3455 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3456 | |||
| 3457 | View Code Duplication | if ($answerCorrect == 1) { |
|
| 3458 | if ($studentChoice) { |
||
| 3459 | $real_answers[$answerId] = true; |
||
| 3460 | } else { |
||
| 3461 | $real_answers[$answerId] = false; |
||
| 3462 | } |
||
| 3463 | } else { |
||
| 3464 | if ($studentChoice) { |
||
| 3465 | $real_answers[$answerId] = false; |
||
| 3466 | } else { |
||
| 3467 | $real_answers[$answerId] = true; |
||
| 3468 | } |
||
| 3469 | } |
||
| 3470 | } else { |
||
| 3471 | $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null; |
||
| 3472 | |||
| 3473 | View Code Duplication | if ($answerCorrect == 1) { |
|
| 3474 | if ($studentChoice) { |
||
| 3475 | $real_answers[$answerId] = true; |
||
| 3476 | } else { |
||
| 3477 | $real_answers[$answerId] = false; |
||
| 3478 | } |
||
| 3479 | } else { |
||
| 3480 | if ($studentChoice) { |
||
| 3481 | $real_answers[$answerId] = false; |
||
| 3482 | } else { |
||
| 3483 | $real_answers[$answerId] = true; |
||
| 3484 | } |
||
| 3485 | } |
||
| 3486 | } |
||
| 3487 | break; |
||
| 3488 | case FILL_IN_BLANKS: |
||
| 3489 | $str = ''; |
||
| 3490 | if ($from_database) { |
||
| 3491 | $sql = "SELECT answer |
||
| 3492 | FROM $TBL_TRACK_ATTEMPT |
||
| 3493 | WHERE |
||
| 3494 | exe_id = $exeId AND |
||
| 3495 | question_id= ".intval($questionId); |
||
| 3496 | $result = Database::query($sql); |
||
| 3497 | $str = Database::result($result, 0, 'answer'); |
||
| 3498 | } |
||
| 3499 | |||
| 3500 | if ($saved_results == false && strpos($str, 'font color') !== false) { |
||
| 3501 | // the question is encoded like this |
||
| 3502 | // [A] B [C] D [E] F::10,10,10@1 |
||
| 3503 | // number 1 before the "@" means that is a switchable fill in blank question |
||
| 3504 | // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10 |
||
| 3505 | // means that is a normal fill blank question |
||
| 3506 | // first we explode the "::" |
||
| 3507 | $pre_array = explode('::', $answer); |
||
| 3508 | |||
| 3509 | // is switchable fill blank or not |
||
| 3510 | $last = count($pre_array) - 1; |
||
| 3511 | $is_set_switchable = explode('@', $pre_array[$last]); |
||
| 3512 | $switchable_answer_set = false; |
||
| 3513 | if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) { |
||
| 3514 | $switchable_answer_set = true; |
||
| 3515 | } |
||
| 3516 | $answer = ''; |
||
| 3517 | for ($k = 0; $k < $last; $k++) { |
||
| 3518 | $answer .= $pre_array[$k]; |
||
| 3519 | } |
||
| 3520 | // splits weightings that are joined with a comma |
||
| 3521 | $answerWeighting = explode(',', $is_set_switchable[0]); |
||
| 3522 | // we save the answer because it will be modified |
||
| 3523 | $temp = $answer; |
||
| 3524 | $answer = ''; |
||
| 3525 | $j = 0; |
||
| 3526 | //initialise answer tags |
||
| 3527 | $user_tags = $correct_tags = $real_text = array(); |
||
| 3528 | // the loop will stop at the end of the text |
||
| 3529 | while (1) { |
||
| 3530 | // quits the loop if there are no more blanks (detect '[') |
||
| 3531 | if ($temp == false || ($pos = api_strpos($temp, '[')) === false) { |
||
| 3532 | // adds the end of the text |
||
| 3533 | $answer = $temp; |
||
| 3534 | $real_text[] = $answer; |
||
| 3535 | break; //no more "blanks", quit the loop |
||
| 3536 | } |
||
| 3537 | // adds the piece of text that is before the blank |
||
| 3538 | //and ends with '[' into a general storage array |
||
| 3539 | $real_text[] = api_substr($temp, 0, $pos +1); |
||
| 3540 | $answer .= api_substr($temp, 0, $pos +1); |
||
| 3541 | //take the string remaining (after the last "[" we found) |
||
| 3542 | $temp = api_substr($temp, $pos +1); |
||
| 3543 | // quit the loop if there are no more blanks, and update $pos to the position of next ']' |
||
| 3544 | if (($pos = api_strpos($temp, ']')) === false) { |
||
| 3545 | // adds the end of the text |
||
| 3546 | $answer .= $temp; |
||
| 3547 | break; |
||
| 3548 | } |
||
| 3549 | if ($from_database) { |
||
| 3550 | $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3551 | WHERE |
||
| 3552 | exe_id = '".$exeId."' AND |
||
| 3553 | question_id= ".intval($questionId).""; |
||
| 3554 | $resfill = Database::query($queryfill); |
||
| 3555 | $str = Database::result($resfill, 0, 'answer'); |
||
| 3556 | api_preg_match_all('#\[([^[]*)\]#', $str, $arr); |
||
| 3557 | $str = str_replace('\r\n', '', $str); |
||
| 3558 | |||
| 3559 | $choice = $arr[1]; |
||
| 3560 | if (isset($choice[$j])) { |
||
| 3561 | $tmp = api_strrpos($choice[$j], ' / '); |
||
| 3562 | $choice[$j] = api_substr($choice[$j], 0, $tmp); |
||
| 3563 | $choice[$j] = trim($choice[$j]); |
||
| 3564 | // Needed to let characters ' and " to work as part of an answer |
||
| 3565 | $choice[$j] = stripslashes($choice[$j]); |
||
| 3566 | } else { |
||
| 3567 | $choice[$j] = null; |
||
| 3568 | } |
||
| 3569 | } else { |
||
| 3570 | // This value is the user input, not escaped while correct answer is escaped by fckeditor |
||
| 3571 | $choice[$j] = api_htmlentities(trim($choice[$j])); |
||
| 3572 | } |
||
| 3573 | |||
| 3574 | $user_tags[] = $choice[$j]; |
||
| 3575 | //put the contents of the [] answer tag into correct_tags[] |
||
| 3576 | $correct_tags[] = api_substr($temp, 0, $pos); |
||
| 3577 | $j++; |
||
| 3578 | $temp = api_substr($temp, $pos +1); |
||
| 3579 | } |
||
| 3580 | $answer = ''; |
||
| 3581 | $real_correct_tags = $correct_tags; |
||
| 3582 | $chosen_list = array(); |
||
| 3583 | |||
| 3584 | for ($i = 0; $i < count($real_correct_tags); $i++) { |
||
| 3585 | if ($i == 0) { |
||
| 3586 | $answer .= $real_text[0]; |
||
| 3587 | } |
||
| 3588 | if (!$switchable_answer_set) { |
||
| 3589 | // Needed to parse ' and " characters |
||
| 3590 | $user_tags[$i] = stripslashes($user_tags[$i]); |
||
| 3591 | View Code Duplication | if ($correct_tags[$i] == $user_tags[$i]) { |
|
| 3592 | // gives the related weighting to the student |
||
| 3593 | $questionScore += $answerWeighting[$i]; |
||
| 3594 | // increments total score |
||
| 3595 | $totalScore += $answerWeighting[$i]; |
||
| 3596 | // adds the word in green at the end of the string |
||
| 3597 | $answer .= $correct_tags[$i]; |
||
| 3598 | } elseif (!empty($user_tags[$i])) { |
||
| 3599 | // else if the word entered by the student IS NOT the same as the one defined by the professor |
||
| 3600 | // adds the word in red at the end of the string, and strikes it |
||
| 3601 | $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>'; |
||
| 3602 | } else { |
||
| 3603 | // adds a tabulation if no word has been typed by the student |
||
| 3604 | $answer .= ''; // remove that causes issue |
||
| 3605 | } |
||
| 3606 | } else { |
||
| 3607 | // switchable fill in the blanks |
||
| 3608 | if (in_array($user_tags[$i], $correct_tags)) { |
||
| 3609 | $chosen_list[] = $user_tags[$i]; |
||
| 3610 | $correct_tags = array_diff($correct_tags, $chosen_list); |
||
| 3611 | // gives the related weighting to the student |
||
| 3612 | $questionScore += $answerWeighting[$i]; |
||
| 3613 | // increments total score |
||
| 3614 | $totalScore += $answerWeighting[$i]; |
||
| 3615 | // adds the word in green at the end of the string |
||
| 3616 | $answer .= $user_tags[$i]; |
||
| 3617 | } elseif (!empty ($user_tags[$i])) { |
||
| 3618 | // else if the word entered by the student IS NOT the same as the one defined by the professor |
||
| 3619 | // adds the word in red at the end of the string, and strikes it |
||
| 3620 | $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>'; |
||
| 3621 | } else { |
||
| 3622 | // adds a tabulation if no word has been typed by the student |
||
| 3623 | $answer .= ''; // remove that causes issue |
||
| 3624 | } |
||
| 3625 | } |
||
| 3626 | |||
| 3627 | // adds the correct word, followed by ] to close the blank |
||
| 3628 | $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]'; |
||
| 3629 | if (isset($real_text[$i +1])) { |
||
| 3630 | $answer .= $real_text[$i +1]; |
||
| 3631 | } |
||
| 3632 | } |
||
| 3633 | } else { |
||
| 3634 | // insert the student result in the track_e_attempt table, field answer |
||
| 3635 | // $answer is the answer like in the c_quiz_answer table for the question |
||
| 3636 | // student data are choice[] |
||
| 3637 | $listCorrectAnswers = FillBlanks::getAnswerInfo( |
||
| 3638 | $answer |
||
| 3639 | ); |
||
| 3640 | |||
| 3641 | $switchableAnswerSet = $listCorrectAnswers['switchable']; |
||
| 3642 | $answerWeighting = $listCorrectAnswers['tabweighting']; |
||
| 3643 | // user choices is an array $choice |
||
| 3644 | |||
| 3645 | // get existing user data in n the BDD |
||
| 3646 | if ($from_database) { |
||
| 3647 | $sql = "SELECT answer |
||
| 3648 | FROM $TBL_TRACK_ATTEMPT |
||
| 3649 | WHERE |
||
| 3650 | exe_id = $exeId AND |
||
| 3651 | question_id= ".intval($questionId); |
||
| 3652 | $result = Database::query($sql); |
||
| 3653 | $str = Database::result($result, 0, 'answer'); |
||
| 3654 | $listStudentResults = FillBlanks::getAnswerInfo( |
||
| 3655 | $str, |
||
| 3656 | true |
||
| 3657 | ); |
||
| 3658 | $choice = $listStudentResults['studentanswer']; |
||
| 3659 | } |
||
| 3660 | |||
| 3661 | // loop other all blanks words |
||
| 3662 | if (!$switchableAnswerSet) { |
||
| 3663 | // not switchable answer, must be in the same place than teacher order |
||
| 3664 | for ($i = 0; $i < count($listCorrectAnswers['tabwords']); $i++) { |
||
| 3665 | $studentAnswer = isset($choice[$i]) ? trim($choice[$i]) : ''; |
||
| 3666 | $correctAnswer = $listCorrectAnswers['tabwords'][$i]; |
||
| 3667 | |||
| 3668 | // This value is the user input, not escaped while correct answer is escaped by fckeditor |
||
| 3669 | // Works with cyrillic alphabet and when using ">" chars see #7718 #7610 #7618 |
||
| 3670 | if (!$from_database) { |
||
| 3671 | $studentAnswer = htmlentities( |
||
| 3672 | api_utf8_encode($studentAnswer) |
||
| 3673 | ); |
||
| 3674 | } |
||
| 3675 | |||
| 3676 | $isAnswerCorrect = 0; |
||
| 3677 | View Code Duplication | if (FillBlanks::isGoodStudentAnswer($studentAnswer, $correctAnswer)) { |
|
| 3678 | // gives the related weighting to the student |
||
| 3679 | $questionScore += $answerWeighting[$i]; |
||
| 3680 | // increments total score |
||
| 3681 | $totalScore += $answerWeighting[$i]; |
||
| 3682 | $isAnswerCorrect = 1; |
||
| 3683 | } |
||
| 3684 | $listCorrectAnswers['studentanswer'][$i] = $studentAnswer; |
||
| 3685 | $listCorrectAnswers['studentscore'][$i] = $isAnswerCorrect; |
||
| 3686 | } |
||
| 3687 | } else { |
||
| 3688 | // switchable answer |
||
| 3689 | $listStudentAnswerTemp = $choice; |
||
| 3690 | $listTeacherAnswerTemp = $listCorrectAnswers['tabwords']; |
||
| 3691 | // for every teacher answer, check if there is a student answer |
||
| 3692 | for ($i = 0; $i < count($listStudentAnswerTemp); $i++) { |
||
| 3693 | $studentAnswer = trim( |
||
| 3694 | $listStudentAnswerTemp[$i] |
||
| 3695 | ); |
||
| 3696 | $found = false; |
||
| 3697 | for ($j = 0; $j < count($listTeacherAnswerTemp); $j++) { |
||
| 3698 | $correctAnswer = $listTeacherAnswerTemp[$j]; |
||
| 3699 | if (!$found) { |
||
| 3700 | View Code Duplication | if (FillBlanks::isGoodStudentAnswer( |
|
| 3701 | $studentAnswer, |
||
| 3702 | $correctAnswer |
||
| 3703 | ) |
||
| 3704 | ) { |
||
| 3705 | $questionScore += $answerWeighting[$i]; |
||
| 3706 | $totalScore += $answerWeighting[$i]; |
||
| 3707 | $listTeacherAnswerTemp[$j] = ""; |
||
| 3708 | $found = true; |
||
| 3709 | } |
||
| 3710 | } |
||
| 3711 | } |
||
| 3712 | $listCorrectAnswers['studentanswer'][$i] = $studentAnswer; |
||
| 3713 | if (!$found) { |
||
| 3714 | $listCorrectAnswers['studentscore'][$i] = 0; |
||
| 3715 | } else { |
||
| 3716 | $listCorrectAnswers['studentscore'][$i] = 1; |
||
| 3717 | } |
||
| 3718 | } |
||
| 3719 | } |
||
| 3720 | $answer = FillBlanks::getAnswerInStudentAttempt( |
||
| 3721 | $listCorrectAnswers |
||
| 3722 | ); |
||
| 3723 | } |
||
| 3724 | break; |
||
| 3725 | case CALCULATED_ANSWER: |
||
| 3726 | $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]); |
||
| 3727 | $preArray = explode('@@', $answer); |
||
| 3728 | $last = count($preArray) - 1; |
||
| 3729 | $answer = ''; |
||
| 3730 | for ($k = 0; $k < $last; $k++) { |
||
| 3731 | $answer .= $preArray[$k]; |
||
| 3732 | } |
||
| 3733 | $answerWeighting = array($answerWeighting); |
||
| 3734 | // we save the answer because it will be modified |
||
| 3735 | $temp = $answer; |
||
| 3736 | $answer = ''; |
||
| 3737 | $j = 0; |
||
| 3738 | //initialise answer tags |
||
| 3739 | $userTags = $correctTags = $realText = array(); |
||
| 3740 | // the loop will stop at the end of the text |
||
| 3741 | while (1) { |
||
| 3742 | // quits the loop if there are no more blanks (detect '[') |
||
| 3743 | if ($temp == false || ($pos = api_strpos($temp, '[')) === false) { |
||
| 3744 | // adds the end of the text |
||
| 3745 | $answer = $temp; |
||
| 3746 | $realText[] = $answer; |
||
| 3747 | break; //no more "blanks", quit the loop |
||
| 3748 | } |
||
| 3749 | // adds the piece of text that is before the blank |
||
| 3750 | //and ends with '[' into a general storage array |
||
| 3751 | $realText[] = api_substr($temp, 0, $pos +1); |
||
| 3752 | $answer .= api_substr($temp, 0, $pos +1); |
||
| 3753 | //take the string remaining (after the last "[" we found) |
||
| 3754 | $temp = api_substr($temp, $pos +1); |
||
| 3755 | // quit the loop if there are no more blanks, and update $pos to the position of next ']' |
||
| 3756 | if (($pos = api_strpos($temp, ']')) === false) { |
||
| 3757 | // adds the end of the text |
||
| 3758 | $answer .= $temp; |
||
| 3759 | break; |
||
| 3760 | } |
||
| 3761 | if ($from_database) { |
||
| 3762 | $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3763 | WHERE |
||
| 3764 | exe_id = '".$exeId."' AND |
||
| 3765 | question_id= ".intval($questionId); |
||
| 3766 | $resfill = Database::query($queryfill); |
||
| 3767 | $str = Database::result($resfill, 0, 'answer'); |
||
| 3768 | api_preg_match_all('#\[([^[]*)\]#', $str, $arr); |
||
| 3769 | $str = str_replace('\r\n', '', $str); |
||
| 3770 | $choice = $arr[1]; |
||
| 3771 | if (isset($choice[$j])) { |
||
| 3772 | $tmp = api_strrpos($choice[$j], ' / '); |
||
| 3773 | |||
| 3774 | if ($tmp) { |
||
| 3775 | $choice[$j] = api_substr($choice[$j], 0, $tmp); |
||
| 3776 | } else { |
||
| 3777 | $tmp = ltrim($tmp, '['); |
||
| 3778 | $tmp = rtrim($tmp, ']'); |
||
| 3779 | } |
||
| 3780 | |||
| 3781 | $choice[$j] = trim($choice[$j]); |
||
| 3782 | // Needed to let characters ' and " to work as part of an answer |
||
| 3783 | $choice[$j] = stripslashes($choice[$j]); |
||
| 3784 | } else { |
||
| 3785 | $choice[$j] = null; |
||
| 3786 | } |
||
| 3787 | } else { |
||
| 3788 | // This value is the user input, not escaped while correct answer is escaped by fckeditor |
||
| 3789 | $choice[$j] = api_htmlentities(trim($choice[$j])); |
||
| 3790 | } |
||
| 3791 | $userTags[] = $choice[$j]; |
||
| 3792 | //put the contents of the [] answer tag into correct_tags[] |
||
| 3793 | $correctTags[] = api_substr($temp, 0, $pos); |
||
| 3794 | $j++; |
||
| 3795 | $temp = api_substr($temp, $pos +1); |
||
| 3796 | } |
||
| 3797 | $answer = ''; |
||
| 3798 | $realCorrectTags = $correctTags; |
||
| 3799 | for ($i = 0; $i < count($realCorrectTags); $i++) { |
||
| 3800 | if ($i == 0) { |
||
| 3801 | $answer .= $realText[0]; |
||
| 3802 | } |
||
| 3803 | // Needed to parse ' and " characters |
||
| 3804 | $userTags[$i] = stripslashes($userTags[$i]); |
||
| 3805 | View Code Duplication | if ($correctTags[$i] == $userTags[$i]) { |
|
| 3806 | // gives the related weighting to the student |
||
| 3807 | $questionScore += $answerWeighting[$i]; |
||
| 3808 | // increments total score |
||
| 3809 | $totalScore += $answerWeighting[$i]; |
||
| 3810 | // adds the word in green at the end of the string |
||
| 3811 | $answer .= $correctTags[$i]; |
||
| 3812 | } elseif (!empty($userTags[$i])) { |
||
| 3813 | // else if the word entered by the student IS NOT the same as the one defined by the professor |
||
| 3814 | // adds the word in red at the end of the string, and strikes it |
||
| 3815 | $answer .= '<font color="red"><s>' . $userTags[$i] . '</s></font>'; |
||
| 3816 | } else { |
||
| 3817 | // adds a tabulation if no word has been typed by the student |
||
| 3818 | $answer .= ''; // remove that causes issue |
||
| 3819 | } |
||
| 3820 | // adds the correct word, followed by ] to close the blank |
||
| 3821 | |||
| 3822 | if ( |
||
| 3823 | $this->results_disabled != EXERCISE_FEEDBACK_TYPE_EXAM |
||
| 3824 | ) { |
||
| 3825 | $answer .= ' / <font color="green"><b>' . $realCorrectTags[$i] . '</b></font>'; |
||
| 3826 | } |
||
| 3827 | |||
| 3828 | $answer .= ']'; |
||
| 3829 | |||
| 3830 | if (isset($realText[$i +1])) { |
||
| 3831 | $answer .= $realText[$i +1]; |
||
| 3832 | } |
||
| 3833 | } |
||
| 3834 | break; |
||
| 3835 | case FREE_ANSWER: |
||
| 3836 | if ($from_database) { |
||
| 3837 | $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT." |
||
| 3838 | WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'"; |
||
| 3839 | $resq = Database::query($query); |
||
| 3840 | $data = Database::fetch_array($resq); |
||
| 3841 | |||
| 3842 | $choice = $data['answer']; |
||
| 3843 | $choice = str_replace('\r\n', '', $choice); |
||
| 3844 | $choice = stripslashes($choice); |
||
| 3845 | $questionScore = $data['marks']; |
||
| 3846 | |||
| 3847 | if ($questionScore == -1) { |
||
| 3848 | $totalScore+= 0; |
||
| 3849 | } else { |
||
| 3850 | $totalScore+= $questionScore; |
||
| 3851 | } |
||
| 3852 | if ($questionScore == '') { |
||
| 3853 | $questionScore = 0; |
||
| 3854 | } |
||
| 3855 | $arrques = $questionName; |
||
| 3856 | $arrans = $choice; |
||
| 3857 | } else { |
||
| 3858 | $studentChoice = $choice; |
||
| 3859 | if ($studentChoice) { |
||
| 3860 | //Fixing negative puntation see #2193 |
||
| 3861 | $questionScore = 0; |
||
| 3862 | $totalScore += 0; |
||
| 3863 | } |
||
| 3864 | } |
||
| 3865 | break; |
||
| 3866 | case ORAL_EXPRESSION: |
||
| 3867 | if ($from_database) { |
||
| 3868 | $query = "SELECT answer, marks |
||
| 3869 | FROM $TBL_TRACK_ATTEMPT |
||
| 3870 | WHERE |
||
| 3871 | exe_id = $exeId AND |
||
| 3872 | question_id = $questionId |
||
| 3873 | "; |
||
| 3874 | $resq = Database::query($query); |
||
| 3875 | $row = Database::fetch_assoc($resq); |
||
| 3876 | $choice = $row['answer']; |
||
| 3877 | $choice = str_replace('\r\n', '', $choice); |
||
| 3878 | $choice = stripslashes($choice); |
||
| 3879 | $questionScore = $row['marks']; |
||
| 3880 | if ($questionScore == -1) { |
||
| 3881 | $totalScore += 0; |
||
| 3882 | } else { |
||
| 3883 | $totalScore += $questionScore; |
||
| 3884 | } |
||
| 3885 | $arrques = $questionName; |
||
| 3886 | $arrans = $choice; |
||
| 3887 | } else { |
||
| 3888 | $studentChoice = $choice; |
||
| 3889 | if ($studentChoice) { |
||
| 3890 | //Fixing negative puntation see #2193 |
||
| 3891 | $questionScore = 0; |
||
| 3892 | $totalScore += 0; |
||
| 3893 | } |
||
| 3894 | } |
||
| 3895 | break; |
||
| 3896 | case DRAGGABLE: |
||
| 3897 | //no break |
||
| 3898 | case MATCHING_DRAGGABLE: |
||
| 3899 | //no break |
||
| 3900 | case MATCHING: |
||
| 3901 | if ($from_database) { |
||
| 3902 | $sql = "SELECT id, answer, id_auto |
||
| 3903 | FROM $table_ans |
||
| 3904 | WHERE |
||
| 3905 | c_id = $course_id AND |
||
| 3906 | question_id = $questionId AND |
||
| 3907 | correct = 0 |
||
| 3908 | "; |
||
| 3909 | $res_answer = Database::query($sql); |
||
| 3910 | // Getting the real answer |
||
| 3911 | $real_list = array(); |
||
| 3912 | while ($real_answer = Database::fetch_array($res_answer)) { |
||
| 3913 | $real_list[$real_answer['id_auto']] = $real_answer['answer']; |
||
| 3914 | } |
||
| 3915 | |||
| 3916 | $sql = "SELECT id, answer, correct, id_auto, ponderation |
||
| 3917 | FROM $table_ans |
||
| 3918 | WHERE |
||
| 3919 | c_id = $course_id AND |
||
| 3920 | question_id = $questionId AND |
||
| 3921 | correct <> 0 |
||
| 3922 | ORDER BY id_auto"; |
||
| 3923 | $res_answers = Database::query($sql); |
||
| 3924 | |||
| 3925 | $questionScore = 0; |
||
| 3926 | |||
| 3927 | while ($a_answers = Database::fetch_array($res_answers)) { |
||
| 3928 | $i_answer_id = $a_answers['id']; //3 |
||
| 3929 | $s_answer_label = $a_answers['answer']; // your daddy - your mother |
||
| 3930 | $i_answer_correct_answer = $a_answers['correct']; //1 - 2 |
||
| 3931 | $i_answer_id_auto = $a_answers['id_auto']; // 3 - 4 |
||
| 3932 | |||
| 3933 | $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT |
||
| 3934 | WHERE |
||
| 3935 | exe_id = '$exeId' AND |
||
| 3936 | question_id = '$questionId' AND |
||
| 3937 | position = '$i_answer_id_auto'"; |
||
| 3938 | |||
| 3939 | $res_user_answer = Database::query($sql); |
||
| 3940 | |||
| 3941 | if (Database::num_rows($res_user_answer) > 0) { |
||
| 3942 | // rich - good looking |
||
| 3943 | $s_user_answer = Database::result($res_user_answer, 0, 0); |
||
| 3944 | } else { |
||
| 3945 | $s_user_answer = 0; |
||
| 3946 | } |
||
| 3947 | |||
| 3948 | $i_answerWeighting = $a_answers['ponderation']; |
||
| 3949 | |||
| 3950 | $user_answer = ''; |
||
| 3951 | if (!empty($s_user_answer)) { |
||
| 3952 | if ($answerType == DRAGGABLE) { |
||
| 3953 | if ($s_user_answer == $i_answer_correct_answer) { |
||
| 3954 | $questionScore += $i_answerWeighting; |
||
| 3955 | $totalScore += $i_answerWeighting; |
||
| 3956 | $user_answer = Display::label(get_lang('Correct'), 'success'); |
||
| 3957 | } else { |
||
| 3958 | $user_answer = Display::label(get_lang('Incorrect'), 'danger'); |
||
| 3959 | } |
||
| 3960 | } else { |
||
| 3961 | if ($s_user_answer == $i_answer_correct_answer) { |
||
| 3962 | $questionScore += $i_answerWeighting; |
||
| 3963 | $totalScore += $i_answerWeighting; |
||
| 3964 | |||
| 3965 | // Try with id |
||
| 3966 | if (isset($real_list[$i_answer_id])) { |
||
| 3967 | $user_answer = Display::span($real_list[$i_answer_id]); |
||
| 3968 | } |
||
| 3969 | |||
| 3970 | // Try with $i_answer_id_auto |
||
| 3971 | if (empty($user_answer)) { |
||
| 3972 | if (isset($real_list[$i_answer_id_auto])) { |
||
| 3973 | $user_answer = Display::span( |
||
| 3974 | $real_list[$i_answer_id_auto] |
||
| 3975 | ); |
||
| 3976 | } |
||
| 3977 | } |
||
| 3978 | } else { |
||
| 3979 | $user_answer = Display::span( |
||
| 3980 | $real_list[$s_user_answer], |
||
| 3981 | ['style' => 'color: #FF0000; text-decoration: line-through;'] |
||
| 3982 | ); |
||
| 3983 | } |
||
| 3984 | } |
||
| 3985 | } elseif ($answerType == DRAGGABLE) { |
||
| 3986 | $user_answer = Display::label(get_lang('Incorrect'), 'danger'); |
||
| 3987 | } else { |
||
| 3988 | $user_answer = Display::span( |
||
| 3989 | get_lang('Incorrect').' ', |
||
| 3990 | ['style' => 'color: #FF0000; text-decoration: line-through;'] |
||
| 3991 | ); |
||
| 3992 | } |
||
| 3993 | |||
| 3994 | if ($show_result) { |
||
| 3995 | if ($showTotalScoreAndUserChoicesInLastAttempt === false) { |
||
| 3996 | $user_answer = ''; |
||
| 3997 | } |
||
| 3998 | echo '<tr>'; |
||
| 3999 | echo '<td>' . $s_answer_label . '</td>'; |
||
| 4000 | echo '<td>' . $user_answer; |
||
| 4001 | |||
| 4002 | if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
||
| 4003 | if (isset($real_list[$i_answer_correct_answer]) && |
||
| 4004 | $showTotalScoreAndUserChoicesInLastAttempt === true |
||
| 4005 | ) { |
||
| 4006 | echo Display::span( |
||
| 4007 | $real_list[$i_answer_correct_answer], |
||
| 4008 | ['style' => 'color: #008000; font-weight: bold;'] |
||
| 4009 | ); |
||
| 4010 | } |
||
| 4011 | } |
||
| 4012 | echo '</td>'; |
||
| 4013 | echo '</tr>'; |
||
| 4014 | } |
||
| 4015 | } |
||
| 4016 | break(2); // break the switch and the "for" condition |
||
| 4017 | } else { |
||
| 4018 | if ($answerCorrect) { |
||
| 4019 | if (isset($choice[$answerAutoId]) && |
||
| 4020 | $answerCorrect == $choice[$answerAutoId] |
||
| 4021 | ) { |
||
| 4022 | $questionScore += $answerWeighting; |
||
| 4023 | $totalScore += $answerWeighting; |
||
| 4024 | $user_answer = Display::span($answerMatching[$choice[$answerAutoId]]); |
||
| 4025 | } else { |
||
| 4026 | if (isset($answerMatching[$choice[$answerAutoId]])) { |
||
| 4027 | $user_answer = Display::span( |
||
| 4028 | $answerMatching[$choice[$answerAutoId]], |
||
| 4029 | ['style' => 'color: #FF0000; text-decoration: line-through;'] |
||
| 4030 | ); |
||
| 4031 | } |
||
| 4032 | } |
||
| 4033 | $matching[$answerAutoId] = $choice[$answerAutoId]; |
||
| 4034 | } |
||
| 4035 | break; |
||
| 4036 | } |
||
| 4037 | case HOT_SPOT: |
||
| 4038 | if ($from_database) { |
||
| 4039 | $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
||
| 4040 | // Check auto id |
||
| 4041 | $sql = "SELECT hotspot_correct |
||
| 4042 | FROM $TBL_TRACK_HOTSPOT |
||
| 4043 | WHERE |
||
| 4044 | hotspot_exe_id = $exeId AND |
||
| 4045 | hotspot_question_id= $questionId AND |
||
| 4046 | hotspot_answer_id = ".intval($answerAutoId); |
||
| 4047 | $result = Database::query($sql); |
||
| 4048 | if (Database::num_rows($result)) { |
||
| 4049 | $studentChoice = Database::result( |
||
| 4050 | $result, |
||
| 4051 | 0, |
||
| 4052 | 'hotspot_correct' |
||
| 4053 | ); |
||
| 4054 | |||
| 4055 | if ($studentChoice) { |
||
| 4056 | $questionScore += $answerWeighting; |
||
| 4057 | $totalScore += $answerWeighting; |
||
| 4058 | } |
||
| 4059 | } else { |
||
| 4060 | // If answer.id is different: |
||
| 4061 | $sql = "SELECT hotspot_correct |
||
| 4062 | FROM $TBL_TRACK_HOTSPOT |
||
| 4063 | WHERE |
||
| 4064 | hotspot_exe_id = $exeId AND |
||
| 4065 | hotspot_question_id= $questionId AND |
||
| 4066 | hotspot_answer_id = ".intval($answerId); |
||
| 4067 | $result = Database::query($sql); |
||
| 4068 | |||
| 4069 | if (Database::num_rows($result)) { |
||
| 4070 | $studentChoice = Database::result( |
||
| 4071 | $result, |
||
| 4072 | 0, |
||
| 4073 | 'hotspot_correct' |
||
| 4074 | ); |
||
| 4075 | |||
| 4076 | if ($studentChoice) { |
||
| 4077 | $questionScore += $answerWeighting; |
||
| 4078 | $totalScore += $answerWeighting; |
||
| 4079 | } |
||
| 4080 | } else { |
||
| 4081 | // check answer.iid |
||
| 4082 | if (!empty($answerIid)) { |
||
| 4083 | $sql = "SELECT hotspot_correct |
||
| 4084 | FROM $TBL_TRACK_HOTSPOT |
||
| 4085 | WHERE |
||
| 4086 | hotspot_exe_id = $exeId AND |
||
| 4087 | hotspot_question_id= $questionId AND |
||
| 4088 | hotspot_answer_id = ".intval($answerIid); |
||
| 4089 | $result = Database::query($sql); |
||
| 4090 | |||
| 4091 | $studentChoice = Database::result( |
||
| 4092 | $result, |
||
| 4093 | 0, |
||
| 4094 | 'hotspot_correct' |
||
| 4095 | ); |
||
| 4096 | |||
| 4097 | if ($studentChoice) { |
||
| 4098 | $questionScore += $answerWeighting; |
||
| 4099 | $totalScore += $answerWeighting; |
||
| 4100 | } |
||
| 4101 | } |
||
| 4102 | } |
||
| 4103 | } |
||
| 4104 | } else { |
||
| 4105 | if (!isset($choice[$answerAutoId]) && !isset($choice[$answerIid])) { |
||
| 4106 | $choice[$answerAutoId] = 0; |
||
| 4107 | $choice[$answerIid] = 0; |
||
| 4108 | } else { |
||
| 4109 | $studentChoice = $choice[$answerAutoId]; |
||
| 4110 | if (empty($studentChoice)) { |
||
| 4111 | $studentChoice = $choice[$answerIid]; |
||
| 4112 | } |
||
| 4113 | $choiceIsValid = false; |
||
| 4114 | if (!empty($studentChoice)) { |
||
| 4115 | $hotspotType = $objAnswerTmp->selectHotspotType($answerId); |
||
| 4116 | $hotspotCoordinates = $objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4117 | $choicePoint = Geometry::decodePoint($studentChoice); |
||
| 4118 | |||
| 4119 | switch ($hotspotType) { |
||
| 4120 | case 'square': |
||
| 4121 | $hotspotProperties = Geometry::decodeSquare($hotspotCoordinates); |
||
| 4122 | $choiceIsValid = Geometry::pointIsInSquare($hotspotProperties, $choicePoint); |
||
| 4123 | break; |
||
| 4124 | case 'circle': |
||
| 4125 | $hotspotProperties = Geometry::decodeEllipse($hotspotCoordinates); |
||
| 4126 | $choiceIsValid = Geometry::pointIsInEllipse($hotspotProperties, $choicePoint); |
||
| 4127 | break; |
||
| 4128 | case 'poly': |
||
| 4129 | $hotspotProperties = Geometry::decodePolygon($hotspotCoordinates); |
||
| 4130 | $choiceIsValid = Geometry::pointIsInPolygon($hotspotProperties, $choicePoint); |
||
| 4131 | break; |
||
| 4132 | } |
||
| 4133 | } |
||
| 4134 | |||
| 4135 | $choice[$answerAutoId] = 0; |
||
| 4136 | if ($choiceIsValid) { |
||
| 4137 | $questionScore += $answerWeighting; |
||
| 4138 | $totalScore += $answerWeighting; |
||
| 4139 | $choice[$answerAutoId] = 1; |
||
| 4140 | $choice[$answerIid] = 1; |
||
| 4141 | } |
||
| 4142 | } |
||
| 4143 | } |
||
| 4144 | break; |
||
| 4145 | // @todo never added to chamilo |
||
| 4146 | //for hotspot with fixed order |
||
| 4147 | case HOT_SPOT_ORDER: |
||
| 4148 | $studentChoice = $choice['order'][$answerId]; |
||
| 4149 | if ($studentChoice == $answerId) { |
||
| 4150 | $questionScore += $answerWeighting; |
||
| 4151 | $totalScore += $answerWeighting; |
||
| 4152 | $studentChoice = true; |
||
| 4153 | } else { |
||
| 4154 | $studentChoice = false; |
||
| 4155 | } |
||
| 4156 | break; |
||
| 4157 | // for hotspot with delineation |
||
| 4158 | case HOT_SPOT_DELINEATION: |
||
| 4159 | if ($from_database) { |
||
| 4160 | // getting the user answer |
||
| 4161 | $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
||
| 4162 | $query = "SELECT hotspot_correct, hotspot_coordinate |
||
| 4163 | FROM $TBL_TRACK_HOTSPOT |
||
| 4164 | WHERE |
||
| 4165 | hotspot_exe_id = '".$exeId."' AND |
||
| 4166 | hotspot_question_id= '".$questionId."' AND |
||
| 4167 | hotspot_answer_id='1'"; |
||
| 4168 | //by default we take 1 because it's a delineation |
||
| 4169 | $resq = Database::query($query); |
||
| 4170 | $row = Database::fetch_array($resq,'ASSOC'); |
||
| 4171 | |||
| 4172 | $choice = $row['hotspot_correct']; |
||
| 4173 | $user_answer = $row['hotspot_coordinate']; |
||
| 4174 | |||
| 4175 | // THIS is very important otherwise the poly_compile will throw an error!! |
||
| 4176 | // round-up the coordinates |
||
| 4177 | $coords = explode('/',$user_answer); |
||
| 4178 | $user_array = ''; |
||
| 4179 | View Code Duplication | foreach ($coords as $coord) { |
|
| 4180 | list($x,$y) = explode(';',$coord); |
||
| 4181 | $user_array .= round($x).';'.round($y).'/'; |
||
| 4182 | } |
||
| 4183 | $user_array = substr($user_array,0,-1); |
||
| 4184 | } else { |
||
| 4185 | if (!empty($studentChoice)) { |
||
| 4186 | $newquestionList[] = $questionId; |
||
| 4187 | } |
||
| 4188 | |||
| 4189 | if ($answerId === 1) { |
||
| 4190 | $studentChoice = $choice[$answerId]; |
||
| 4191 | $questionScore += $answerWeighting; |
||
| 4192 | |||
| 4193 | if ($hotspot_delineation_result[1]==1) { |
||
| 4194 | $totalScore += $answerWeighting; //adding the total |
||
| 4195 | } |
||
| 4196 | } |
||
| 4197 | } |
||
| 4198 | $_SESSION['hotspot_coord'][1] = $delineation_cord; |
||
| 4199 | $_SESSION['hotspot_dest'][1] = $answer_delineation_destination; |
||
| 4200 | break; |
||
| 4201 | } // end switch Answertype |
||
| 4202 | |||
| 4203 | if ($show_result) { |
||
| 4204 | if ($debug) error_log('Showing questions $from '.$from); |
||
| 4205 | if ($from == 'exercise_result') { |
||
| 4206 | //display answers (if not matching type, or if the answer is correct) |
||
| 4207 | if ( |
||
| 4208 | !in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]) || |
||
| 4209 | $answerCorrect |
||
| 4210 | ) { |
||
| 4211 | if ( |
||
| 4212 | in_array( |
||
| 4213 | $answerType, |
||
| 4214 | array( |
||
| 4215 | UNIQUE_ANSWER, |
||
| 4216 | UNIQUE_ANSWER_IMAGE, |
||
| 4217 | UNIQUE_ANSWER_NO_OPTION, |
||
| 4218 | MULTIPLE_ANSWER, |
||
| 4219 | MULTIPLE_ANSWER_COMBINATION, |
||
| 4220 | GLOBAL_MULTIPLE_ANSWER |
||
| 4221 | ) |
||
| 4222 | ) |
||
| 4223 | ) { |
||
| 4224 | ExerciseShowFunctions::display_unique_or_multiple_answer( |
||
| 4225 | $feedback_type, |
||
| 4226 | $answerType, |
||
| 4227 | $studentChoice, |
||
| 4228 | $answer, |
||
| 4229 | $answerComment, |
||
| 4230 | $answerCorrect, |
||
| 4231 | 0, |
||
| 4232 | 0, |
||
| 4233 | 0, |
||
| 4234 | $results_disabled, |
||
| 4235 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4236 | ); |
||
| 4237 | } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { |
||
| 4238 | ExerciseShowFunctions::display_multiple_answer_true_false( |
||
| 4239 | $feedback_type, |
||
| 4240 | $answerType, |
||
| 4241 | $studentChoice, |
||
| 4242 | $answer, |
||
| 4243 | $answerComment, |
||
| 4244 | $answerCorrect, |
||
| 4245 | 0, |
||
| 4246 | $questionId, |
||
| 4247 | 0, |
||
| 4248 | $results_disabled, |
||
| 4249 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4250 | ); |
||
| 4251 | } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) { |
||
| 4252 | ExerciseShowFunctions::display_multiple_answer_combination_true_false( |
||
| 4253 | $feedback_type, |
||
| 4254 | $answerType, |
||
| 4255 | $studentChoice, |
||
| 4256 | $answer, |
||
| 4257 | $answerComment, |
||
| 4258 | $answerCorrect, |
||
| 4259 | 0, |
||
| 4260 | 0, |
||
| 4261 | 0, |
||
| 4262 | $results_disabled, |
||
| 4263 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4264 | ); |
||
| 4265 | } elseif ($answerType == FILL_IN_BLANKS) { |
||
| 4266 | ExerciseShowFunctions::display_fill_in_blanks_answer( |
||
| 4267 | $feedback_type, |
||
| 4268 | $answer, |
||
| 4269 | 0, |
||
| 4270 | 0, |
||
| 4271 | $results_disabled, |
||
| 4272 | '', |
||
| 4273 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4274 | ); |
||
| 4275 | } elseif ($answerType == CALCULATED_ANSWER) { |
||
| 4276 | ExerciseShowFunctions::display_calculated_answer( |
||
| 4277 | $feedback_type, |
||
| 4278 | $answer, |
||
| 4279 | 0, |
||
| 4280 | 0, |
||
| 4281 | $results_disabled, |
||
| 4282 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4283 | ); |
||
| 4284 | } elseif ($answerType == FREE_ANSWER) { |
||
| 4285 | ExerciseShowFunctions::display_free_answer( |
||
| 4286 | $feedback_type, |
||
| 4287 | $choice, |
||
| 4288 | $exeId, |
||
| 4289 | $questionId, |
||
| 4290 | $questionScore, |
||
| 4291 | $results_disabled |
||
| 4292 | ); |
||
| 4293 | } elseif ($answerType == ORAL_EXPRESSION) { |
||
| 4294 | // to store the details of open questions in an array to be used in mail |
||
| 4295 | /** @var OralExpression $objQuestionTmp */ |
||
| 4296 | ExerciseShowFunctions::display_oral_expression_answer( |
||
| 4297 | $feedback_type, |
||
| 4298 | $choice, |
||
| 4299 | 0, |
||
| 4300 | 0, |
||
| 4301 | $objQuestionTmp->getFileUrl(true), |
||
| 4302 | $results_disabled |
||
| 4303 | ); |
||
| 4304 | } elseif ($answerType == HOT_SPOT) { |
||
| 4305 | foreach ($orderedHotspots as $correctAnswerId => $hotspot) { |
||
| 4306 | if ($hotspot->getHotspotAnswerId() == $answerAutoId) { |
||
| 4307 | break; |
||
| 4308 | } |
||
| 4309 | } |
||
| 4310 | |||
| 4311 | ExerciseShowFunctions::display_hotspot_answer( |
||
| 4312 | $feedback_type, |
||
| 4313 | $answerId, |
||
| 4314 | $answer, |
||
| 4315 | $studentChoice, |
||
| 4316 | $answerComment, |
||
| 4317 | $results_disabled, |
||
| 4318 | $answerId, |
||
| 4319 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4320 | ); |
||
| 4321 | } elseif ($answerType == HOT_SPOT_ORDER) { |
||
| 4322 | ExerciseShowFunctions::display_hotspot_order_answer( |
||
| 4323 | $feedback_type, |
||
| 4324 | $answerId, |
||
| 4325 | $answer, |
||
| 4326 | $studentChoice, |
||
| 4327 | $answerComment |
||
| 4328 | ); |
||
| 4329 | } elseif ($answerType == HOT_SPOT_DELINEATION) { |
||
| 4330 | $user_answer = $_SESSION['exerciseResultCoordinates'][$questionId]; |
||
| 4331 | |||
| 4332 | //round-up the coordinates |
||
| 4333 | $coords = explode('/',$user_answer); |
||
| 4334 | $user_array = ''; |
||
| 4335 | View Code Duplication | foreach ($coords as $coord) { |
|
| 4336 | list($x,$y) = explode(';',$coord); |
||
| 4337 | $user_array .= round($x).';'.round($y).'/'; |
||
| 4338 | } |
||
| 4339 | $user_array = substr($user_array,0,-1); |
||
| 4340 | |||
| 4341 | View Code Duplication | if ($next) { |
|
| 4342 | |||
| 4343 | $user_answer = $user_array; |
||
| 4344 | |||
| 4345 | // we compare only the delineation not the other points |
||
| 4346 | $answer_question = $_SESSION['hotspot_coord'][1]; |
||
| 4347 | $answerDestination = $_SESSION['hotspot_dest'][1]; |
||
| 4348 | |||
| 4349 | //calculating the area |
||
| 4350 | $poly_user = convert_coordinates($user_answer, '/'); |
||
| 4351 | $poly_answer = convert_coordinates($answer_question, '|'); |
||
| 4352 | $max_coord = poly_get_max($poly_user, $poly_answer); |
||
| 4353 | $poly_user_compiled = poly_compile($poly_user, $max_coord); |
||
| 4354 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
||
| 4355 | $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
||
| 4356 | |||
| 4357 | $overlap = $poly_results['both']; |
||
| 4358 | $poly_answer_area = $poly_results['s1']; |
||
| 4359 | $poly_user_area = $poly_results['s2']; |
||
| 4360 | $missing = $poly_results['s1Only']; |
||
| 4361 | $excess = $poly_results['s2Only']; |
||
| 4362 | |||
| 4363 | //$overlap = round(polygons_overlap($poly_answer,$poly_user)); |
||
| 4364 | // //this is an area in pixels |
||
| 4365 | if ($debug > 0) { |
||
| 4366 | error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); |
||
| 4367 | } |
||
| 4368 | |||
| 4369 | if ($overlap < 1) { |
||
| 4370 | //shortcut to avoid complicated calculations |
||
| 4371 | $final_overlap = 0; |
||
| 4372 | $final_missing = 100; |
||
| 4373 | $final_excess = 100; |
||
| 4374 | } else { |
||
| 4375 | // the final overlap is the percentage of the initial polygon |
||
| 4376 | // that is overlapped by the user's polygon |
||
| 4377 | $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
||
| 4378 | if ($debug > 1) { |
||
| 4379 | error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); |
||
| 4380 | } |
||
| 4381 | // the final missing area is the percentage of the initial polygon |
||
| 4382 | // that is not overlapped by the user's polygon |
||
| 4383 | $final_missing = 100 - $final_overlap; |
||
| 4384 | if ($debug > 1) { |
||
| 4385 | error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); |
||
| 4386 | } |
||
| 4387 | // the final excess area is the percentage of the initial polygon's size |
||
| 4388 | // that is covered by the user's polygon outside of the initial polygon |
||
| 4389 | $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
||
| 4390 | if ($debug > 1) { |
||
| 4391 | error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); |
||
| 4392 | } |
||
| 4393 | } |
||
| 4394 | |||
| 4395 | //checking the destination parameters parsing the "@@" |
||
| 4396 | $destination_items= explode('@@', $answerDestination); |
||
| 4397 | $threadhold_total = $destination_items[0]; |
||
| 4398 | $threadhold_items=explode(';',$threadhold_total); |
||
| 4399 | $threadhold1 = $threadhold_items[0]; // overlap |
||
| 4400 | $threadhold2 = $threadhold_items[1]; // excess |
||
| 4401 | $threadhold3 = $threadhold_items[2]; //missing |
||
| 4402 | |||
| 4403 | // if is delineation |
||
| 4404 | if ($answerId===1) { |
||
| 4405 | //setting colors |
||
| 4406 | if ($final_overlap>=$threadhold1) { |
||
| 4407 | $overlap_color=true; //echo 'a'; |
||
| 4408 | } |
||
| 4409 | //echo $excess.'-'.$threadhold2; |
||
| 4410 | if ($final_excess<=$threadhold2) { |
||
| 4411 | $excess_color=true; //echo 'b'; |
||
| 4412 | } |
||
| 4413 | //echo '--------'.$missing.'-'.$threadhold3; |
||
| 4414 | if ($final_missing<=$threadhold3) { |
||
| 4415 | $missing_color=true; //echo 'c'; |
||
| 4416 | } |
||
| 4417 | |||
| 4418 | // if pass |
||
| 4419 | if ( |
||
| 4420 | $final_overlap >= $threadhold1 && |
||
| 4421 | $final_missing <= $threadhold3 && |
||
| 4422 | $final_excess <= $threadhold2 |
||
| 4423 | ) { |
||
| 4424 | $next=1; //go to the oars |
||
| 4425 | $result_comment=get_lang('Acceptable'); |
||
| 4426 | $final_answer = 1; // do not update with update_exercise_attempt |
||
| 4427 | } else { |
||
| 4428 | $next=0; |
||
| 4429 | $result_comment=get_lang('Unacceptable'); |
||
| 4430 | $comment=$answerDestination=$objAnswerTmp->selectComment(1); |
||
| 4431 | $answerDestination=$objAnswerTmp->selectDestination(1); |
||
| 4432 | //checking the destination parameters parsing the "@@" |
||
| 4433 | $destination_items= explode('@@', $answerDestination); |
||
| 4434 | } |
||
| 4435 | } elseif($answerId>1) { |
||
| 4436 | if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
||
| 4437 | if ($debug>0) { |
||
| 4438 | error_log(__LINE__.' - answerId is of type noerror',0); |
||
| 4439 | } |
||
| 4440 | //type no error shouldn't be treated |
||
| 4441 | $next = 1; |
||
| 4442 | continue; |
||
| 4443 | } |
||
| 4444 | if ($debug>0) { |
||
| 4445 | error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0); |
||
| 4446 | } |
||
| 4447 | //check the intersection between the oar and the user |
||
| 4448 | //echo 'user'; print_r($x_user_list); print_r($y_user_list); |
||
| 4449 | //echo 'official';print_r($x_list);print_r($y_list); |
||
| 4450 | //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
||
| 4451 | $inter= $result['success']; |
||
| 4452 | |||
| 4453 | //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4454 | $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4455 | |||
| 4456 | $poly_answer = convert_coordinates($delineation_cord,'|'); |
||
| 4457 | $max_coord = poly_get_max($poly_user,$poly_answer); |
||
| 4458 | $poly_answer_compiled = poly_compile($poly_answer,$max_coord); |
||
| 4459 | $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); |
||
| 4460 | |||
| 4461 | if ($overlap == false) { |
||
| 4462 | //all good, no overlap |
||
| 4463 | $next = 1; |
||
| 4464 | continue; |
||
| 4465 | } else { |
||
| 4466 | if ($debug>0) { |
||
| 4467 | error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0); |
||
| 4468 | } |
||
| 4469 | $organs_at_risk_hit++; |
||
| 4470 | //show the feedback |
||
| 4471 | $next=0; |
||
| 4472 | $comment=$answerDestination=$objAnswerTmp->selectComment($answerId); |
||
| 4473 | $answerDestination=$objAnswerTmp->selectDestination($answerId); |
||
| 4474 | |||
| 4475 | $destination_items= explode('@@', $answerDestination); |
||
| 4476 | $try_hotspot=$destination_items[1]; |
||
| 4477 | $lp_hotspot=$destination_items[2]; |
||
| 4478 | $select_question_hotspot=$destination_items[3]; |
||
| 4479 | $url_hotspot=$destination_items[4]; |
||
| 4480 | } |
||
| 4481 | } |
||
| 4482 | } else { // the first delineation feedback |
||
| 4483 | if ($debug>0) { |
||
| 4484 | error_log(__LINE__.' first',0); |
||
| 4485 | } |
||
| 4486 | } |
||
| 4487 | } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) { |
||
| 4488 | echo '<tr>'; |
||
| 4489 | echo Display::tag('td', $answerMatching[$answerId]); |
||
| 4490 | echo Display::tag( |
||
| 4491 | 'td', |
||
| 4492 | "$user_answer / " . Display::tag( |
||
| 4493 | 'strong', |
||
| 4494 | $answerMatching[$answerCorrect], |
||
| 4495 | ['style' => 'color: #008000; font-weight: bold;'] |
||
| 4496 | ) |
||
| 4497 | ); |
||
| 4498 | echo '</tr>'; |
||
| 4499 | } |
||
| 4500 | } |
||
| 4501 | } else { |
||
| 4502 | if ($debug) error_log('Showing questions $from '.$from); |
||
| 4503 | |||
| 4504 | switch ($answerType) { |
||
| 4505 | case UNIQUE_ANSWER: |
||
| 4506 | case UNIQUE_ANSWER_IMAGE: |
||
| 4507 | case UNIQUE_ANSWER_NO_OPTION: |
||
| 4508 | case MULTIPLE_ANSWER: |
||
| 4509 | case GLOBAL_MULTIPLE_ANSWER : |
||
| 4510 | View Code Duplication | case MULTIPLE_ANSWER_COMBINATION: |
|
| 4511 | if ($answerId == 1) { |
||
| 4512 | ExerciseShowFunctions::display_unique_or_multiple_answer( |
||
| 4513 | $feedback_type, |
||
| 4514 | $answerType, |
||
| 4515 | $studentChoice, |
||
| 4516 | $answer, |
||
| 4517 | $answerComment, |
||
| 4518 | $answerCorrect, |
||
| 4519 | $exeId, |
||
| 4520 | $questionId, |
||
| 4521 | $answerId, |
||
| 4522 | $results_disabled, |
||
| 4523 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4524 | ); |
||
| 4525 | } else { |
||
| 4526 | ExerciseShowFunctions::display_unique_or_multiple_answer( |
||
| 4527 | $feedback_type, |
||
| 4528 | $answerType, |
||
| 4529 | $studentChoice, |
||
| 4530 | $answer, |
||
| 4531 | $answerComment, |
||
| 4532 | $answerCorrect, |
||
| 4533 | $exeId, |
||
| 4534 | $questionId, |
||
| 4535 | '', |
||
| 4536 | $results_disabled, |
||
| 4537 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4538 | ); |
||
| 4539 | } |
||
| 4540 | break; |
||
| 4541 | View Code Duplication | case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: |
|
| 4542 | if ($answerId == 1) { |
||
| 4543 | ExerciseShowFunctions::display_multiple_answer_combination_true_false( |
||
| 4544 | $feedback_type, |
||
| 4545 | $answerType, |
||
| 4546 | $studentChoice, |
||
| 4547 | $answer, |
||
| 4548 | $answerComment, |
||
| 4549 | $answerCorrect, |
||
| 4550 | $exeId, |
||
| 4551 | $questionId, |
||
| 4552 | $answerId, |
||
| 4553 | $results_disabled, |
||
| 4554 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4555 | ); |
||
| 4556 | } else { |
||
| 4557 | ExerciseShowFunctions::display_multiple_answer_combination_true_false( |
||
| 4558 | $feedback_type, |
||
| 4559 | $answerType, |
||
| 4560 | $studentChoice, |
||
| 4561 | $answer, |
||
| 4562 | $answerComment, |
||
| 4563 | $answerCorrect, |
||
| 4564 | $exeId, |
||
| 4565 | $questionId, |
||
| 4566 | '', |
||
| 4567 | $results_disabled, |
||
| 4568 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4569 | ); |
||
| 4570 | } |
||
| 4571 | break; |
||
| 4572 | View Code Duplication | case MULTIPLE_ANSWER_TRUE_FALSE: |
|
| 4573 | if ($answerId == 1) { |
||
| 4574 | ExerciseShowFunctions::display_multiple_answer_true_false( |
||
| 4575 | $feedback_type, |
||
| 4576 | $answerType, |
||
| 4577 | $studentChoice, |
||
| 4578 | $answer, |
||
| 4579 | $answerComment, |
||
| 4580 | $answerCorrect, |
||
| 4581 | $exeId, |
||
| 4582 | $questionId, |
||
| 4583 | $answerId, |
||
| 4584 | $results_disabled, |
||
| 4585 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4586 | ); |
||
| 4587 | } else { |
||
| 4588 | ExerciseShowFunctions::display_multiple_answer_true_false( |
||
| 4589 | $feedback_type, |
||
| 4590 | $answerType, |
||
| 4591 | $studentChoice, |
||
| 4592 | $answer, |
||
| 4593 | $answerComment, |
||
| 4594 | $answerCorrect, |
||
| 4595 | $exeId, |
||
| 4596 | $questionId, |
||
| 4597 | '', |
||
| 4598 | $results_disabled, |
||
| 4599 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4600 | ); |
||
| 4601 | } |
||
| 4602 | break; |
||
| 4603 | case FILL_IN_BLANKS: |
||
| 4604 | ExerciseShowFunctions::display_fill_in_blanks_answer( |
||
| 4605 | $feedback_type, |
||
| 4606 | $answer, |
||
| 4607 | $exeId, |
||
| 4608 | $questionId, |
||
| 4609 | $results_disabled, |
||
| 4610 | $str, |
||
| 4611 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4612 | ); |
||
| 4613 | break; |
||
| 4614 | case CALCULATED_ANSWER: |
||
| 4615 | ExerciseShowFunctions::display_calculated_answer( |
||
| 4616 | $feedback_type, |
||
| 4617 | $answer, |
||
| 4618 | $exeId, |
||
| 4619 | $questionId, |
||
| 4620 | $results_disabled, |
||
| 4621 | '', |
||
| 4622 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4623 | ); |
||
| 4624 | break; |
||
| 4625 | case FREE_ANSWER: |
||
| 4626 | echo ExerciseShowFunctions::display_free_answer( |
||
| 4627 | $feedback_type, |
||
| 4628 | $choice, |
||
| 4629 | $exeId, |
||
| 4630 | $questionId, |
||
| 4631 | $questionScore, |
||
| 4632 | $results_disabled |
||
| 4633 | ); |
||
| 4634 | break; |
||
| 4635 | case ORAL_EXPRESSION: |
||
| 4636 | echo '<tr> |
||
| 4637 | <td valign="top">' . ExerciseShowFunctions::display_oral_expression_answer( |
||
| 4638 | $feedback_type, |
||
| 4639 | $choice, |
||
| 4640 | $exeId, |
||
| 4641 | $questionId, |
||
| 4642 | $objQuestionTmp->getFileUrl(), |
||
| 4643 | $results_disabled |
||
| 4644 | ) . '</td> |
||
| 4645 | </tr> |
||
| 4646 | </table>'; |
||
| 4647 | break; |
||
| 4648 | case HOT_SPOT: |
||
| 4649 | ExerciseShowFunctions::display_hotspot_answer( |
||
| 4650 | $feedback_type, |
||
| 4651 | $answerId, |
||
| 4652 | $answer, |
||
| 4653 | $studentChoice, |
||
| 4654 | $answerComment, |
||
| 4655 | $results_disabled, |
||
| 4656 | $answerId, |
||
| 4657 | $showTotalScoreAndUserChoicesInLastAttempt |
||
| 4658 | ); |
||
| 4659 | break; |
||
| 4660 | case HOT_SPOT_DELINEATION: |
||
| 4661 | $user_answer = $user_array; |
||
| 4662 | View Code Duplication | if ($next) { |
|
| 4663 | //$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); |
||
| 4664 | // Save into db |
||
| 4665 | /* $sql = "INSERT INTO $tbl_track_e_hotspot ( |
||
| 4666 | * hotspot_user_id, |
||
| 4667 | * hotspot_course_code, |
||
| 4668 | * hotspot_exe_id, |
||
| 4669 | * hotspot_question_id, |
||
| 4670 | * hotspot_answer_id, |
||
| 4671 | * hotspot_correct, |
||
| 4672 | * hotspot_coordinate |
||
| 4673 | * ) |
||
| 4674 | VALUES ( |
||
| 4675 | * '".Database::escape_string($_user['user_id'])."', |
||
| 4676 | * '".Database::escape_string($_course['id'])."', |
||
| 4677 | * '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', |
||
| 4678 | * '".Database::escape_string($answerId)."', |
||
| 4679 | * '".Database::escape_string($studentChoice)."', |
||
| 4680 | * '".Database::escape_string($user_array)."')"; |
||
| 4681 | $result = Database::query($sql,__FILE__,__LINE__); |
||
| 4682 | */ |
||
| 4683 | $user_answer = $user_array; |
||
| 4684 | |||
| 4685 | // we compare only the delineation not the other points |
||
| 4686 | $answer_question = $_SESSION['hotspot_coord'][1]; |
||
| 4687 | $answerDestination = $_SESSION['hotspot_dest'][1]; |
||
| 4688 | |||
| 4689 | //calculating the area |
||
| 4690 | $poly_user = convert_coordinates($user_answer, '/'); |
||
| 4691 | $poly_answer = convert_coordinates($answer_question, '|'); |
||
| 4692 | |||
| 4693 | $max_coord = poly_get_max($poly_user, $poly_answer); |
||
| 4694 | $poly_user_compiled = poly_compile($poly_user, $max_coord); |
||
| 4695 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
||
| 4696 | $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); |
||
| 4697 | |||
| 4698 | $overlap = $poly_results['both']; |
||
| 4699 | $poly_answer_area = $poly_results['s1']; |
||
| 4700 | $poly_user_area = $poly_results['s2']; |
||
| 4701 | $missing = $poly_results['s1Only']; |
||
| 4702 | $excess = $poly_results['s2Only']; |
||
| 4703 | |||
| 4704 | //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels |
||
| 4705 | if ($debug > 0) { |
||
| 4706 | error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); |
||
| 4707 | } |
||
| 4708 | if ($overlap < 1) { |
||
| 4709 | //shortcut to avoid complicated calculations |
||
| 4710 | $final_overlap = 0; |
||
| 4711 | $final_missing = 100; |
||
| 4712 | $final_excess = 100; |
||
| 4713 | } else { |
||
| 4714 | // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon |
||
| 4715 | $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); |
||
| 4716 | if ($debug > 1) { |
||
| 4717 | error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); |
||
| 4718 | } |
||
| 4719 | // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon |
||
| 4720 | $final_missing = 100 - $final_overlap; |
||
| 4721 | if ($debug > 1) { |
||
| 4722 | error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); |
||
| 4723 | } |
||
| 4724 | // 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 |
||
| 4725 | $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); |
||
| 4726 | if ($debug > 1) { |
||
| 4727 | error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); |
||
| 4728 | } |
||
| 4729 | } |
||
| 4730 | |||
| 4731 | //checking the destination parameters parsing the "@@" |
||
| 4732 | $destination_items = explode('@@', $answerDestination); |
||
| 4733 | $threadhold_total = $destination_items[0]; |
||
| 4734 | $threadhold_items = explode(';', $threadhold_total); |
||
| 4735 | $threadhold1 = $threadhold_items[0]; // overlap |
||
| 4736 | $threadhold2 = $threadhold_items[1]; // excess |
||
| 4737 | $threadhold3 = $threadhold_items[2]; //missing |
||
| 4738 | // if is delineation |
||
| 4739 | if ($answerId === 1) { |
||
| 4740 | //setting colors |
||
| 4741 | if ($final_overlap >= $threadhold1) { |
||
| 4742 | $overlap_color = true; //echo 'a'; |
||
| 4743 | } |
||
| 4744 | //echo $excess.'-'.$threadhold2; |
||
| 4745 | if ($final_excess <= $threadhold2) { |
||
| 4746 | $excess_color = true; //echo 'b'; |
||
| 4747 | } |
||
| 4748 | //echo '--------'.$missing.'-'.$threadhold3; |
||
| 4749 | if ($final_missing <= $threadhold3) { |
||
| 4750 | $missing_color = true; //echo 'c'; |
||
| 4751 | } |
||
| 4752 | |||
| 4753 | // if pass |
||
| 4754 | if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) { |
||
| 4755 | $next = 1; //go to the oars |
||
| 4756 | $result_comment = get_lang('Acceptable'); |
||
| 4757 | $final_answer = 1; // do not update with update_exercise_attempt |
||
| 4758 | } else { |
||
| 4759 | $next = 0; |
||
| 4760 | $result_comment = get_lang('Unacceptable'); |
||
| 4761 | $comment = $answerDestination = $objAnswerTmp->selectComment(1); |
||
| 4762 | $answerDestination = $objAnswerTmp->selectDestination(1); |
||
| 4763 | //checking the destination parameters parsing the "@@" |
||
| 4764 | $destination_items = explode('@@', $answerDestination); |
||
| 4765 | } |
||
| 4766 | } elseif ($answerId > 1) { |
||
| 4767 | if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { |
||
| 4768 | if ($debug > 0) { |
||
| 4769 | error_log(__LINE__ . ' - answerId is of type noerror', 0); |
||
| 4770 | } |
||
| 4771 | //type no error shouldn't be treated |
||
| 4772 | $next = 1; |
||
| 4773 | continue; |
||
| 4774 | } |
||
| 4775 | if ($debug > 0) { |
||
| 4776 | error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0); |
||
| 4777 | } |
||
| 4778 | //check the intersection between the oar and the user |
||
| 4779 | //echo 'user'; print_r($x_user_list); print_r($y_user_list); |
||
| 4780 | //echo 'official';print_r($x_list);print_r($y_list); |
||
| 4781 | //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); |
||
| 4782 | $inter = $result['success']; |
||
| 4783 | |||
| 4784 | //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4785 | $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId); |
||
| 4786 | |||
| 4787 | $poly_answer = convert_coordinates($delineation_cord, '|'); |
||
| 4788 | $max_coord = poly_get_max($poly_user, $poly_answer); |
||
| 4789 | $poly_answer_compiled = poly_compile($poly_answer, $max_coord); |
||
| 4790 | $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); |
||
| 4791 | |||
| 4792 | if ($overlap == false) { |
||
| 4793 | //all good, no overlap |
||
| 4794 | $next = 1; |
||
| 4795 | continue; |
||
| 4796 | } else { |
||
| 4797 | if ($debug > 0) { |
||
| 4798 | error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0); |
||
| 4799 | } |
||
| 4800 | $organs_at_risk_hit++; |
||
| 4801 | //show the feedback |
||
| 4802 | $next = 0; |
||
| 4803 | $comment = $answerDestination = $objAnswerTmp->selectComment($answerId); |
||
| 4804 | $answerDestination = $objAnswerTmp->selectDestination($answerId); |
||
| 4805 | |||
| 4806 | $destination_items = explode('@@', $answerDestination); |
||
| 4807 | $try_hotspot = $destination_items[1]; |
||
| 4808 | $lp_hotspot = $destination_items[2]; |
||
| 4809 | $select_question_hotspot = $destination_items[3]; |
||
| 4810 | $url_hotspot=$destination_items[4]; |
||
| 4811 | } |
||
| 4812 | } |
||
| 4813 | } else { // the first delineation feedback |
||
| 4814 | if ($debug > 0) { |
||
| 4815 | error_log(__LINE__ . ' first', 0); |
||
| 4816 | } |
||
| 4817 | } |
||
| 4818 | break; |
||
| 4819 | case HOT_SPOT_ORDER: |
||
| 4820 | ExerciseShowFunctions::display_hotspot_order_answer( |
||
| 4821 | $feedback_type, |
||
| 4822 | $answerId, |
||
| 4823 | $answer, |
||
| 4824 | $studentChoice, |
||
| 4825 | $answerComment |
||
| 4826 | ); |
||
| 4827 | break; |
||
| 4828 | case DRAGGABLE: |
||
| 4829 | //no break |
||
| 4830 | case MATCHING_DRAGGABLE: |
||
| 4831 | //no break |
||
| 4832 | case MATCHING: |
||
| 4833 | echo '<tr>'; |
||
| 4834 | echo Display::tag('td', $answerMatching[$answerId]); |
||
| 4835 | echo Display::tag( |
||
| 4836 | 'td', |
||
| 4837 | "$user_answer / " . Display::tag( |
||
| 4838 | 'strong', |
||
| 4839 | $answerMatching[$answerCorrect], |
||
| 4840 | ['style' => 'color: #008000; font-weight: bold;'] |
||
| 4841 | ) |
||
| 4842 | ); |
||
| 4843 | echo '</tr>'; |
||
| 4844 | |||
| 4845 | break; |
||
| 4846 | } |
||
| 4847 | } |
||
| 4848 | } |
||
| 4849 | if ($debug) error_log(' ------ '); |
||
| 4850 | } // end for that loops over all answers of the current question |
||
| 4851 | |||
| 4852 | if ($debug) error_log('-- end answer loop --'); |
||
| 4853 | |||
| 4854 | $final_answer = true; |
||
| 4855 | |||
| 4856 | foreach ($real_answers as $my_answer) { |
||
| 4857 | if (!$my_answer) { |
||
| 4858 | $final_answer = false; |
||
| 4859 | } |
||
| 4860 | } |
||
| 4861 | |||
| 4862 | //we add the total score after dealing with the answers |
||
| 4863 | if ($answerType == MULTIPLE_ANSWER_COMBINATION || |
||
| 4864 | $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE |
||
| 4865 | ) { |
||
| 4866 | if ($final_answer) { |
||
| 4867 | //getting only the first score where we save the weight of all the question |
||
| 4868 | $answerWeighting = $objAnswerTmp->selectWeighting(1); |
||
| 4869 | $questionScore += $answerWeighting; |
||
| 4870 | $totalScore += $answerWeighting; |
||
| 4871 | } |
||
| 4872 | } |
||
| 4873 | |||
| 4874 | //Fixes multiple answer question in order to be exact |
||
| 4875 | //if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 4876 | /* if ($answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 4877 | $diff = @array_diff($answer_correct_array, $real_answers); |
||
| 4878 | |||
| 4879 | // All good answers or nothing works like exact |
||
| 4880 | |||
| 4881 | $counter = 1; |
||
| 4882 | $correct_answer = true; |
||
| 4883 | foreach ($real_answers as $my_answer) { |
||
| 4884 | if ($debug) |
||
| 4885 | error_log(" my_answer: $my_answer answer_correct_array[counter]: ".$answer_correct_array[$counter]); |
||
| 4886 | if ($my_answer != $answer_correct_array[$counter]) { |
||
| 4887 | $correct_answer = false; |
||
| 4888 | break; |
||
| 4889 | } |
||
| 4890 | $counter++; |
||
| 4891 | } |
||
| 4892 | |||
| 4893 | if ($debug) error_log(" answer_correct_array: ".print_r($answer_correct_array, 1).""); |
||
| 4894 | if ($debug) error_log(" real_answers: ".print_r($real_answers, 1).""); |
||
| 4895 | if ($debug) error_log(" correct_answer: ".$correct_answer); |
||
| 4896 | |||
| 4897 | if ($correct_answer == false) { |
||
| 4898 | $questionScore = 0; |
||
| 4899 | } |
||
| 4900 | |||
| 4901 | // This makes the result non exact |
||
| 4902 | if (!empty($diff)) { |
||
| 4903 | $questionScore = 0; |
||
| 4904 | } |
||
| 4905 | }*/ |
||
| 4906 | |||
| 4907 | $extra_data = array( |
||
| 4908 | 'final_overlap' => $final_overlap, |
||
| 4909 | 'final_missing'=>$final_missing, |
||
| 4910 | 'final_excess'=> $final_excess, |
||
| 4911 | 'overlap_color' => $overlap_color, |
||
| 4912 | 'missing_color'=>$missing_color, |
||
| 4913 | 'excess_color'=> $excess_color, |
||
| 4914 | 'threadhold1' => $threadhold1, |
||
| 4915 | 'threadhold2'=>$threadhold2, |
||
| 4916 | 'threadhold3'=> $threadhold3, |
||
| 4917 | ); |
||
| 4918 | if ($from == 'exercise_result') { |
||
| 4919 | // if answer is hotspot. To the difference of exercise_show.php, |
||
| 4920 | // we use the results from the session (from_db=0) |
||
| 4921 | // TODO Change this, because it is wrong to show the user |
||
| 4922 | // some results that haven't been stored in the database yet |
||
| 4923 | if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION ) { |
||
| 4924 | |||
| 4925 | if ($debug) error_log('$from AND this is a hotspot kind of question '); |
||
| 4926 | |||
| 4927 | $my_exe_id = 0; |
||
| 4928 | $from_database = 0; |
||
| 4929 | if ($answerType == HOT_SPOT_DELINEATION) { |
||
| 4930 | if (0) { |
||
| 4931 | if ($overlap_color) { |
||
| 4932 | $overlap_color='green'; |
||
| 4933 | } else { |
||
| 4934 | $overlap_color='red'; |
||
| 4935 | } |
||
| 4936 | if ($missing_color) { |
||
| 4937 | $missing_color='green'; |
||
| 4938 | } else { |
||
| 4939 | $missing_color='red'; |
||
| 4940 | } |
||
| 4941 | if ($excess_color) { |
||
| 4942 | $excess_color='green'; |
||
| 4943 | } else { |
||
| 4944 | $excess_color='red'; |
||
| 4945 | } |
||
| 4946 | if (!is_numeric($final_overlap)) { |
||
| 4947 | $final_overlap = 0; |
||
| 4948 | } |
||
| 4949 | if (!is_numeric($final_missing)) { |
||
| 4950 | $final_missing = 0; |
||
| 4951 | } |
||
| 4952 | if (!is_numeric($final_excess)) { |
||
| 4953 | $final_excess = 0; |
||
| 4954 | } |
||
| 4955 | |||
| 4956 | if ($final_overlap>100) { |
||
| 4957 | $final_overlap = 100; |
||
| 4958 | } |
||
| 4959 | |||
| 4960 | $table_resume='<table class="data_table"> |
||
| 4961 | <tr class="row_odd" > |
||
| 4962 | <td></td> |
||
| 4963 | <td ><b>' . get_lang('Requirements') . '</b></td> |
||
| 4964 | <td><b>' . get_lang('YourAnswer') . '</b></td> |
||
| 4965 | </tr> |
||
| 4966 | <tr class="row_even"> |
||
| 4967 | <td><b>' . get_lang('Overlap') . '</b></td> |
||
| 4968 | <td>' . get_lang('Min') . ' ' . $threadhold1 . '</td> |
||
| 4969 | <td><div style="color:' . $overlap_color . '">' |
||
| 4970 | . (($final_overlap < 0) ? 0 : intval($final_overlap)) . '</div></td> |
||
| 4971 | </tr> |
||
| 4972 | <tr> |
||
| 4973 | <td><b>' . get_lang('Excess') . '</b></td> |
||
| 4974 | <td>' . get_lang('Max') . ' ' . $threadhold2 . '</td> |
||
| 4975 | <td><div style="color:' . $excess_color . '">' |
||
| 4976 | . (($final_excess < 0) ? 0 : intval($final_excess)) . '</div></td> |
||
| 4977 | </tr> |
||
| 4978 | <tr class="row_even"> |
||
| 4979 | <td><b>' . get_lang('Missing') . '</b></td> |
||
| 4980 | <td>' . get_lang('Max') . ' ' . $threadhold3 . '</td> |
||
| 4981 | <td><div style="color:' . $missing_color . '">' |
||
| 4982 | . (($final_missing < 0) ? 0 : intval($final_missing)) . '</div></td> |
||
| 4983 | </tr> |
||
| 4984 | </table>'; |
||
| 4985 | View Code Duplication | if ($next == 0) { |
|
| 4986 | $try = $try_hotspot; |
||
| 4987 | $lp = $lp_hotspot; |
||
| 4988 | $destinationid = $select_question_hotspot; |
||
| 4989 | $url = $url_hotspot; |
||
| 4990 | } else { |
||
| 4991 | //show if no error |
||
| 4992 | //echo 'no error'; |
||
| 4993 | $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers); |
||
| 4994 | $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers); |
||
| 4995 | } |
||
| 4996 | |||
| 4997 | echo '<h1><div style="color:#333;">' . get_lang('Feedback') . '</div></h1> |
||
| 4998 | <p style="text-align:center">'; |
||
| 4999 | |||
| 5000 | $message = '<p>' . get_lang('YourDelineation') . '</p>'; |
||
| 5001 | $message .= $table_resume; |
||
| 5002 | $message .= '<br />' . get_lang('ResultIs') . ' ' . $result_comment . '<br />'; |
||
| 5003 | if ($organs_at_risk_hit > 0) { |
||
| 5004 | $message .= '<p><b>' . get_lang('OARHit') . '</b></p>'; |
||
| 5005 | } |
||
| 5006 | $message .='<p>' . $comment . '</p>'; |
||
| 5007 | echo $message; |
||
| 5008 | } else { |
||
| 5009 | echo $hotspot_delineation_result[0]; //prints message |
||
| 5010 | $from_database = 1; // the hotspot_solution.swf needs this variable |
||
| 5011 | } |
||
| 5012 | |||
| 5013 | //save the score attempts |
||
| 5014 | |||
| 5015 | if (1) { |
||
| 5016 | //getting the answer 1 or 0 comes from exercise_submit_modal.php |
||
| 5017 | $final_answer = $hotspot_delineation_result[1]; |
||
| 5018 | if ($final_answer == 0) { |
||
| 5019 | $questionScore = 0; |
||
| 5020 | } |
||
| 5021 | // we always insert the answer_id 1 = delineation |
||
| 5022 | Event::saveQuestionAttempt($questionScore, 1, $quesId, $exeId, 0); |
||
| 5023 | //in delineation mode, get the answer from $hotspot_delineation_result[1] |
||
| 5024 | $hotspotValue = (int) $hotspot_delineation_result[1] === 1 ? 1 : 0; |
||
| 5025 | Event::saveExerciseAttemptHotspot( |
||
| 5026 | $exeId, |
||
| 5027 | $quesId, |
||
| 5028 | 1, |
||
| 5029 | $hotspotValue, |
||
| 5030 | $exerciseResultCoordinates[$quesId] |
||
| 5031 | ); |
||
| 5032 | } else { |
||
| 5033 | if ($final_answer==0) { |
||
| 5034 | $questionScore = 0; |
||
| 5035 | $answer=0; |
||
| 5036 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0); |
||
| 5037 | if (is_array($exerciseResultCoordinates[$quesId])) { |
||
| 5038 | foreach($exerciseResultCoordinates[$quesId] as $idx => $val) { |
||
| 5039 | Event::saveExerciseAttemptHotspot( |
||
| 5040 | $exeId, |
||
| 5041 | $quesId, |
||
| 5042 | $idx, |
||
| 5043 | 0, |
||
| 5044 | $val |
||
| 5045 | ); |
||
| 5046 | } |
||
| 5047 | } |
||
| 5048 | } else { |
||
| 5049 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0); |
||
| 5050 | if (is_array($exerciseResultCoordinates[$quesId])) { |
||
| 5051 | foreach($exerciseResultCoordinates[$quesId] as $idx => $val) { |
||
| 5052 | $hotspotValue = (int) $choice[$idx] === 1 ? 1 : 0; |
||
| 5053 | Event::saveExerciseAttemptHotspot( |
||
| 5054 | $exeId, |
||
| 5055 | $quesId, |
||
| 5056 | $idx, |
||
| 5057 | $hotspotValue, |
||
| 5058 | $val |
||
| 5059 | ); |
||
| 5060 | } |
||
| 5061 | } |
||
| 5062 | } |
||
| 5063 | } |
||
| 5064 | $my_exe_id = $exeId; |
||
| 5065 | } |
||
| 5066 | } |
||
| 5067 | |||
| 5068 | if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) { |
||
| 5069 | // We made an extra table for the answers |
||
| 5070 | |||
| 5071 | if ($show_result) { |
||
| 5072 | $relPath = api_get_path(WEB_CODE_PATH); |
||
| 5073 | // if ($origin != 'learnpath') { |
||
| 5074 | echo '</table></td></tr>'; |
||
| 5075 | echo " |
||
| 5076 | <tr> |
||
| 5077 | <td colspan=\"2\"> |
||
| 5078 | <p><em>" . get_lang('HotSpot') . "</em></p> |
||
| 5079 | <div id=\"hotspot-solution-$questionId\"></div> |
||
| 5080 | <script> |
||
| 5081 | $(document).on('ready', function () { |
||
| 5082 | new HotspotQuestion({ |
||
| 5083 | questionId: $questionId, |
||
| 5084 | exerciseId: $exeId, |
||
| 5085 | selector: '#hotspot-solution-$questionId', |
||
| 5086 | for: 'solution', |
||
| 5087 | relPath: '$relPath' |
||
| 5088 | }); |
||
| 5089 | }); |
||
| 5090 | </script> |
||
| 5091 | </td> |
||
| 5092 | </tr> |
||
| 5093 | "; |
||
| 5094 | // } |
||
| 5095 | } |
||
| 5096 | } |
||
| 5097 | |||
| 5098 | //if ($origin != 'learnpath') { |
||
| 5099 | if ($show_result) { |
||
| 5100 | echo '</table>'; |
||
| 5101 | } |
||
| 5102 | // } |
||
| 5103 | } |
||
| 5104 | unset ($objAnswerTmp); |
||
| 5105 | |||
| 5106 | $totalWeighting += $questionWeighting; |
||
| 5107 | // Store results directly in the database |
||
| 5108 | // For all in one page exercises, the results will be |
||
| 5109 | // stored by exercise_results.php (using the session) |
||
| 5110 | |||
| 5111 | if ($saved_results) { |
||
| 5112 | if ($debug) error_log("Save question results $saved_results"); |
||
| 5113 | if ($debug) error_log(print_r($choice ,1 )); |
||
| 5114 | |||
| 5115 | if (empty($choice)) { |
||
| 5116 | $choice = 0; |
||
| 5117 | } |
||
| 5118 | if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { |
||
| 5119 | if ($choice != 0) { |
||
| 5120 | $reply = array_keys($choice); |
||
| 5121 | for ($i = 0; $i < sizeof($reply); $i++) { |
||
| 5122 | $ans = $reply[$i]; |
||
| 5123 | Event::saveQuestionAttempt( |
||
| 5124 | $questionScore, |
||
| 5125 | $ans . ':' . $choice[$ans], |
||
| 5126 | $quesId, |
||
| 5127 | $exeId, |
||
| 5128 | $i, |
||
| 5129 | $this->id |
||
| 5130 | ); |
||
| 5131 | if ($debug) { |
||
| 5132 | error_log('result =>' . $questionScore . ' ' . $ans . ':' . $choice[$ans]); |
||
| 5133 | } |
||
| 5134 | } |
||
| 5135 | } else { |
||
| 5136 | Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); |
||
| 5137 | } |
||
| 5138 | } elseif ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) { |
||
| 5139 | if ($choice != 0) { |
||
| 5140 | $reply = array_keys($choice); |
||
| 5141 | |||
| 5142 | if ($debug) { |
||
| 5143 | error_log("reply " . print_r($reply, 1) . ""); |
||
| 5144 | } |
||
| 5145 | View Code Duplication | for ($i = 0; $i < sizeof($reply); $i++) { |
|
| 5146 | $ans = $reply[$i]; |
||
| 5147 | Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id); |
||
| 5148 | } |
||
| 5149 | } else { |
||
| 5150 | Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); |
||
| 5151 | } |
||
| 5152 | } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) { |
||
| 5153 | if ($choice != 0) { |
||
| 5154 | $reply = array_keys($choice); |
||
| 5155 | View Code Duplication | for ($i = 0; $i < sizeof($reply); $i++) { |
|
| 5156 | $ans = $reply[$i]; |
||
| 5157 | Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id); |
||
| 5158 | } |
||
| 5159 | } else { |
||
| 5160 | Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); |
||
| 5161 | } |
||
| 5162 | } elseif (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) { |
||
| 5163 | if (isset($matching)) { |
||
| 5164 | foreach ($matching as $j => $val) { |
||
| 5165 | Event::saveQuestionAttempt($questionScore, $val, $quesId, $exeId, $j, $this->id); |
||
| 5166 | } |
||
| 5167 | } |
||
| 5168 | } elseif ($answerType == FREE_ANSWER) { |
||
| 5169 | $answer = $choice; |
||
| 5170 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); |
||
| 5171 | } elseif ($answerType == ORAL_EXPRESSION) { |
||
| 5172 | $answer = $choice; |
||
| 5173 | Event::saveQuestionAttempt( |
||
| 5174 | $questionScore, |
||
| 5175 | $answer, |
||
| 5176 | $quesId, |
||
| 5177 | $exeId, |
||
| 5178 | 0, |
||
| 5179 | $this->id, |
||
| 5180 | false, |
||
| 5181 | $objQuestionTmp->getAbsoluteFilePath() |
||
| 5182 | ); |
||
| 5183 | } elseif (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION])) { |
||
| 5184 | $answer = $choice; |
||
| 5185 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); |
||
| 5186 | // } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) { |
||
| 5187 | } elseif ($answerType == HOT_SPOT) { |
||
| 5188 | $answer = []; |
||
| 5189 | if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) { |
||
| 5190 | Database::delete( |
||
| 5191 | Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT), |
||
| 5192 | [ |
||
| 5193 | 'hotspot_exe_id = ? AND hotspot_question_id = ? AND c_id = ?' => [ |
||
| 5194 | $exeId, |
||
| 5195 | $questionId, |
||
| 5196 | api_get_course_int_id() |
||
| 5197 | ] |
||
| 5198 | ] |
||
| 5199 | ); |
||
| 5200 | |||
| 5201 | foreach ($exerciseResultCoordinates[$questionId] as $idx => $val) { |
||
| 5202 | $answer[] = $val; |
||
| 5203 | $hotspotValue = (int) $choice[$idx] === 1 ? 1 : 0; |
||
| 5204 | Event::saveExerciseAttemptHotspot( |
||
| 5205 | $exeId, |
||
| 5206 | $quesId, |
||
| 5207 | $idx, |
||
| 5208 | $hotspotValue, |
||
| 5209 | $val, |
||
| 5210 | false, |
||
| 5211 | $this->id |
||
| 5212 | ); |
||
| 5213 | } |
||
| 5214 | } |
||
| 5215 | |||
| 5216 | Event::saveQuestionAttempt($questionScore, implode('|', $answer), $quesId, $exeId, 0, $this->id); |
||
| 5217 | } else { |
||
| 5218 | Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0,$this->id); |
||
| 5219 | } |
||
| 5220 | } |
||
| 5221 | |||
| 5222 | if ($propagate_neg == 0 && $questionScore < 0) { |
||
| 5223 | $questionScore = 0; |
||
| 5224 | } |
||
| 5225 | |||
| 5226 | if ($saved_results) { |
||
| 5227 | $stat_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES); |
||
| 5228 | $sql = 'UPDATE ' . $stat_table . ' SET |
||
| 5229 | exe_result = exe_result + ' . floatval($questionScore) . ' |
||
| 5230 | WHERE exe_id = ' . $exeId; |
||
| 5231 | Database::query($sql); |
||
| 5232 | } |
||
| 5233 | |||
| 5234 | $return_array = array( |
||
| 5235 | 'score' => $questionScore, |
||
| 5236 | 'weight' => $questionWeighting, |
||
| 5237 | 'extra' => $extra_data, |
||
| 5238 | 'open_question' => $arrques, |
||
| 5239 | 'open_answer' => $arrans, |
||
| 5240 | 'answer_type' => $answerType |
||
| 5241 | ); |
||
| 5242 | |||
| 5243 | return $return_array; |
||
| 5244 | } |
||
| 5245 | |||
| 5246 | /** |
||
| 5247 | * Sends a notification when a user ends an examn |
||
| 5248 | * |
||
| 5249 | * @param array $question_list_answers |
||
| 5250 | * @param string $origin |
||
| 5251 | * @param int $exe_id |
||
| 5252 | * @param float $score |
||
| 5253 | * @param float $weight |
||
| 5254 | * @return bool |
||
| 5255 | */ |
||
| 5256 | public function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id, $score, $weight) |
||
| 5351 | |||
| 5352 | /** |
||
| 5353 | * Sends a notification when a user ends an examn |
||
| 5354 | * |
||
| 5355 | * @param integer $exe_id |
||
| 5356 | */ |
||
| 5357 | public function send_notification_for_open_questions($question_list_answers, $origin, $exe_id) |
||
| 5452 | |||
| 5453 | function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id) |
||
| 5543 | |||
| 5544 | /** |
||
| 5545 | * @param array $user_data result of api_get_user_info() |
||
| 5546 | * @param string $start_date |
||
| 5547 | * @param null $duration |
||
| 5548 | * @param string $ip Optional. The user IP |
||
| 5549 | * @return string |
||
| 5550 | */ |
||
| 5551 | public function show_exercise_result_header($user_data, $start_date = null, $duration = null, $ip = null) |
||
| 5592 | |||
| 5593 | /** |
||
| 5594 | * Create a quiz from quiz data |
||
| 5595 | * @param string Title |
||
| 5596 | * @param int Time before it expires (in minutes) |
||
| 5597 | * @param int Type of exercise |
||
| 5598 | * @param int Whether it's randomly picked questions (1) or not (0) |
||
| 5599 | * @param int Whether the exercise is visible to the user (1) or not (0) |
||
| 5600 | * @param int Whether the results are show to the user (0) or not (1) |
||
| 5601 | * @param int Maximum number of attempts (0 if no limit) |
||
| 5602 | * @param int Feedback type |
||
| 5603 | * @todo this was function was added due the import exercise via CSV |
||
| 5604 | * @return int New exercise ID |
||
| 5605 | */ |
||
| 5606 | public function createExercise( |
||
| 5671 | |||
| 5672 | function process_geometry() |
||
| 5676 | |||
| 5677 | /** |
||
| 5678 | * Returns the exercise result |
||
| 5679 | * @param int attempt id |
||
| 5680 | * @return float exercise result |
||
| 5681 | */ |
||
| 5682 | public function get_exercise_result($exe_id) |
||
| 5719 | |||
| 5720 | /** |
||
| 5721 | * Checks if the exercise is visible due a lot of conditions |
||
| 5722 | * visibility, time limits, student attempts |
||
| 5723 | * Return associative array |
||
| 5724 | * value : true if execise visible |
||
| 5725 | * message : HTML formated message |
||
| 5726 | * rawMessage : text message |
||
| 5727 | * @param int $lpId |
||
| 5728 | * @param int $lpItemId |
||
| 5729 | * @param int $lpItemViewId |
||
| 5730 | * @param bool $filterByAdmin |
||
| 5731 | * @return array |
||
| 5732 | */ |
||
| 5733 | public function is_visible( |
||
| 5921 | |||
| 5922 | public function added_in_lp() |
||
| 5933 | |||
| 5934 | /** |
||
| 5935 | * Returns an array with the media list |
||
| 5936 | * @param array question list |
||
| 5937 | * @example there's 1 question with iid 5 that belongs to the media question with iid = 100 |
||
| 5938 | * <code> |
||
| 5939 | * array (size=2) |
||
| 5940 | * 999 => |
||
| 5941 | * array (size=3) |
||
| 5942 | * 0 => int 7 |
||
| 5943 | * 1 => int 6 |
||
| 5944 | * 2 => int 3254 |
||
| 5945 | * 100 => |
||
| 5946 | * array (size=1) |
||
| 5947 | * 0 => int 5 |
||
| 5948 | * </code> |
||
| 5949 | * @return array |
||
| 5950 | */ |
||
| 5951 | private function setMediaList($questionList) |
||
| 5969 | |||
| 5970 | /** |
||
| 5971 | * Returns an array with this form |
||
| 5972 | * @example |
||
| 5973 | * <code> |
||
| 5974 | * array (size=3) |
||
| 5975 | 999 => |
||
| 5976 | array (size=3) |
||
| 5977 | 0 => int 3422 |
||
| 5978 | 1 => int 3423 |
||
| 5979 | 2 => int 3424 |
||
| 5980 | 100 => |
||
| 5981 | array (size=2) |
||
| 5982 | 0 => int 3469 |
||
| 5983 | 1 => int 3470 |
||
| 5984 | 101 => |
||
| 5985 | array (size=1) |
||
| 5986 | 0 => int 3482 |
||
| 5987 | * </code> |
||
| 5988 | * The array inside the key 999 means the question list that belongs to the media id = 999, |
||
| 5989 | * this case is special because 999 means "no media". |
||
| 5990 | * @return array |
||
| 5991 | */ |
||
| 5992 | public function getMediaList() |
||
| 5996 | |||
| 5997 | /** |
||
| 5998 | * Is media question activated? |
||
| 5999 | * @return bool |
||
| 6000 | */ |
||
| 6001 | public function mediaIsActivated() |
||
| 6020 | |||
| 6021 | /** |
||
| 6022 | * Gets question list from the exercise |
||
| 6023 | * |
||
| 6024 | * @return array |
||
| 6025 | */ |
||
| 6026 | public function getQuestionList() |
||
| 6030 | |||
| 6031 | /** |
||
| 6032 | * Question list with medias compressed like this |
||
| 6033 | * @example |
||
| 6034 | * <code> |
||
| 6035 | * array( |
||
| 6036 | * question_id_1, |
||
| 6037 | * question_id_2, |
||
| 6038 | * media_id, <- this media id contains question ids |
||
| 6039 | * question_id_3, |
||
| 6040 | * ) |
||
| 6041 | * </code> |
||
| 6042 | * @return array |
||
| 6043 | */ |
||
| 6044 | public function getQuestionListWithMediasCompressed() |
||
| 6048 | |||
| 6049 | /** |
||
| 6050 | * Question list with medias uncompressed like this |
||
| 6051 | * @example |
||
| 6052 | * <code> |
||
| 6053 | * array( |
||
| 6054 | * question_id, |
||
| 6055 | * question_id, |
||
| 6056 | * question_id, <- belongs to a media id |
||
| 6057 | * question_id, <- belongs to a media id |
||
| 6058 | * question_id, |
||
| 6059 | * ) |
||
| 6060 | * </code> |
||
| 6061 | * @return array |
||
| 6062 | */ |
||
| 6063 | public function getQuestionListWithMediasUncompressed() |
||
| 6067 | |||
| 6068 | /** |
||
| 6069 | * Sets the question list when the exercise->read() is executed |
||
| 6070 | * @param bool $adminView Whether to view the set the list of *all* questions or just the normal student view |
||
| 6071 | */ |
||
| 6072 | public function setQuestionList($adminView = false) |
||
| 6082 | |||
| 6083 | /** |
||
| 6084 | * |
||
| 6085 | * @params array question list |
||
| 6086 | * @params bool expand or not question list (true show all questions, false show media question id instead of the question ids) |
||
| 6087 | * |
||
| 6088 | **/ |
||
| 6089 | View Code Duplication | public function transformQuestionListWithMedias($question_list, $expand_media_questions = false) |
|
| 6132 | |||
| 6133 | function get_validated_question_list() |
||
| 6195 | |||
| 6196 | function get_question_list($expand_media_questions = false) |
||
| 6202 | |||
| 6203 | View Code Duplication | function transform_question_list_with_medias($question_list, $expand_media_questions = false) |
|
| 6244 | |||
| 6245 | /** |
||
| 6246 | * @param int $exe_id |
||
| 6247 | * @return array|mixed |
||
| 6248 | */ |
||
| 6249 | public function get_stat_track_exercise_info_by_exe_id($exe_id) |
||
| 6279 | |||
| 6280 | public function edit_question_to_remind($exe_id, $question_id, $action = 'add') |
||
| 6327 | |||
| 6328 | public function fill_in_blank_answer_to_array($answer) |
||
| 6334 | |||
| 6335 | public function fill_in_blank_answer_to_string($answer) |
||
| 6356 | |||
| 6357 | function return_time_left_div() |
||
| 6373 | |||
| 6374 | function get_count_question_list() |
||
| 6384 | |||
| 6385 | function get_exercise_list_ordered() |
||
| 6386 | { |
||
| 6387 | $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER); |
||
| 6388 | $course_id = api_get_course_int_id(); |
||
| 6389 | $session_id = api_get_session_id(); |
||
| 6390 | $sql = "SELECT exercise_id, exercise_order |
||
| 6391 | FROM $table_exercise_order |
||
| 6392 | WHERE c_id = $course_id AND session_id = $session_id |
||
| 6393 | ORDER BY exercise_order"; |
||
| 6394 | $result = Database::query($sql); |
||
| 6395 | $list = array(); |
||
| 6396 | if (Database::num_rows($result)) { |
||
| 6397 | while ($row = Database::fetch_array($result, 'ASSOC')) { |
||
| 6398 | $list[$row['exercise_order']] = $row['exercise_id']; |
||
| 6399 | } |
||
| 6400 | } |
||
| 6401 | return $list; |
||
| 6402 | } |
||
| 6403 | |||
| 6404 | /** |
||
| 6405 | * Get categories added in the exercise--category matrix |
||
| 6406 | * @return bool |
||
| 6407 | */ |
||
| 6408 | public function get_categories_in_exercise() |
||
| 6425 | |||
| 6426 | /** |
||
| 6427 | * @param null $order |
||
| 6428 | * @return bool |
||
| 6429 | */ |
||
| 6430 | public function get_categories_with_name_in_exercise($order = null) |
||
| 6450 | |||
| 6451 | /** |
||
| 6452 | * Get total number of question that will be parsed when using the category/exercise |
||
| 6453 | */ |
||
| 6454 | View Code Duplication | public function getNumberQuestionExerciseCategory() |
|
| 6455 | { |
||
| 6456 | $table = Database::get_course_table(TABLE_QUIZ_REL_CATEGORY); |
||
| 6457 | if (!empty($this->id)) { |
||
| 6458 | $sql = "SELECT SUM(count_questions) count_questions |
||
| 6459 | FROM $table |
||
| 6460 | WHERE exercise_id = {$this->id} AND c_id = {$this->course_id}"; |
||
| 6461 | $result = Database::query($sql); |
||
| 6462 | if (Database::num_rows($result)) { |
||
| 6463 | $row = Database::fetch_array($result); |
||
| 6464 | return $row['count_questions']; |
||
| 6465 | } |
||
| 6466 | } |
||
| 6467 | return 0; |
||
| 6468 | } |
||
| 6469 | |||
| 6470 | /** |
||
| 6471 | * Save categories in the TABLE_QUIZ_REL_CATEGORY table |
||
| 6472 | * @param array $categories |
||
| 6473 | */ |
||
| 6474 | public function save_categories_in_exercise($categories) |
||
| 6494 | |||
| 6495 | /** |
||
| 6496 | * @param array $questionList |
||
| 6497 | * @param int $currentQuestion |
||
| 6498 | * @param array $conditions |
||
| 6499 | * @param string $link |
||
| 6500 | * @return string |
||
| 6501 | */ |
||
| 6502 | public function progressExercisePaginationBar($questionList, $currentQuestion, $conditions, $link) |
||
| 6550 | |||
| 6551 | |||
| 6552 | /** |
||
| 6553 | * Shows a list of numbers that represents the question to answer in a exercise |
||
| 6554 | * |
||
| 6555 | * @param array $categories |
||
| 6556 | * @param int $current |
||
| 6557 | * @param array $conditions |
||
| 6558 | * @param string $link |
||
| 6559 | * @return string |
||
| 6560 | */ |
||
| 6561 | public function progressExercisePaginationBarWithCategories( |
||
| 6684 | |||
| 6685 | /** |
||
| 6686 | * Renders a question list |
||
| 6687 | * |
||
| 6688 | * @param array $questionList (with media questions compressed) |
||
| 6689 | * @param int $currentQuestion |
||
| 6690 | * @param array $exerciseResult |
||
| 6691 | * @param array $attemptList |
||
| 6692 | * @param array $remindList |
||
| 6693 | */ |
||
| 6694 | public function renderQuestionList($questionList, $currentQuestion, $exerciseResult, $attemptList, $remindList) |
||
| 6787 | |||
| 6788 | /** |
||
| 6789 | * @param int $questionId |
||
| 6790 | * @param array $attemptList |
||
| 6791 | * @param array $remindList |
||
| 6792 | * @param int $i |
||
| 6793 | * @param int $current_question |
||
| 6794 | * @param array $questions_in_media |
||
| 6795 | * @param bool $last_question_in_media |
||
| 6796 | * @param array $realQuestionList |
||
| 6797 | * @param bool $generateJS |
||
| 6798 | * @return null |
||
| 6799 | */ |
||
| 6800 | public function renderQuestion( |
||
| 6927 | |||
| 6928 | /** |
||
| 6929 | * Shows a question |
||
| 6930 | * @param Question $objQuestionTmp |
||
| 6931 | * @param bool $only_questions if true only show the questions, no exercise title |
||
| 6932 | * @param bool $origin origin i.e = learnpath |
||
| 6933 | * @param string $current_item current item from the list of questions |
||
| 6934 | * @param bool $show_title |
||
| 6935 | * @param bool $freeze |
||
| 6936 | * @param array $user_choice |
||
| 6937 | * @param bool $show_comment |
||
| 6938 | * @param null $exercise_feedback |
||
| 6939 | * @param bool $show_answers |
||
| 6940 | * @param null $modelType |
||
| 6941 | * @param bool $categoryMinusOne |
||
| 6942 | * @return bool|null|string |
||
| 6943 | */ |
||
| 6944 | public function showQuestion( |
||
| 7826 | |||
| 7827 | /** |
||
| 7828 | * @param int $exeId |
||
| 7829 | * @return array |
||
| 7830 | */ |
||
| 7831 | public function returnQuestionListByAttempt($exeId) |
||
| 7835 | |||
| 7836 | /** |
||
| 7837 | * Display the exercise results |
||
| 7838 | * @param int $exe_id |
||
| 7839 | * @param bool $saveUserResult save users results (true) or just show the results (false) |
||
| 7840 | * @param bool $returnExerciseResult return array with exercise result info |
||
| 7841 | * @return mixed |
||
| 7842 | */ |
||
| 7843 | public function displayQuestionListByAttempt($exe_id, $saveUserResult = false, $returnExerciseResult = false) |
||
| 8107 | |||
| 8108 | /** |
||
| 8109 | * Returns an HTML ribbon to show on top of the exercise result, with |
||
| 8110 | * colouring depending on the success or failure of the student |
||
| 8111 | * @param integer $score |
||
| 8112 | * @param integer $weight |
||
| 8113 | * @param bool $check_pass_percentage |
||
| 8114 | * @return string |
||
| 8115 | */ |
||
| 8116 | public function get_question_ribbon($score, $weight, $check_pass_percentage = false) |
||
| 8153 | |||
| 8154 | /** |
||
| 8155 | * Returns an array of categories details for the questions of the current |
||
| 8156 | * exercise. |
||
| 8157 | * @return array |
||
| 8158 | */ |
||
| 8159 | public function getQuestionWithCategories() |
||
| 8185 | |||
| 8186 | /** |
||
| 8187 | * Calculate the max_score of the quiz, depending of question inside, and quiz advanced option |
||
| 8188 | */ |
||
| 8189 | public function get_max_score() |
||
| 8240 | |||
| 8241 | /** |
||
| 8242 | * @return string |
||
| 8243 | */ |
||
| 8244 | public function get_formated_title() |
||
| 8248 | |||
| 8249 | /** |
||
| 8250 | * @param $in_title |
||
| 8251 | * @return string |
||
| 8252 | */ |
||
| 8253 | public static function get_formated_title_variable($in_title) |
||
| 8257 | |||
| 8258 | /** |
||
| 8259 | * @return string |
||
| 8260 | */ |
||
| 8261 | public function format_title() |
||
| 8265 | |||
| 8266 | /** |
||
| 8267 | * @param $in_title |
||
| 8268 | * @return string |
||
| 8269 | */ |
||
| 8270 | public static function format_title_variable($in_title) |
||
| 8274 | |||
| 8275 | /** |
||
| 8276 | * @param int $courseId |
||
| 8277 | * @param int $sessionId |
||
| 8278 | * @return array exercises |
||
| 8279 | */ |
||
| 8280 | View Code Duplication | public function getExercisesByCouseSession($courseId, $sessionId) |
|
| 8303 | |||
| 8304 | /** |
||
| 8305 | * |
||
| 8306 | * @param int $courseId |
||
| 8307 | * @param int $sessionId |
||
| 8308 | * @param array $quizId |
||
| 8309 | * @return array exercises |
||
| 8310 | */ |
||
| 8311 | public function getExerciseAndResult($courseId, $sessionId, $quizId = array()) |
||
| 8350 | |||
| 8351 | /** |
||
| 8352 | * @param $exeId |
||
| 8353 | * @param $exercise_stat_info |
||
| 8354 | * @param $remindList |
||
| 8355 | * @param $currentQuestion |
||
| 8356 | * @return int|null |
||
| 8357 | */ |
||
| 8358 | public static function getNextQuestionId($exeId, $exercise_stat_info, $remindList, $currentQuestion) |
||
| 8429 | |||
| 8430 | /** |
||
| 8431 | * Gets the position of a questionId in the question list |
||
| 8432 | * @param $questionId |
||
| 8433 | * @return int |
||
| 8434 | */ |
||
| 8435 | public function getPositionInCompressedQuestionList($questionId) |
||
| 8458 | |||
| 8459 | /** |
||
| 8460 | * Get the correct answers in all attempts |
||
| 8461 | * @param int $learnPathId |
||
| 8462 | * @param int $learnPathItemId |
||
| 8463 | * @return array |
||
| 8464 | */ |
||
| 8465 | public function getCorrectAnswersInAllAttempts($learnPathId = 0, $learnPathItemId = 0) |
||
| 8512 | } |
||
| 8513 |
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.