From 1de8064eb4b24f4ac4377526ca49e67fb662f73d Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 8 May 2013 13:23:53 +0200 Subject: [PATCH] Adding extra field filters for the new question global list see BT#6042 --- main/exercice/question.class.php | 106 +++- main/exercice/unique_answer.class.php | 46 +- main/inc/Entity/CQuizQuestion.php | 6 + main/inc/Entity/ExtraField.php | 303 ++++++++++++ main/inc/Entity/ExtraFieldValues.php | 145 ++++++ main/inc/Entity/QuestionField.php | 16 + main/inc/Entity/QuestionFieldOptions.php | 184 +++++++ main/inc/Entity/QuestionFieldValues.php | 57 +++ .../Repository/CQuizQuestionRepository.php | 12 +- main/inc/ajax/model.ajax.php | 107 ++--- main/inc/lib/display.lib.php | 3 +- main/inc/lib/extra_field.lib.php | 452 +++++++++++++++--- main/inc/lib/extra_field_option.lib.php | 3 + main/inc/lib/sessionmanager.lib.php | 131 +---- main/session/session_list.php | 5 +- .../questionmanager/question_categories.tpl | 7 +- .../admin/questionmanager/questions.tpl | 122 ++++- .../QuestionManagerController.php | 109 ++--- 18 files changed, 1464 insertions(+), 350 deletions(-) create mode 100644 main/inc/Entity/ExtraField.php create mode 100644 main/inc/Entity/ExtraFieldValues.php create mode 100644 main/inc/Entity/QuestionField.php create mode 100644 main/inc/Entity/QuestionFieldOptions.php create mode 100644 main/inc/Entity/QuestionFieldValues.php diff --git a/main/exercice/question.class.php b/main/exercice/question.class.php index 52dd9f640e..1fe0514fe7 100644 --- a/main/exercice/question.class.php +++ b/main/exercice/question.class.php @@ -1940,7 +1940,7 @@ abstract class Question return $html; } - static function question_type_no_review() + public static function question_type_no_review() { return array( HOT_SPOT, @@ -1949,7 +1949,8 @@ abstract class Question ); } - public static function getMediaLabels() { + public static function getMediaLabels() + { // Shows media questions $courseMedias = Question::prepare_course_media_select(api_get_course_int_id()); @@ -1965,4 +1966,105 @@ abstract class Question return $labels; } + + public static function getQuestionColumns() + { + // The order is important you need to check the the $column variable in the model.ajax.php file + $columns = array('id', get_lang('Name'), get_lang('Description')); + + // Column config. + $columnModel = array( + array( + 'name' => 'iid', + 'index' => 'iid', + 'width' => '20', + 'align' => 'left' + ), + array( + 'name' => 'question', + 'index' => 'question', + 'width' => '200', + 'align' => 'left' + ), + array( + 'name' => 'description', + 'index' => 'description', + 'width' => '100', + 'align' => 'left', + 'sortable' => 'false' + ) + ); + $extraField = new \ExtraField('question'); + $rules = $extraField->getRules($columns, $columnModel); + + $columns[] = get_lang('Actions'); + + $columnModel[] = array( + 'name' => 'actions', + 'index' => 'actions', + 'width' => '30', + 'align' => 'left', + 'formatter' => 'action_formatter', + 'sortable' => 'false' + ); + + foreach ($columnModel as $col_model) { + $simple_column_name[] = $col_model['name']; + } + + $return_array = array( + 'columns' => $columns, + 'column_model' => $columnModel, + 'rules' => $rules, + 'simple_column_name' => $simple_column_name + ); + + return $return_array; + } + + /** + * Get all questions + * @param $options + * @return array + */ + public static function getQuestions($categoryId, $options, $get_count = false) + { + $questionTable = Database::get_course_table(TABLE_QUIZ_QUESTION); + $where = 'WHERE 1 = 1 '; + + $extra_field = new ExtraField('question'); + $conditions = $extra_field->parseConditions($options); + $inject_joins = $conditions['inject_joins']; + $where .= $conditions['where']; + $inject_where = $conditions['inject_where']; + $inject_extra_fields = $conditions['inject_extra_fields']; + $order = $conditions['order']; + $limit = $conditions['limit']; + + if ($get_count == true) { + $select = " SELECT count(*) as total_rows"; + } else { + $select = " SELECT s.*, $inject_extra_fields 1"; + } + $categoryCondition = null; + if (!empty($categoryId)) { + $categoryRelQuestionTable = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); + $categoryCondition = " INNER JOIN $categoryRelQuestionTable c ON (s.iid = c.question_id)"; + $categoryId = intval($categoryId); + $where .= " AND category_id = $categoryId "; + } + + $query = " $select FROM $questionTable s $inject_joins $categoryCondition $where $inject_where $order $limit"; + + $result = Database::query($query); + $questions = array(); + if (Database::num_rows($result)) { + $questions = Database::store_result($result, 'ASSOC'); + if ($get_count) { + return $questions[0]['total_rows']; + } + } + return $questions; + + } } diff --git a/main/exercice/unique_answer.class.php b/main/exercice/unique_answer.class.php index 1b9043507f..a67e2a38ee 100644 --- a/main/exercice/unique_answer.class.php +++ b/main/exercice/unique_answer.class.php @@ -143,37 +143,43 @@ class UniqueAnswer extends Question for ($i = 1; $i <= $nb_answers; ++$i) { $form->addElement('html', ''); if (isset($answer) && is_object($answer)) { + $answer_id = $answer->getRealAnswerIdFromList($i); if ($answer->correct[$answer_id]) { $correct = $i; } + $defaults['answer['.$i.']'] = $answer->answer[$answer_id]; $defaults['comment['.$i.']'] = $answer->comment[$answer_id]; $defaults['weighting['.$i.']'] = Text::float_format($answer->weighting[$answer_id], 1); - $item_list = explode('@@', $answer->destination[$answer_id]); - - $try = $item_list[0]; - $lp = $item_list[1]; - $list_dest = $item_list[2]; - $url = $item_list[3]; - - if ($try == 0) { - $try_result = 0; - } else { - $try_result = 1; - } - if ($url == 0) { - $url_result = ''; - } else { - $url_result = $url; + if (!empty($answer->destination[$answer_id])) { + $item_list = explode('@@', $answer->destination[$answer_id]); + $try = $item_list[0]; + $lp = $item_list[1]; + $list_dest = $item_list[2]; + $url = $item_list[3]; + + if ($try == 0) { + $try_result = 0; + } else { + $try_result = 1; + } + + if ($url == 0) { + $url_result = ''; + } else { + $url_result = $url; + } + + $temp_scenario['url'.$i] = $url_result; + $temp_scenario['try'.$i] = $try_result; + $temp_scenario['lp'.$i] = $lp; + $temp_scenario['destination'.$i] = $list_dest; } - $temp_scenario['url'.$i] = $url_result; - $temp_scenario['try'.$i] = $try_result; - $temp_scenario['lp'.$i] = $lp; - $temp_scenario['destination'.$i] = $list_dest; + } else { $defaults['answer[1]'] = get_lang('DefaultUniqueAnswer1'); $defaults['weighting[1]'] = 10; diff --git a/main/inc/Entity/CQuizQuestion.php b/main/inc/Entity/CQuizQuestion.php index 6c8ef3a79c..76eaf7af53 100644 --- a/main/inc/Entity/CQuizQuestion.php +++ b/main/inc/Entity/CQuizQuestion.php @@ -106,9 +106,15 @@ class CQuizQuestion **/ private $quizQuestionRelCategoryList; + /** + * @ORM\OneToMany(targetEntity="QuestionFieldValues", mappedBy="question") + */ + private $extraFields; + public function __construct() { $this->quizQuestionRelCategoryList = new ArrayCollection(); + $this->extraFields = new ArrayCollection(); } public function getCategories() diff --git a/main/inc/Entity/ExtraField.php b/main/inc/Entity/ExtraField.php new file mode 100644 index 0000000000..aab172dff5 --- /dev/null +++ b/main/inc/Entity/ExtraField.php @@ -0,0 +1,303 @@ +id; + } + + /** + * Set fieldType + * + * @param integer $fieldType + * @return ExtraField + */ + public function setFieldType($fieldType) + { + $this->fieldType = $fieldType; + + return $this; + } + + /** + * Get fieldType + * + * @return integer + */ + public function getFieldType() + { + return $this->fieldType; + } + + /** + * Set fieldVariable + * + * @param string $fieldVariable + * @return ExtraField + */ + public function setFieldVariable($fieldVariable) + { + $this->fieldVariable = $fieldVariable; + + return $this; + } + + /** + * Get fieldVariable + * + * @return string + */ + public function getFieldVariable() + { + return $this->fieldVariable; + } + + /** + * Set fieldDisplayText + * + * @param string $fieldDisplayText + * @return ExtraField + */ + public function setFieldDisplayText($fieldDisplayText) + { + $this->fieldDisplayText = $fieldDisplayText; + + return $this; + } + + /** + * Get fieldDisplayText + * + * @return string + */ + public function getFieldDisplayText() + { + return $this->fieldDisplayText; + } + + /** + * Set fieldDefaultValue + * + * @param string $fieldDefaultValue + * @return ExtraField + */ + public function setFieldDefaultValue($fieldDefaultValue) + { + $this->fieldDefaultValue = $fieldDefaultValue; + + return $this; + } + + /** + * Get fieldDefaultValue + * + * @return string + */ + public function getFieldDefaultValue() + { + return $this->fieldDefaultValue; + } + + /** + * Set fieldOrder + * + * @param integer $fieldOrder + * @return ExtraField + */ + public function setFieldOrder($fieldOrder) + { + $this->fieldOrder = $fieldOrder; + + return $this; + } + + /** + * Get fieldOrder + * + * @return integer + */ + public function getFieldOrder() + { + return $this->fieldOrder; + } + + /** + * Set fieldVisible + * + * @param boolean $fieldVisible + * @return ExtraField + */ + public function setFieldVisible($fieldVisible) + { + $this->fieldVisible = $fieldVisible; + + return $this; + } + + /** + * Get fieldVisible + * + * @return boolean + */ + public function getFieldVisible() + { + return $this->fieldVisible; + } + + /** + * Set fieldChangeable + * + * @param boolean $fieldChangeable + * @return ExtraField + */ + public function setFieldChangeable($fieldChangeable) + { + $this->fieldChangeable = $fieldChangeable; + + return $this; + } + + /** + * Get fieldChangeable + * + * @return boolean + */ + public function getFieldChangeable() + { + return $this->fieldChangeable; + } + + /** + * Set fieldFilter + * + * @param boolean $fieldFilter + * @return ExtraField + */ + public function setFieldFilter($fieldFilter) + { + $this->fieldFilter = $fieldFilter; + + return $this; + } + + /** + * Get fieldFilter + * + * @return boolean + */ + public function getFieldFilter() + { + return $this->fieldFilter; + } + + /** + * Set tms + * + * @param \DateTime $tms + * @return ExtraField + */ + public function setTms($tms) + { + $this->tms = $tms; + + return $this; + } + + /** + * Get tms + * + * @return \DateTime + */ + public function getTms() + { + return $this->tms; + } +} diff --git a/main/inc/Entity/ExtraFieldValues.php b/main/inc/Entity/ExtraFieldValues.php new file mode 100644 index 0000000000..682fa3c260 --- /dev/null +++ b/main/inc/Entity/ExtraFieldValues.php @@ -0,0 +1,145 @@ +id; + } + + /** + * Set questionId + * + * @param integer $questionId + * @return ExtraFieldValues + */ + public function setQuestionId($questionId) + { + $this->questionId = $questionId; + + return $this; + } + + /** + * Get questionId + * + * @return integer + */ + public function getQuestionId() + { + return $this->questionId; + } + + /** + * Set fieldId + * + * @param integer $fieldId + * @return ExtraFieldValues + */ + public function setFieldId($fieldId) + { + $this->fieldId = $fieldId; + + return $this; + } + + /** + * Get fieldId + * + * @return integer + */ + public function getFieldId() + { + return $this->fieldId; + } + + /** + * Set fieldValue + * + * @param string $fieldValue + * @return ExtraFieldValues + */ + public function setFieldValue($fieldValue) + { + $this->fieldValue = $fieldValue; + + return $this; + } + + /** + * Get fieldValue + * + * @return string + */ + public function getFieldValue() + { + return $this->fieldValue; + } + + /** + * Set tms + * + * @param \DateTime $tms + * @return ExtraFieldValues + */ + public function setTms($tms) + { + $this->tms = $tms; + + return $this; + } + + /** + * Get tms + * + * @return \DateTime + */ + public function getTms() + { + return $this->tms; + } +} diff --git a/main/inc/Entity/QuestionField.php b/main/inc/Entity/QuestionField.php new file mode 100644 index 0000000000..889abaa4af --- /dev/null +++ b/main/inc/Entity/QuestionField.php @@ -0,0 +1,16 @@ +id; + } + + /** + * Set fieldId + * + * @param integer $fieldId + * @return SessionFieldOptions + */ + public function setFieldId($fieldId) + { + $this->fieldId = $fieldId; + + return $this; + } + + /** + * Get fieldId + * + * @return integer + */ + public function getFieldId() + { + return $this->fieldId; + } + + /** + * Set optionValue + * + * @param string $optionValue + * @return SessionFieldOptions + */ + public function setOptionValue($optionValue) + { + $this->optionValue = $optionValue; + + return $this; + } + + /** + * Get optionValue + * + * @return string + */ + public function getOptionValue() + { + return $this->optionValue; + } + + /** + * Set optionDisplayText + * + * @param string $optionDisplayText + * @return SessionFieldOptions + */ + public function setOptionDisplayText($optionDisplayText) + { + $this->optionDisplayText = $optionDisplayText; + + return $this; + } + + /** + * Get optionDisplayText + * + * @return string + */ + public function getOptionDisplayText() + { + return $this->optionDisplayText; + } + + /** + * Set optionOrder + * + * @param integer $optionOrder + * @return SessionFieldOptions + */ + public function setOptionOrder($optionOrder) + { + $this->optionOrder = $optionOrder; + + return $this; + } + + /** + * Get optionOrder + * + * @return integer + */ + public function getOptionOrder() + { + return $this->optionOrder; + } + + /** + * Set tms + * + * @param \DateTime $tms + * @return SessionFieldOptions + */ + public function setTms($tms) + { + $this->tms = $tms; + + return $this; + } + + /** + * Get tms + * + * @return \DateTime + */ + public function getTms() + { + return $this->tms; + } +} diff --git a/main/inc/Entity/QuestionFieldValues.php b/main/inc/Entity/QuestionFieldValues.php new file mode 100644 index 0000000000..80641f446e --- /dev/null +++ b/main/inc/Entity/QuestionFieldValues.php @@ -0,0 +1,57 @@ +questionId = $questionId; + + return $this; + } + + /** + * Get questionId + * + * @return integer + */ + public function getQuestionId() + { + return $this->questionId; + } +} diff --git a/main/inc/Entity/Repository/CQuizQuestionRepository.php b/main/inc/Entity/Repository/CQuizQuestionRepository.php index c915b4d66f..5a40f0cc2f 100644 --- a/main/inc/Entity/Repository/CQuizQuestionRepository.php +++ b/main/inc/Entity/Repository/CQuizQuestionRepository.php @@ -19,19 +19,23 @@ class CQuizQuestionRepository extends EntityRepository */ public function getQuestionsByCategory($categoryId) { - // Setting alias for this class "q" = CQuizQuestion + // Setting alias for this class "q" = CQuizQuestion. $qb = $this->createQueryBuilder('q'); - // Select all question information + // Select all question information. $qb->select('q'); - // Inner join with the table c_quiz_question_rel_category + // Inner join with the table c_quiz_question_rel_category. $qb->innerJoin('q.quizQuestionRelCategoryList', 'c'); + // Inner join with question extra fields. + //$qb->innerJoin('q.extraFields', 'e'); + $wherePart = $qb->expr()->andx(); $wherePart->add($qb->expr()->eq('c.categoryId', $categoryId)); $qb->where($wherePart); + //echo $qb->getQuery()->getSQL()."
"; return $qb; } -} \ No newline at end of file +} diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 384926b82b..a1f8b4de5f 100644 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -118,72 +118,26 @@ if ($_REQUEST['_search'] == 'true') { } $filters = isset($_REQUEST['filters']) ? json_decode($_REQUEST['filters']) : false; - //for now - $extra_field = new ExtraField('session'); + // for now if (!empty($filters)) { - //Getting double select if exists - $double_select = array(); - foreach ($filters->rules as $rule) { - if (strpos($rule->field, '_second') === false) { - - } else { - $my_field = str_replace('_second', '', $rule->field); - $double_select[$my_field] = $rule->data; - } + switch($action) { + case 'get_questions': + $type = 'question'; + break; + case 'get_sessions': + $type = 'session'; + break; } - $condition_array = array(); - - foreach ($filters->rules as $rule) { - if (strpos($rule->field, 'extra_') === false) { - //normal fields - $field = $rule->field; - if (!empty($rule->data)) { - $condition_array[] = get_where_clause($field, $rule->op, $rule->data); - } - } else { - //Extra fields - - //normal - if (strpos($rule->field, '_second') === false) { - //No _second - $original_field = str_replace('extra_', '', $rule->field); - $field_option = $extra_field->get_handler_field_info_by_field_variable($original_field); - - if ($field_option['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) { - - if (isset($double_select[$rule->field])) { - $data = explode('#', $rule->data); - $rule->data = $data[1].'::'.$double_select[$rule->field]; - } else { - // only was sent 1 select - $data = explode('#', $rule->data); - $rule->data = $data[1]; - } - if (!empty($rule->data)) { - $condition_array[] = ' ('.get_where_clause($rule->field, $rule->op, $rule->data).') '; - $extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']); - } - } else { - if (!empty($rule->data)) { - $condition_array[] = ' ('.get_where_clause($rule->field, $rule->op, $rule->data).') '; - $extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']); - } - } - } else { - $my_field = str_replace('_second', '', $rule->field); - $original_field = str_replace('extra_', '', $my_field); - $field_option = $extra_field->get_handler_field_info_by_field_variable($original_field); - $extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']); - } - } - } + $extraField = new ExtraField($type); + $result = $extraField->getExtraFieldRules($filters); + $extra_fields = $result['extra_fields']; + $condition_array = $result['condition_array']; if (!empty($condition_array)) { $where_condition .= ' AND ( '; $where_condition .= implode($filters->groupOp, $condition_array); - $where_condition .= ' ) '; } } @@ -202,9 +156,13 @@ switch ($action) { case 'get_questions': $categoryId = isset($_REQUEST['categoryId']) ? $_REQUEST['categoryId'] : null; /** @var \Doctrine\ORM\EntityManager $em */ - $em = $app['orm.em']; + /*$em = $app['orm.em']; $repo = $em->getRepository('Entity\CQuizQuestionRelCategory'); - $count = $repo->getCountQuestionByCategory($categoryId); + $count = $repo->getCountQuestionByCategory($categoryId);*/ + if (isset($_REQUEST['categoryId'])) { + $categoryId = intval($_REQUEST['categoryId']); + } + $count = Question::getQuestions($categoryId, array('where'=> $where_condition, 'extra' => $extra_fields), true); break; case 'get_user_list_plugin_widescale': $count = UserManager::get_user_data(null, null, null, null, true); @@ -252,7 +210,7 @@ switch ($action) { } $count = ExerciseLib::get_count_exam_results($exercise_id, $where_condition); break; - case 'get_hotpotatoes_exercise_results': + case 'get_hotpotatoes_exercise_results': $hotpot_path = $_REQUEST['path']; $count = ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path); break; @@ -340,17 +298,17 @@ if (isset($_REQUEST['oper']) && $_REQUEST['oper'] == 'del') { $obj->delete($_REQUEST['id']); } -$is_allowedToEdit = api_is_allowed_to_edit(null,true) || api_is_allowed_to_edit(true) || api_is_drh(); +$is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_allowed_to_edit(true) || api_is_drh(); //5. Querying the DB for the elements $columns = array(); switch ($action) { case 'get_questions': - $columns = array('iid', 'question', 'description', 'actions'); // @todo implement a class that manages jqgrid petitions /** @var \Entity\Repository\CQuizQuestionRepository $repo */ - $repo = $em->getRepository('Entity\CQuizQuestion'); + /*$repo = $em->getRepository('Entity\CQuizQuestion'); + var_dump($where_condition, $extra_fields); $qb = $repo->getQuestionsByCategory($categoryId); if (!empty($sidx) && strlen($sidx) > 1) { $sidx = 'q.'.$sidx; @@ -361,22 +319,15 @@ switch ($action) { $qb->getMaxResults($limit); $query = $qb->getQuery(); //echo $qb->getQuery()->getSQL(); - $questions = $query->getResult(); + $questions = $query->getResult();*/ /** @var \Entity\CQuizCategory $category */ /*$category = $repo->find($categoryId); $questions = $category->getQuestions();*/ + $columns = Question::getQuestionColumns(); + $columns = $columns['simple_column_name']; + $result = Question::getQuestions($categoryId, array('where'=> $where_condition, 'order'=>"$sidx $sord", 'extra' => $extra_fields, 'limit'=> "$start , $limit")); - $result = array(); - foreach ($questions as $question) { - $row = array(); - $row['iid'] = $question->getIid(); - $row['question'] = $question->getQuestion(); - $row['description'] = $question->getDescription(); - //$row['iid'] = $question->getIid(); - //$row['iid'] = $question->getIid(); - $result[] = $row; - } break; case 'get_user_list_plugin_widescale': $columns = array('username', 'firstname', 'lastname', 'exam_password'); @@ -426,8 +377,8 @@ switch ($action) { $column_names[] = $extra['3']; } } - $result = CourseManager::get_user_list_from_course_code(null, null, "LIMIT $start, $limit", " $sidx $sord", null, null, true); - break; + $result = CourseManager::get_user_list_from_course_code(null, null, "LIMIT $start, $limit", " $sidx $sord", null, null, true); + break; case 'get_user_skill_ranking': $columns = array('photo', 'firstname', 'lastname', 'skills_acquired', 'currently_learning', 'rank'); $result = $skill->get_user_list_skill_ranking($start, $limit, $sidx, $sord, $where_condition); @@ -797,4 +748,4 @@ if (in_array($action, $allowed_actions)) { } echo json_encode($response); } -exit; \ No newline at end of file +exit; diff --git a/main/inc/lib/display.lib.php b/main/inc/lib/display.lib.php index ce4fd394b5..acda7bb571 100644 --- a/main/inc/lib/display.lib.php +++ b/main/inc/lib/display.lib.php @@ -1104,7 +1104,6 @@ class Display $all_text = addslashes(get_lang('All')); $json .= '$("'.$obj->pager.' option[value='.$all_value.']").text("'.$all_text.'");'; - $json .= "\n"; //Adding edit/delete icons @@ -1846,4 +1845,4 @@ class Display } return $html; } -} \ No newline at end of file +} diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 5dd376618c..2fe35c4b03 100644 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -46,6 +46,7 @@ class ExtraField extends Model //Used for the model $this->table = Database::get_main_table(TABLE_MAIN_COURSE_FIELD); $this->handler_id = 'course_code'; + $this->primaryKey = 'id'; break; case 'user': $this->table_field_options = Database::get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS); @@ -54,6 +55,7 @@ class ExtraField extends Model //Used for the model $this->table = Database::get_main_table(TABLE_MAIN_USER_FIELD); $this->handler_id = 'user_id'; + $this->primaryKey = 'user_id'; break; case 'session': $this->table_field_options = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS); @@ -62,21 +64,24 @@ class ExtraField extends Model //Used for the model $this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD); $this->handler_id = 'session_id'; + $this->primaryKey = 'id'; break; case 'question': - $this->table_field_options = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_OPTIONS); - $this->table_field_values = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES); + $this->table_field_options = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_OPTIONS); + $this->table_field_values = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES); //Used for the model - $this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD); + $this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD); $this->handler_id = 'question_id'; + $this->primaryKey = 'iid'; break; } - $this->pageUrl = 'extra_fields.php?type='.$this->type; + $this->pageUrl = 'extra_fields.php?type='.$this->type; $this->pageName = get_lang(ucwords($this->type).'Fields'); // Example QuestionFields } - static function getValidExtraFieldTypes() { + static function getValidExtraFieldTypes() + { return array( 'user', 'course', @@ -501,7 +506,7 @@ class ExtraField extends Model if (isset($field_details['options']) && !empty($field_details['options'])) { foreach ($field_details['options'] as $option_details) { $options[$option_details['option_value']] = $option_details['option_display_text']; - $group[] = $form->createElement( + $group[] = $form->createElement( 'checkbox', 'extra_'.$field_details['field_variable'], $option_details['option_value'], @@ -548,7 +553,9 @@ class ExtraField extends Model if (!empty($field_details['options'])) { foreach ($field_details['options'] as $option_id => $option_details) { if ($get_lang_variables) { - $options[$option_details['option_value']] = get_lang($option_details['option_display_text']); + $options[$option_details['option_value']] = get_lang( + $option_details['option_display_text'] + ); } else { $options[$option_details['option_value']] = $option_details['option_display_text']; } @@ -814,13 +821,13 @@ EOF; function setupBreadcrumb(&$breadcrumb, $action) { if ($action == 'add') { - $breadcrumb[]=array('url' => $this->pageUrl,'name' => $this->pageName); - $breadcrumb[]=array('url' => '#','name' => get_lang('Add')); + $breadcrumb[] = array('url' => $this->pageUrl, 'name' => $this->pageName); + $breadcrumb[] = array('url' => '#', 'name' => get_lang('Add')); } elseif ($action == 'edit') { - $breadcrumb[]=array('url' => $this->pageUrl,'name' => $this->pageName); - $breadcrumb[]=array('url' => '#','name' => get_lang('Edit')); + $breadcrumb[] = array('url' => $this->pageUrl, 'name' => $this->pageName); + $breadcrumb[] = array('url' => '#', 'name' => get_lang('Edit')); } else { - $breadcrumb[]=array('url' => '#','name' => $this->pageName); + $breadcrumb[] = array('url' => '#', 'name' => $this->pageName); } } @@ -832,26 +839,90 @@ EOF; { // action links echo '
'; - echo '' . Display::return_icon('back.png', get_lang('BackTo') . ' ' . get_lang('PlatformAdmin'), '', ICON_SIZE_MEDIUM) . ''; - echo '' . Display::return_icon('add_user_fields.png', get_lang('Add'), '', ICON_SIZE_MEDIUM) . ''; + echo ''.Display::return_icon( + 'back.png', + get_lang('BackTo').' '.get_lang('PlatformAdmin'), + '', + ICON_SIZE_MEDIUM + ).''; + echo ''.Display::return_icon( + 'add_user_fields.png', + get_lang('Add'), + '', + ICON_SIZE_MEDIUM + ).''; echo '
'; echo Display::grid_html($this->type.'_fields'); } - public function getJqgridColumnNames() { - return array(get_lang('Name'), get_lang('FieldLabel'), get_lang('Type'), get_lang('FieldChangeability'), get_lang('Visibility'), get_lang('Filter'), get_lang('FieldOrder'), get_lang('Actions')); + public function getJqgridColumnNames() + { + return array( + get_lang('Name'), + get_lang('FieldLabel'), + get_lang('Type'), + get_lang('FieldChangeability'), + get_lang('Visibility'), + get_lang('Filter'), + get_lang('FieldOrder'), + get_lang('Actions') + ); } - public function getJqgridColumnModel() { + public function getJqgridColumnModel() + { return array( - array('name'=>'field_display_text', 'index'=>'field_display_text', 'width'=>'180', 'align'=>'left'), - array('name'=>'field_variable', 'index'=>'field_variable', 'width'=>'', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_type', 'index'=>'field_type', 'width'=>'', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_changeable', 'index'=>'field_changeable', 'width'=>'50', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_visible', 'index'=>'field_visible', 'width'=>'40', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_filter', 'index'=>'field_filter', 'width'=>'30', 'align'=>'left','sortable'=>'true'), - array('name'=>'field_order', 'index'=>'field_order', 'width'=>'40', 'align'=>'left','sortable'=>'true'), - array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false') + array('name' => 'field_display_text', 'index' => 'field_display_text', 'width' => '180', 'align' => 'left'), + array( + 'name' => 'field_variable', + 'index' => 'field_variable', + 'width' => '', + 'align' => 'left', + 'sortable' => 'true' + ), + array( + 'name' => 'field_type', + 'index' => 'field_type', + 'width' => '', + 'align' => 'left', + 'sortable' => 'true' + ), + array( + 'name' => 'field_changeable', + 'index' => 'field_changeable', + 'width' => '50', + 'align' => 'left', + 'sortable' => 'true' + ), + array( + 'name' => 'field_visible', + 'index' => 'field_visible', + 'width' => '40', + 'align' => 'left', + 'sortable' => 'true' + ), + array( + 'name' => 'field_filter', + 'index' => 'field_filter', + 'width' => '30', + 'align' => 'left', + 'sortable' => 'true' + ), + array( + 'name' => 'field_order', + 'index' => 'field_order', + 'width' => '40', + 'align' => 'left', + 'sortable' => 'true' + ), + array( + 'name' => 'actions', + 'index' => 'actions', + 'width' => '100', + 'align' => 'left', + 'formatter' => 'action_formatter', + 'sortable' => 'false' + ) ); } @@ -866,7 +937,7 @@ EOF; $form->addElement('hidden', 'id', $id); // Setting the form elements - $header = get_lang('Add'); + $header = get_lang('Add'); $defaults = array(); if ($action == 'edit') { @@ -881,34 +952,57 @@ EOF; // Field type $types = self::get_field_types(); - $form->addElement('select', 'field_type', get_lang('FieldType'), $types, array('id' => 'field_type', 'class' => 'chzn-select', 'data-placeholder' => get_lang('Select'))); + $form->addElement( + 'select', + 'field_type', + get_lang('FieldType'), + $types, + array('id' => 'field_type', 'class' => 'chzn-select', 'data-placeholder' => get_lang('Select')) + ); $form->addElement('label', get_lang('Example'), '
-
'); //$form->addElement('advanced_settings',''.get_lang('AdvancedParameters').''); //$form->addElement('html',' {% endblock %} + {% block right_column %}
diff --git a/main/template/default/admin/questionmanager/questions.tpl b/main/template/default/admin/questionmanager/questions.tpl index 6b15495eee..ca8a9ae7d3 100644 --- a/main/template/default/admin/questionmanager/questions.tpl +++ b/main/template/default/admin/questionmanager/questions.tpl @@ -1,8 +1,128 @@ +
+ {% if category %} +

{{ category.title }}

+ {% endif %} + {{ grid }} -
\ No newline at end of file + diff --git a/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php b/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php index 7633a6bb82..d6563a7cf7 100644 --- a/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php +++ b/src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php @@ -127,50 +127,38 @@ class QuestionManagerController public function getQuestionsByCategoryAction(Application $app, $categoryId) { // Getting CQuizCategory repo. - $repo = $app['orm.em']->getRepository('Entity\CQuizCategory'); + /** @var \Doctrine\ORM\EntityManager $em */ + $em = $app['orm.em']; + $repo = $em->getRepository('Entity\CQuizCategory'); /** @var \Entity\CQuizCategory $category */ $category = $repo->find($categoryId); - $questions = $category->getQuestions(); + //$questions = $category->getQuestions(); + + /*$questionFields = $em->getRepository('Entity\QuestionField')->findAll(); + $rules = array(); + foreach ($questionFields as $extraField) { + $extraField->getFieldVariable(); + $rules[] = ; + }*/ + + $questionColumns = \Question::getQuestionColumns(); + $columnModel = $questionColumns['column_model']; + $columns = $questionColumns['columns']; + $rules = $questionColumns['rules']; $grid = \Display::grid_html('questions'); //jqgrid will use this URL to do the selects $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_questions&categoryId='.$categoryId; - //The order is important you need to check the the $column variable in the model.ajax.php file - $columns = array('id', get_lang('Name'), get_lang('Description'), get_lang('Actions')); - - // Column config. - $columnModel = array( - array( - 'name' => 'iid', - 'index' => 'iid', - 'width' => '20', - 'align' => 'left' - ), - array( - 'name' => 'question', - 'index' => 'question', - 'width' => '200', - 'align' => 'left' - ), - array( - 'name' => 'description', - 'index' => 'description', - 'width' => '100', - 'align' => 'left', - 'sortable' => 'false' - ), - array( - 'name' => 'actions', - 'index' => 'actions', - 'width' => '30', - 'align' => 'left', - 'formatter' => 'action_formatter', - 'sortable' => 'false' + $extraParams['postData'] =array( + 'filters' => array( + "groupOp" => "AND", + "rules" => $rules ) ); + // Autowidth. $extraParams['autowidth'] = 'true'; // Height auto. @@ -186,24 +174,10 @@ class QuestionManagerController $js = \Display::grid_js('questions', $url, $columns, $columnModel, $extraParams, array(), $actionLinks, true); + $app['template']->assign('category', $category); $app['template']->assign('grid', $grid); $app['template']->assign('js', $js); - //$adapter = new DoctrineCollectionAdapter($questions); - - //$adapter = new FixedAdapter($nbResults, array()); - /*$pagerfanta = new Pagerfanta($adapter); - $pagerfanta->setMaxPerPage(10); // 10 by default - $pagerfanta->setCurrentPage(1); // 1 by default - */ - //$this->app['pagerfanta.view.router.name'] = 'userportal'; - /*$this->app['pagerfanta.view.router.params'] = array( - 'filter' => $filter, - 'type' => 'courses', - 'page' => $page - );*/ - //$app['template']->assign('pagination', $pagerfanta); - $response = $app['template']->render_template('admin/questionmanager/questions.tpl'); return new Response($response, 200, array()); } @@ -222,17 +196,43 @@ class QuestionManagerController $app['extraJS'] = $extraJS; // Getting CQuizCategory repo. + /** @var \Gedmo\Tree\Entity\Repository\NestedTreeRepository $repo */ $repo = $app['orm.em']->getRepository('Entity\CQuizCategory'); + $categoryId = $app['request']->get('categoryId'); + $subtree = null; + + if (isset($categoryId)) { + // Insert node. + /* + $options = array( + 'decorate' => true, + 'rootOpen' => '', + 'childOpen' => '
  • ', + 'childClose' => '
  • ' + ); + $node = $repo->find($categoryId); + + $qb = $repo->getChildrenQueryBuilder($node, true, 'title', 'ASC', true); + $query = $qb->getQuery(); + $subtree = $repo->buildTree($query->getArrayResult(), $options); + var_dump($subtree);*/ + } + $options = array( 'decorate' => true, 'rootOpen' => '', 'childOpen' => '
  • ', 'childClose' => '
  • ', - 'nodeDecorator' => function ($row) use ($app) { + 'nodeDecorator' => function ($row) use ($app, $categoryId, $subtree) { $url = $app['url_generator']->generate('admin_questions_get_categories', array('id' => $row['iid'])); - return \Display::url($row['title'], $url, array('id' => $row['iid'])); + $url = \Display::url($row['title'], $url, array('id' => $row['iid'])); + if ($row['iid'] == $categoryId) { + $url .= $subtree; + } + return $url; } //'representationField' => 'slug', //'html' => true @@ -246,16 +246,13 @@ class QuestionManagerController ->where('node.cId <> 0 AND node.lvl = 0') ->orderBy('node.root, node.lft', 'ASC'); - $categoryId = $app['request']->get('categoryId'); - - if (isset($categoryId)) { - /*$qb->add('where', 'node.rgt = :categoryId'); - $qb->setParameter('categoryId', $categoryId);*/ - } + //$node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false + //$qb = $repo->getChildrenQueryBuilder(null, true, 'title', 'ASC', true); $query = $qb->getQuery(); $tree = $repo->buildTree($query->getArrayResult(), $options); + $app['template']->assign('category_tree', $tree); // Getting globals