Esempio n. 1
0
 /**
  * Returns a category summary report
  *
  * @param int exercise id
  * @param array prefilled array with the category_id, score, and weight example: array(1 => array('score' => '10', 'total' => 20));
  * @param bool $categoryMinusOne shows category - 1 see BT#6540
  * @return string
  */
 public static function get_stats_table_by_attempt($exercise_id, $category_list = array(), $categoryMinusOne = false)
 {
     if (empty($category_list)) {
         return null;
     }
     $category_name_list = Testcategory::getListOfCategoriesNameForTest($exercise_id, false);
     $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']);
     }
     $em = Database::getManager();
     $repo = $em->getRepository('ChamiloCoreBundle:CQuizCategory');
     $redefineCategoryList = array();
     if (!empty($category_list) && count($category_list) > 1) {
         $globalCategoryScore = array();
         foreach ($category_list as $category_id => $category_item) {
             $cat = $em->find('ChamiloCoreBundle:CQuizCategory', $category_id);
             $path = $repo->getPath($cat);
             $categoryName = $category_name_list[$category_id];
             $index = 0;
             if ($categoryMinusOne) {
                 $index = 1;
             }
             if (isset($path[$index])) {
                 $category_id = $path[$index]->getIid();
                 $categoryName = $path[$index]->getTitle();
             }
             if (!isset($globalCategoryScore[$category_id])) {
                 $globalCategoryScore[$category_id] = array();
                 $globalCategoryScore[$category_id]['score'] = 0;
                 $globalCategoryScore[$category_id]['total'] = 0;
                 $globalCategoryScore[$category_id]['title'] = '';
             }
             $globalCategoryScore[$category_id]['score'] += $category_item['score'];
             $globalCategoryScore[$category_id]['total'] += $category_item['total'];
             $globalCategoryScore[$category_id]['title'] = $categoryName;
         }
         foreach ($globalCategoryScore as $category_item) {
             $table->setCellContents($row, 0, $category_item['title']);
             $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));
             $class = 'class="row_odd"';
             if ($row % 2) {
                 $class = 'class="row_even"';
             }
             $table->setRowAttributes($row, $class, 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));
             $table->setRowAttributes($row, 'class="row_total"', true);
         }
         return $table->toHtml();
     }
     return null;
 }
 /**
  *
  * @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);
         //$category_list = Testcategory::getListOfCategoriesIDForTestObject($this);
         $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;
     }
 }
 echo "<div style='font-weight:bold; width:6%; float:left; padding:10px 0px; text-align:center;'>" . get_lang('Difficulty') . "</div>";
 echo "<div style='font-weight:bold; width:4%; float:left; padding:10px 0px; text-align:center;'>" . get_lang('Score') . "</div>";
 echo "</div>";
 echo "<div style='clear:both'>&nbsp;</div>";
 echo '<div id="question_list">';
 if ($nbrQuestions) {
     // Always getting list from DB.
     $objExercise->setCategoriesGrouping(false);
     $questionList = $objExercise->getQuestionListWithMediasUncompressed();
     // Style for columns.
     $styleQuestion = "width:50%; float:left;";
     $styleType = "width:4%; float:left; padding-top:4px; text-align:center;";
     $styleCat = "width:22%; float:left; padding-top:8px; text-align:center;";
     $styleLevel = "width:6%; float:left; padding-top:8px; text-align:center;";
     $styleScore = "width:4%; float:left; padding-top:8px; 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 = '<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>';
             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>';
             }
             $edit_link = Display::tag('div', $edit_link, array('style' => 'float:left; padding:0px; margin:0px'));
 /**
  * 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, show_score($category_item['score'], $category_item['total'], false));
             $table->setCellContents($row, 2, 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, show_score($none_category['score'], $none_category['total'], false));
             $table->setCellContents($row, 2, 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, show_score($total['score'], $total['total'], false));
             $table->setCellContents($row, 2, show_score($total['score'], $total['total'], true, false, true));
         }
         return $table->toHtml();
     }
     return null;
 }