Browse Source

Adding question extra field values in the "fast-jqgrid" question list (only for field_filter = 1)

Julio Montoya 11 years ago
parent
commit
4b7a62ca60

+ 16 - 1
main/exercice/exercise.class.php

@@ -540,7 +540,7 @@ class Exercise
      * @param string $sord
      * @param array $where_condition
      */
-    public function getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition = array())
+    public function getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition = array(), $extraFields = array())
     {
         if (!empty($this->id)) {
             $category_list = Testcategory::getListOfCategoriesNameForTest($this->id, false);
@@ -580,6 +580,9 @@ class Exercise
             $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')) {
                     $objQuestionTmp = Question::read($question['iid']);
                     $category_labels = Testcategory::return_category_labels($objQuestionTmp->category_list, $category_list);
@@ -607,6 +610,18 @@ class Exercise
                         '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;
                 }
             }

+ 35 - 9
main/exercice/question_list_pagination_admin.inc.php

@@ -34,7 +34,18 @@ $token = Security::get_token();
 $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_question_list&exerciseId='.$exerciseId;
 
 //The order is important you need to check the the $column variable in the model.ajax.php file
-$columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Difficulty'), get_lang('Score'), get_lang('Actions'));
+$columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Difficulty'), get_lang('Score'));
+//$columns = array(get_lang('Questions'), get_lang('Type'), get_lang('Category'), get_lang('Score'));
+
+// Adding filtered question extra fields
+$extraField = new ExtraField('question');
+$extraFields = $extraField->get_all(array('field_filter = ?' => 1));
+if (!empty($extraFields)) {
+    foreach ($extraFields as $field) {
+        $columns[] = $field['field_display_text'];
+    }
+}
+$columns[] = get_lang('Actions');
 
 //Column config
 $column_model = array(
@@ -66,17 +77,32 @@ $column_model = array(
         'width'    => '50',
         'align'    => 'left',
         'sortable' => 'false'
-    ),
-    array(
-        'name'      => 'actions',
-        'index'     => 'actions',
-        'width'     => '50',
-        'align'     => 'left',
-        'formatter' => 'action_formatter',
-        'sortable'  => 'false'
     )
 );
 
+if (!empty($extraFields)) {
+    foreach ($extraFields as $field) {
+        $column_model[] =
+        array(
+            'name'     => $field['field_variable'],
+            'index'    => $field['field_variable'],
+            'width'    => '100',
+            'align'    => 'left',
+            'sortable' => 'false'
+        );
+    }
+}
+
+$column_model[] = array(
+    'name'      => 'actions',
+    'index'     => 'actions',
+    'width'     => '50',
+    'align'     => 'left',
+    'formatter' => 'action_formatter',
+    'sortable'  => 'false'
+);
+
+
 
 //Autowidth
 $extra_params['autowidth'] = 'true';

+ 12 - 2
main/inc/ajax/model.ajax.php

@@ -316,8 +316,18 @@ switch ($action) {
         break;
     case 'get_question_list':
         if (isset($exercise) && !empty($exercise)) {
-            $columns = array('question', 'type', 'category', 'level', 'score', 'actions');
-            $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition);
+            $extraField = new ExtraField('question');
+            $extraFields = $extraField->get_all(array('field_filter = ?' => 1));
+
+            $columns = array('question', 'type', 'category', 'level', 'score');
+            if (!empty($extraFields)) {
+                foreach ($extraFields as $extraField) {
+                    $columns[] = $extraField['field_variable'];
+                }
+            }
+            $columns[] = 'actions';
+
+            $result = $exercise->getQuestionListPagination($start, $limit, $sidx, $sord, $where_condition, $extraFields);
         }
         break;
     case 'get_group_reporting':