/** * Returns a category summary report * @params int exercise id * @params array pre filled array with the category_id, score, and weight * example: array(1 => array('score' => '10', 'total' => 20)); */ public static function get_stats_table_by_attempt($exercise_id, $category_list = array()) { if (empty($category_list)) { return null; } $category_name_list = TestCategory::getListOfCategoriesNameForTest($exercise_id); $table = new HTML_Table(array('class' => 'data_table')); $table->setHeaderContents(0, 0, get_lang('Categories')); $table->setHeaderContents(0, 1, get_lang('AbsoluteScore')); $table->setHeaderContents(0, 2, get_lang('RelativeScore')); $row = 1; $none_category = array(); if (isset($category_list['none'])) { $none_category = $category_list['none']; unset($category_list['none']); } $total = array(); if (isset($category_list['total'])) { $total = $category_list['total']; unset($category_list['total']); } if (count($category_list) > 1) { foreach ($category_list as $category_id => $category_item) { $table->setCellContents($row, 0, $category_name_list[$category_id]); $table->setCellContents($row, 1, ExerciseLib::show_score($category_item['score'], $category_item['total'], false)); $table->setCellContents($row, 2, ExerciseLib::show_score($category_item['score'], $category_item['total'], true, false, true)); $row++; } if (!empty($none_category)) { $table->setCellContents($row, 0, get_lang('None')); $table->setCellContents($row, 1, ExerciseLib::show_score($none_category['score'], $none_category['total'], false)); $table->setCellContents($row, 2, ExerciseLib::show_score($none_category['score'], $none_category['total'], true, false, true)); $row++; } if (!empty($total)) { $table->setCellContents($row, 0, get_lang('Total')); $table->setCellContents($row, 1, ExerciseLib::show_score($total['score'], $total['total'], false)); $table->setCellContents($row, 2, ExerciseLib::show_score($total['score'], $total['total'], true, false, true)); } return $table->toHtml(); } return null; }
//$questionList = $objExercise->selectQuestionList(true); $objExercise->setCategoriesGrouping(false); // Show exercises as in category settings //$questionList = $objExercise->getQuestionListWithMediasUncompressed(); // Show all questions no matter the category settings. $tempCategoryOrder = $objExercise->specialCategoryOrders; $objExercise->specialCategoryOrders = false; $questionList = $objExercise->selectQuestionList(true); $objExercise->specialCategoryOrders = $tempCategoryOrder; // Style for columns $styleQuestion = "width:50%; float:left; margin-left: 25px;"; $styleType = "width:4%; float:left; text-align:center;"; $styleCat = "width:22%; float:left; text-align:center;"; $styleLevel = "width:6%; float:left; text-align:center;"; $styleScore = "width:4%; float:left; text-align:center;"; $category_list = TestCategory::getListOfCategoriesNameForTest($objExercise->id, false); if (is_array($questionList)) { foreach ($questionList as $id) { //To avoid warning messages if (!is_numeric($id)) { continue; } /** @var Question $objQuestionTmp */ $objQuestionTmp = Question::read($id); $question_class = get_class($objQuestionTmp); $clone_link = '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&clone_question=' . $id . '">' . Display::return_icon('cd.gif', get_lang('Copy'), array(), ICON_SIZE_SMALL) . '</a>'; $edit_link = $objQuestionTmp->type == CALCULATED_ANSWER && $objQuestionTmp->isAnswered() ? '<a>' . Display::return_icon('edit_na.png', get_lang('QuestionEditionNotAvailableBecauseItIsAlreadyAnsweredHoweverYouCanCopyItAndModifyTheCopy'), array(), ICON_SIZE_SMALL) . '</a>' : '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&type=' . $objQuestionTmp->selectType() . '&myid=1&editQuestion=' . $id . '">' . Display::return_icon('edit.png', get_lang('Modify'), array(), ICON_SIZE_SMALL) . '</a>'; $delete_link = null; if ($objExercise->edit_exercise_in_lp == true) { $delete_link = '<a id="delete_' . $id . '" class="opener" href="' . api_get_self() . '?' . api_get_cidreq() . '&exerciseId=' . $exerciseId . '&deleteQuestion=' . $id . '" >' . Display::return_icon('delete.png', get_lang('RemoveFromTest'), array(), ICON_SIZE_SMALL) . '</a>'; }
/** * * @param int $start * @param int $limit * @param int $sidx * @param string $sord * @param array $where_condition * @param array $extraFields */ public function getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition = array(), $extraFields = array()) { if (!empty($this->id)) { $category_list = TestCategory::getListOfCategoriesNameForTest($this->id, false); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $sql = "SELECT q.iid\n FROM {$TBL_EXERCICE_QUESTION} e INNER JOIN {$TBL_QUESTIONS} q\n ON (e.question_id = q.iid AND e.c_id = " . $this->course_id . " )\n\t\t\t\t\tWHERE e.exercice_id\t= '" . Database::escape_string($this->id) . "'\n\t\t\t\t\t"; $orderCondition = "ORDER BY question_order"; if (!empty($sidx) && !empty($sord)) { if ($sidx == 'question') { if (in_array(strtolower($sord), array('desc', 'asc'))) { $orderCondition = " ORDER BY q.{$sidx} {$sord}"; } } } $sql .= $orderCondition; $limitCondition = null; if (isset($start) && isset($limit)) { $start = intval($start); $limit = intval($limit); $limitCondition = " LIMIT {$start}, {$limit}"; } $sql .= $limitCondition; $result = Database::query($sql); $questions = array(); if (Database::num_rows($result)) { if (!empty($extraFields)) { $extraFieldValue = new ExtraFieldValue('question'); } while ($question = Database::fetch_array($result, 'ASSOC')) { /** @var Question $objQuestionTmp */ $objQuestionTmp = Question::read($question['iid']); $category_labels = TestCategory::return_category_labels($objQuestionTmp->category_list, $category_list); if (empty($category_labels)) { $category_labels = "-"; } // Question type list($typeImg, $typeExpl) = $objQuestionTmp->get_type_icon_html(); $question_media = null; if (!empty($objQuestionTmp->parent_id)) { $objQuestionMedia = Question::read($objQuestionTmp->parent_id); $question_media = Question::getMediaLabel($objQuestionMedia->question); } $questionType = Display::tag('div', Display::return_icon($typeImg, $typeExpl, array(), ICON_SIZE_MEDIUM) . $question_media); $question = array('id' => $question['iid'], 'question' => $objQuestionTmp->selectTitle(), 'type' => $questionType, 'category' => Display::tag('div', '<a href="#" style="padding:0px; margin:0px;">' . $category_labels . '</a>'), 'score' => $objQuestionTmp->selectWeighting(), 'level' => $objQuestionTmp->level); if (!empty($extraFields)) { foreach ($extraFields as $extraField) { $value = $extraFieldValue->get_values_by_handler_and_field_id($question['id'], $extraField['id']); $stringValue = null; if ($value) { $stringValue = $value['field_value']; } $question[$extraField['field_variable']] = $stringValue; } } $questions[] = $question; } } return $questions; } }