diff --git a/main/auth/courses.php b/main/auth/courses.php index 041345854a8..2016007ed6e 100755 --- a/main/auth/courses.php +++ b/main/auth/courses.php @@ -264,6 +264,7 @@ $countCoursesInCategory = count($courses); } else { $values = $_REQUEST; + if ($allowExtraFields) { $extraResult = $extraField->processExtraFieldSearch($values, $form, 'course', 'AND'); $conditions = $extraResult['condition']; diff --git a/main/inc/lib/CoursesAndSessionsCatalog.class.php b/main/inc/lib/CoursesAndSessionsCatalog.class.php index 728e1905289..a8d9cd33952 100644 --- a/main/inc/lib/CoursesAndSessionsCatalog.class.php +++ b/main/inc/lib/CoursesAndSessionsCatalog.class.php @@ -671,6 +671,7 @@ public static function searchAndSortCourses( } unset($course); } + // do we have $course['groupKey']['subKey'] to sort on, such as 'point_info/users' ? foreach ($sortKeys as $key) { if (false !== strpos($key, '/')) { diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 3046a470e72..ed97b938eca 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/main/inc/lib/extra_field.lib.php @@ -2486,10 +2486,7 @@ public function processExtraFieldSearch($values, $form, $alias, $condition = 'OR } } - $extraFieldsAll = $this->get_all( - ['visible_to_self = ? AND filter = ?' => [1, 1]], - 'option_order' - ); + $extraFieldsAll = $this->get_all(['visible_to_self = ? AND filter = ?' => [1, 1]], 'option_order'); $extraFieldsType = array_column($extraFieldsAll, 'field_type', 'variable'); $extraFields = array_column($extraFieldsAll, 'variable'); $filter = new stdClass(); @@ -2562,8 +2559,8 @@ public function processExtraFieldSearch($values, $form, $alias, $condition = 'OR */ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condition = 'OR') { - $extra_fields = []; - $condition_array = []; + $extraFields = []; + $conditionArray = []; // Getting double select if exists $double_select = []; @@ -2591,7 +2588,7 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit // normal fields $field = $rule->field; if (isset($rule->data) && is_string($rule->data) && -1 != $rule->data) { - $condition_array[] = $this->get_where_clause($field, $rule->op, $rule->data); + $conditionArray[] = $this->get_where_clause($field, $rule->op, $rule->data); } } else { // Extra fields @@ -2600,47 +2597,61 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit $original_field = str_replace($stringToSearch, '', $rule->field); $field_option = $this->get_handler_field_info_by_field_variable($original_field); - if (self::FIELD_TYPE_DOUBLE_SELECT == $field_option['field_type']) { - if (isset($double_select[$rule->field])) { - $data = explode('#', $rule->data); - $rule->data = $data[1].'::'.$double_select[$rule->field]; - } else { - // only was sent 1 select - if (is_string($rule->data)) { + switch ($field_option['field_type']) { + case self::FIELD_TYPE_DOUBLE_SELECT: + if (isset($double_select[$rule->field])) { $data = explode('#', $rule->data); - $rule->data = $data[1]; + $rule->data = $data[1].'::'.$double_select[$rule->field]; + } else { + // only was sent 1 select + if (is_string($rule->data)) { + $data = explode('#', $rule->data); + $rule->data = $data[1]; + } } - } - if (!isset($rule->data)) { - $condition_array[] = ' (' - .$this->get_where_clause($rule->field, $rule->op, $rule->data) - .') '; - $extra_fields[] = ['field' => $rule->field, 'id' => $field_option['id']]; - } - } else { - if (isset($rule->data)) { - if (isset($rule->data) && is_int($rule->data) && -1 == $rule->data) { - continue; + if (!isset($rule->data)) { + $conditionArray[] = ' (' + .$this->get_where_clause($rule->field, $rule->op, $rule->data) + .') '; + $extraFields[] = ['field' => $rule->field, 'id' => $field_option['id']]; } - /*var_dump($rule->data); - foreach ($rule->data as $option) { - }*/ - $where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR'); - $condition_array[] = " ( $where ) "; - - $extra_fields[] = [ - 'field' => $rule->field, - 'id' => $field_option['id'], - 'data' => $rule->data, - ]; - } + break; + case self::FIELD_TYPE_TAG: + if (isset($rule->data)) { + if (is_int($rule->data) && -1 == $rule->data) { + break; + } + // Where will be injected in the parseConditions() + //$where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR'); + //$conditionArray[] = " ( $where ) "; + $extraFields[] = [ + 'field' => $rule->field, + 'id' => $field_option['id'], + 'data' => $rule->data, + ]; + } + break; + default: + if (isset($rule->data)) { + if (is_int($rule->data) && -1 == $rule->data) { + break; + } + $where = $this->get_where_clause($rule->field, $rule->op, $rule->data, 'OR'); + $conditionArray[] = " ( $where ) "; + $extraFields[] = [ + 'field' => $rule->field, + 'id' => $field_option['id'], + 'data' => $rule->data, + ]; + } + break; } } else { $my_field = str_replace('_second', '', $rule->field); $original_field = str_replace($stringToSearch, '', $my_field); $field_option = $this->get_handler_field_info_by_field_variable($original_field); - $extra_fields[] = [ + $extraFields[] = [ 'field' => $rule->field, 'id' => $field_option['id'], ]; @@ -2649,17 +2660,7 @@ public function getExtraFieldRules($filters, $stringToSearch = 'extra_', $condit } } - /*var_dump( - [ - 'extra_fields' => $extra_fields, - 'condition_array' => $condition_array, - ] - );*/ - - return [ - 'extra_fields' => $extra_fields, - 'condition_array' => $condition_array, - ]; + return ['extra_fields' => $extraFields, 'condition_array' => $conditionArray,]; } /** @@ -2737,7 +2738,7 @@ public function parseConditions($options, $alias = 's') case self::FIELD_TYPE_DOUBLE_SELECT: $inject_extra_fields .= " fvo$counter.display_text as {$extra['field']}, "; break; - case self::FIELD_TYPE_TAG: + case self::FIELD_TYPE_TAG: // If using OR // If using AND $newCounter = 1; @@ -2780,7 +2781,6 @@ public function parseConditions($options, $alias = 's') $inject_joins = null; $inject_where = null; $where = null; - if (!empty($options['where'])) { if (!empty($options['extra'])) { // Removing double 1=1 @@ -2810,8 +2810,8 @@ public function parseConditions($options, $alias = 's') break; case self::FIELD_TYPE_TAG: $newCounter = 1; - $whereTag = []; if (isset($extra_info['data']) && !empty($extra_info['data'])) { + $whereTag = []; foreach ($extra_info['data'] as $data) { $data = Database::escape_string($data); $key = $counter.$newCounter; @@ -2827,10 +2827,9 @@ public function parseConditions($options, $alias = 's') "; $newCounter++; } - } - - if (!empty($whereTag)) { - $options['where'] = ' ('.implode(' AND ', $whereTag).') '; + if (!empty($whereTag)) { + $options['where'] .= ' AND ('.implode(' AND ', $whereTag).') '; + } } break; default: @@ -2849,11 +2848,11 @@ public function parseConditions($options, $alias = 's') $where .= ' AND '.$options['where']; } - $order = null; + $order = ''; if (!empty($options['order'])) { $order = ' ORDER BY '.$options['order']; } - $limit = null; + $limit = ''; if (!empty($options['limit'])) { $limit = ' LIMIT '.$options['limit']; }