Explorar o código

Improving exercise question pagination by categories see BT#5635

Julio Montoya %!s(int64=12) %!d(string=hai) anos
pai
achega
69e70fadf0

+ 4 - 0
main/css/base.css

@@ -5266,4 +5266,8 @@ i.size-32.icon-new-work {
 .data_table .row_total {
     background-color: #555;
     color:white;
+}
+
+.exercise_pagination {
+    margin: 0px;
 }

+ 2 - 0
main/exercice/exercise_result.php

@@ -161,6 +161,7 @@ if ($origin != 'learnpath') {
     if (api_is_allowed_to_session_edit()) {
         Session::erase('objExercise');
         Session::erase('exe_id');
+        Session::erase('categoryList');
     }
 
     Display::display_footer();
@@ -172,6 +173,7 @@ if ($origin != 'learnpath') {
     if (api_is_allowed_to_session_edit()) {
         Session::erase('objExercise');
         Session::erase('exe_id');
+        Session::erase('categoryList');
     }
     //record the results in the learning path, using the SCORM interface (API)
     echo "<script>window.parent.API.void_save_asset('$total_score', '$total_weight', 0, 'completed');</script>";

+ 16 - 1
main/exercice/exercise_submit.php

@@ -888,7 +888,22 @@ if ($objExercise->type == ONE_PER_PAGE) {
         $values = array_flip($questionList);
         $current_question = isset($values[$remind_question_id]) ? $values[$remind_question_id] + 1 : $values[$fixedRemindList[0]] +1;
     }
-    echo Display::progress_pagination_bar($questionList, $current_question, $conditions, $link);
+
+    $categoryList = Session::read('categoryList');
+
+    if (empty($categoryList)) {
+        $categoryList = Testcategory::getListOfCategoriesWithQuestionForTestObject($objExercise);
+        Session::write('categoryList', $categoryList);
+    }
+
+    if (!empty($categoryList)) {
+        echo Display::progress_pagination_bar_with_categories($categoryList, $current_question, $conditions, $link);
+    } else {
+        echo Display::progress_pagination_bar($questionList, $current_question, $conditions, $link);
+    }
+
+    //echo Display::progress_pagination_bar($questionList, $current_question, $conditions, $link);
+
     echo Display::label(get_lang('Answered'), 'success').' '.Display::label(get_lang('Unanswered')).' '.Display::label(get_lang('ToReview'), 'warning').' '.Display::label(get_lang('CurrentQuestion'), 'info');
     //var_dump($category_list);
 }

+ 50 - 0
main/exercice/testcategory.class.php

@@ -526,6 +526,56 @@ class Testcategory
 		return $categories_in_exercise;
 	}
 
+
+    public static function getListOfCategoriesWithQuestionForTestObject($exercise_obj) {
+        $question_list = $exercise_obj->selectQuestionList();
+        $categoriesWithQuestion = array();
+        $parentsLoaded = array();
+        global $app;
+        $em = $app['orm.em'];
+        $repo = $em->getRepository('Entity\CQuizCategory');
+
+        // the array given by selectQuestionList start at indice 1 and not at indice 0 !!! ???
+        foreach ($question_list as $question_id) {
+            $category_list = Testcategory::getCategoryForQuestion($question_id);
+            foreach ($category_list as $categoryId) {
+                if (!isset($categoriesWithQuestion[$categoryId])) {
+                    $cat = new Testcategory($categoryId);
+                    $cat = (array)$cat;
+                    $cat['iid'] = $cat['id'];
+                    $cat['name'] = $cat['title'];
+                    if (!empty($cat['parent_id'])) {
+                        if (!isset($parentsLoaded[$cat['parent_id']])) {
+                            $categoryEntity = $em->find('Entity\CQuizCategory', $cat['parent_id']);
+                            $parentsLoaded[$cat['parent_id']] = $categoryEntity;
+                        } else {
+                            $categoryEntity = $parentsLoaded[$cat['parent_id']];
+                        }
+                        $path = $repo->getPath($categoryEntity);
+                        if (isset($path) && isset($path[0])) {
+                            $categoryId = $path[0]->getIid();
+                            $cat['id'] = $categoryId;
+                            $cat['iid'] = $categoryId;
+                            $cat['parent_path'] = null;
+                            $cat['title'] = $path[0]->getTitle();
+                            $cat['name'] = $path[0]->getTitle();
+                            $cat['parent_id'] = null;
+                        }
+                        $temp = isset($categoriesWithQuestion[$categoryId]) ? $categoriesWithQuestion[$categoryId]['question_list'] : array();
+                        $categoriesWithQuestion[$categoryId] = $cat;
+                        $categoriesWithQuestion[$categoryId]['question_list'] = $temp;
+                    } else {
+                        $categoriesWithQuestion[$categoryId] = $cat;
+                    }
+                }
+                $categoriesWithQuestion[$categoryId]['question_list'][] = $question_id;
+            }
+        }
+
+        return $categoriesWithQuestion;
+    }
+
+
     /**
 	 * return the list of differents categories NAME for a test
 	 * input : test_id

+ 54 - 5
main/inc/lib/display.lib.php

@@ -1719,24 +1719,38 @@ class Display
         return $html;
     }
 
-    static function progress_pagination_bar($list, $current, $conditions = array(), $link = null)
+    /**
+     *
+     * @param array $list
+     * @param int $current
+     * @param array $conditions
+     * @param string $link
+     * @return string
+     */
+    static function progress_pagination_bar($list, $current, $conditions = array(), $link = null, $counter = null)
     {
-        $counter = 1;
+        if (empty($counter)) {
+            $counter = 1;
+        }
+
         $pagination_size = '';
         $total = count($list);
-        if ($total > 25) {
+        /*if ($total > 25) {
             $pagination_size = 'pagination-small';
         }
         if ($total > 50) {
             $pagination_size = 'pagination-mini';
         }
-        $html = '<div class="pagination '.$pagination_size.' pagination-centered"><ul>';
+        */
+        $pagination_size = 'pagination-mini';
 
+        //$html = '<div class="exercise_pagination pagination '.$pagination_size.' pagination-centered"><ul>';
+        $html = '<div class="exercise_pagination pagination '.$pagination_size.'"><ul>';
         foreach ($list as $item_id) {
             $class = "active";
 
             if ($counter < $current) {
-            //    $class = "before";
+                //    $class = "before";
             }
             $class = "before";
 
@@ -1779,6 +1793,41 @@ class Display
         return $html;
     }
 
+    /**
+     * @param $categories
+     * @param $list
+     * @param $current
+     * @param array $conditions
+     * @param null $link
+     * @return null|string
+     */
+    static function progress_pagination_bar_with_categories($categories, $current, $conditions = array(), $link = null)
+    {
+        $counter = 0;
+        $totalTemp = 0;
+        $html = null;
+        foreach ($categories as $category) {
+            $list = $category['question_list'];
+
+            if ($counter > 0) {
+                $total = $totalTemp + 1;
+            } else {
+                $total = 0;
+            }
+            $html .= '<div class="row">';
+            $html .= '<div class="span2">'.$category['name'].'</div>';
+            $html .= '<div class="span10">';
+            $html .= self::progress_pagination_bar($list, $current, $conditions, $link, $total);
+            $html .= '</div>';
+            $html .= '</div>';
+
+            $totalTemp = $totalTemp + count($list);
+            $counter++;
+        }
+
+        return $html;
+    }
+
     /**
      * @param int $current
      * @param int $total