');
$form->addElement('text', 'field_variable', get_lang('FieldLabel'), array('class' => 'span5'));
- $form->addElement('text', 'field_options', get_lang('FieldPossibleValues'), array('id' => 'field_options', 'class' => 'span6'));
+ $form->addElement(
+ 'text',
+ 'field_options',
+ get_lang('FieldPossibleValues'),
+ array('id' => 'field_options', 'class' => 'span6')
+ );
if ($action == 'edit') {
- if (in_array($defaults['field_type'], array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT))) {
- $url = Display::url(get_lang('EditExtraFieldOptions'), 'extra_field_options.php?type='.$this->type.'&field_id=' . $id);
+ if (in_array(
+ $defaults['field_type'],
+ array(ExtraField::FIELD_TYPE_SELECT, ExtraField::FIELD_TYPE_DOUBLE_SELECT)
+ )
+ ) {
+ $url = Display::url(
+ get_lang('EditExtraFieldOptions'),
+ 'extra_field_options.php?type='.$this->type.'&field_id='.$id
+ );
$form->addElement('label', null, $url);
$form->freeze('field_options');
}
}
- $form->addElement('text', 'field_default_value', get_lang('FieldDefaultValue'), array('id' => 'field_default_value', 'class' => 'span5'));
+ $form->addElement(
+ 'text',
+ 'field_default_value',
+ get_lang('FieldDefaultValue'),
+ array('id' => 'field_default_value', 'class' => 'span5')
+ );
- $group = array();
+ $group = array();
$group[] = $form->createElement('radio', 'field_visible', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_visible', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('Visible'), '', false);
- $group = array();
+ $group = array();
$group[] = $form->createElement('radio', 'field_changeable', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_changeable', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldChangeability'), '', false);
- $group = array();
+ $group = array();
$group[] = $form->createElement('radio', 'field_filter', null, get_lang('Yes'), 1);
$group[] = $form->createElement('radio', 'field_filter', null, get_lang('No'), 0);
$form->addGroup($group, '', get_lang('FieldFilter'), '', false);
@@ -923,9 +1017,9 @@ EOF;
$defaults['field_options'] = $option->get_field_options_by_field_to_string($id);
$form->addElement('button', 'submit', get_lang('Modify'), 'class="save"');
} else {
- $defaults['field_visible'] = 0;
+ $defaults['field_visible'] = 0;
$defaults['field_changeable'] = 0;
- $defaults['field_filter'] = 0;
+ $defaults['field_filter'] = 0;
$form->addElement('button', 'submit', get_lang('Add'), 'class="save"');
}
@@ -949,27 +1043,42 @@ EOF;
{
//With this function we can add actions to the jgrid (edit, delete, etc)
return 'function action_formatter(cellvalue, options, rowObject) {
- return \'
'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).''.
- '
'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''.
+ return \'
'.Display::return_icon(
+ 'edit.png',
+ get_lang('Edit'),
+ '',
+ ICON_SIZE_SMALL
+ ).''.
+ '
'.Display::return_icon(
+ 'delete.png',
+ get_lang('Delete'),
+ '',
+ ICON_SIZE_SMALL
+ ).''.
'\';
}';
}
public function getRules(&$columns, &$column_model)
{
- $fields = $this->get_all(array('field_visible = ? AND field_filter = ?' => array(1, 1)), 'option_display_text');
+ $fields = $this->get_all(
+ array('field_visible = ? AND field_filter = ?' => array(1, 1)),
+ 'option_display_text'
+ );
$extraFieldOption = new ExtraFieldOption($this->type);
$rules = array();
if (!empty($fields)) {
foreach ($fields as $field) {
$search_options = array();
- $type = 'text';
+ $type = 'text';
if (in_array($field['field_type'], array(self::FIELD_TYPE_SELECT, self::FIELD_TYPE_DOUBLE_SELECT))) {
- $type = 'select';
+ $type = 'select';
$search_options['sopt'] = array('eq', 'ne'); //equal not equal
} else {
- $search_options['sopt'] = array('cn', 'nc');//contains not contains
+ $search_options['sopt'] = array('cn', 'nc'); //contains not contains
}
$search_options['searchhidden'] = 'true';
@@ -977,8 +1086,8 @@ EOF;
if ($field['field_type'] == self::FIELD_TYPE_DOUBLE_SELECT) {
//Add 2 selects
- $options = $extraFieldOption->get_field_options_by_field($field['id']);
- $options = self::extra_field_double_select_convert_array_to_ordered_array($options);
+ $options = $extraFieldOption->get_field_options_by_field($field['id']);
+ $options = self::extra_field_double_select_convert_array_to_ordered_array($options);
$first_options = array();
if (!empty($options)) {
@@ -992,55 +1101,256 @@ EOF;
}
}
- $search_options['value'] = implode(';', $first_options);
+ $search_options['value'] = implode(';', $first_options);
$search_options['dataInit'] = 'fill_second_select';
//First
$column_model[] = array(
- 'name' => 'extra_'.$field['field_variable'],
- 'index' => 'extra_'.$field['field_variable'],
- 'width' => '100',
- 'hidden' => 'true',
- 'search' => 'true',
- 'stype' => 'select',
+ 'name' => 'extra_'.$field['field_variable'],
+ 'index' => 'extra_'.$field['field_variable'],
+ 'width' => '100',
+ 'hidden' => 'true',
+ 'search' => 'true',
+ 'stype' => 'select',
'searchoptions' => $search_options
);
- $columns[] = $field['field_display_text'].' (1)';
- $rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
+ $columns[] = $field['field_display_text'].' (1)';
+ $rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
//Second
- $search_options['value'] = $field['id'].':';
+ $search_options['value'] = $field['id'].':';
$search_options['dataInit'] = 'register_second_select';
$column_model[] = array(
- 'name' => 'extra_'.$field['field_variable'].'_second',
- 'index' => 'extra_'.$field['field_variable'].'_second',
- 'width' => '100',
- 'hidden' => 'true',
- 'search' => 'true',
- 'stype' => 'select',
+ 'name' => 'extra_'.$field['field_variable'].'_second',
+ 'index' => 'extra_'.$field['field_variable'].'_second',
+ 'width' => '100',
+ 'hidden' => 'true',
+ 'search' => 'true',
+ 'stype' => 'select',
'searchoptions' => $search_options
);
- $columns[] = $field['field_display_text'].' (2)';
- $rules[] = array('field' => 'extra_'.$field['field_variable'].'_second', 'op' => 'cn');
+ $columns[] = $field['field_display_text'].' (2)';
+ $rules[] = array('field' => 'extra_'.$field['field_variable'].'_second', 'op' => 'cn');
continue;
} else {
- $search_options['value'] = $extraFieldOption->get_field_options_to_string($field['id'], false, 'option_display_text');
+ $search_options['value'] = $extraFieldOption->get_field_options_to_string(
+ $field['id'],
+ false,
+ 'option_display_text'
+ );
}
$column_model[] = array(
- 'name' => 'extra_'.$field['field_variable'],
- 'index' => 'extra_'.$field['field_variable'],
- 'width' => '100',
- 'hidden' => 'true',
- 'search' => 'true',
- 'stype' => $type,
+ 'name' => 'extra_'.$field['field_variable'],
+ 'index' => 'extra_'.$field['field_variable'],
+ 'width' => '100',
+ 'hidden' => 'true',
+ 'search' => 'true',
+ 'stype' => $type,
'searchoptions' => $search_options
);
- $columns[] = $field['field_display_text'];
- $rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
+ $columns[] = $field['field_display_text'];
+ $rules[] = array('field' => 'extra_'.$field['field_variable'], 'op' => 'cn');
}
}
+
return $rules;
}
+
+ /**
+ * @param array $options
+ * @return array
+ */
+ function parseConditions($options)
+ {
+ $inject_extra_fields = null;
+ $extraFieldOption = new ExtraFieldOption($this->type);
+ $double_fields = array();
+
+ if (isset($options['extra'])) {
+ $extra_fields = $options['extra'];
+ if (!empty($extra_fields)) {
+ $counter = 1;
+ foreach ($extra_fields as &$extra) {
+ $extra_field_obj = new ExtraField($this->type);
+ $extra_field_info = $extra_field_obj->get($extra['id']);
+ $extra['extra_field_info'] = $extra_field_info;
+
+ if (in_array(
+ $extra_field_info['field_type'],
+ array(
+ ExtraField::FIELD_TYPE_SELECT,
+ ExtraField::FIELD_TYPE_SELECT,
+ ExtraField::FIELD_TYPE_DOUBLE_SELECT
+ )
+ )
+ ) {
+ $inject_extra_fields .= " fvo$counter.option_display_text as {$extra['field']}, ";
+ } else {
+ $inject_extra_fields .= " fv$counter.field_value as {$extra['field']}, ";
+ }
+
+ if (isset($extra_fields_info[$extra['id']])) {
+ $info = $extra_fields_info[$extra['id']];
+ } else {
+ $info = $this->get($extra['id']);
+ $extra_fields_info[$extra['id']] = $info;
+ }
+ if ($info['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
+ $double_fields[$info['id']] = $info;
+ }
+ $counter++;
+ }
+ }
+ }
+ $options_by_double = array();
+ foreach ($double_fields as $double) {
+ $my_options = $extraFieldOption->get_field_options_by_field(
+ $double['id'],
+ true
+ );
+ $options_by_double['extra_'.$double['field_variable']] = $my_options;
+ }
+
+ $field_value_to_join = array();
+
+ //filter can be all/any = and/or
+ $inject_joins = null;
+ $inject_where = null;
+ $where = null;
+
+ if (!empty($options['where'])) {
+ if (!empty($options['extra'])) {
+ //Removing double 1=1
+ $options['where'] = str_replace(' 1 = 1 AND', '', $options['where']);
+ //Always OR
+ $counter = 1;
+ foreach ($extra_fields as $extra_info) {
+ $extra_field_info = $extra_info['extra_field_info'];
+ $inject_joins .= " INNER JOIN $this->table_field_values fv$counter ON (s.".$this->primaryKey." = fv$counter.".$this->handler_id.") ";
+
+ //Add options
+ if (in_array(
+ $extra_field_info['field_type'],
+ array(
+ ExtraField::FIELD_TYPE_SELECT,
+ ExtraField::FIELD_TYPE_SELECT,
+ ExtraField::FIELD_TYPE_DOUBLE_SELECT
+ )
+ )
+ ) {
+ $options['where'] = str_replace(
+ $extra_info['field'],
+ 'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fvo'.$counter.'.option_value',
+ $options['where']
+ );
+ $inject_joins .= " INNER JOIN $this->table_field_options fvo$counter ".
+ " ON (fv$counter.field_id = fvo$counter.field_id AND fv$counter.field_value = fvo$counter.option_value) ";
+ } else {
+ //text, textarea, etc
+ $options['where'] = str_replace(
+ $extra_info['field'],
+ 'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fv'.$counter.'.field_value',
+ $options['where']
+ );
+ }
+
+ $field_value_to_join[] = " fv$counter.$this->handler_id ";
+ $counter++;
+ }
+ if (!empty($field_value_to_join)) {
+ //$inject_where .= " AND s.id = ".implode(' = ', $field_value_to_join);
+ }
+ }
+ $where .= ' AND '.$options['where'];
+ }
+
+ $order = null;
+ if (!empty($options['order'])) {
+ $order = " ORDER BY ".$options['order'];
+ }
+ $limit = null;
+ if (!empty($options['limit'])) {
+ $limit = " LIMIT ".$options['limit'];
+ }
+
+ return array(
+ 'order' => $order,
+ 'limit' => $limit,
+ 'where' => $where,
+ 'inject_where' => $inject_where,
+ 'inject_joins' => $inject_joins,
+ 'field_value_to_join' => $field_value_to_join,
+ 'inject_extra_fields' => $inject_extra_fields,
+ );
+ }
+
+ public function getExtraFieldRules($filters)
+ {
+ $extra_fields = array();
+
+ // 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;
+ }
+ }
+
+ $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 = $this->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 = $this->get_handler_field_info_by_field_variable($original_field);
+ $extra_fields[] = array('field' => $rule->field, 'id' => $field_option['id']);
+ }
+ }
+ }
+
+ return array(
+ 'extra_fields' => $extra_fields,
+ 'condition_array' => $condition_array
+ );
+ }
}
diff --git a/main/inc/lib/extra_field_option.lib.php b/main/inc/lib/extra_field_option.lib.php
index dbad3657e0..a3450daf85 100644
--- a/main/inc/lib/extra_field_option.lib.php
+++ b/main/inc/lib/extra_field_option.lib.php
@@ -521,4 +521,7 @@ class ExtraFieldOption extends Model
return $form;
}
+
+
+
}
diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php
index f5264a5d7a..f3b73934a0 100644
--- a/main/inc/lib/sessionmanager.lib.php
+++ b/main/inc/lib/sessionmanager.lib.php
@@ -182,10 +182,9 @@ class SessionManager
* @return mixed Integer for number of rows, or array of results
* @assert (array(),true) !== false
*/
- public static function get_sessions_admin($options = array(), $get_count = false) {
- $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
- $tbl_session_field_values = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
- $tbl_session_field_options = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_OPTIONS);
+ public static function get_sessions_admin($options = array(), $get_count = false)
+ {
+ $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$where = 'WHERE 1 = 1 ';
$user_id = api_get_user_id();
@@ -198,58 +197,14 @@ class SessionManager
$where .=" AND s.id_coach = $user_id ";
}
- $inject_extra_fields = null;
- $extra_fields = array();
- $extra_fields_info = array();
-
- //for now only sessions
$extra_field = new ExtraField('session');
- $double_fields = array();
-
- $extra_field_option = new ExtraFieldOption('session');
-
- $extra_present = false;
-
- if (isset($options['extra'])) {
- $extra_fields = $options['extra'];
- if (!empty($extra_fields)) {
- $extra_present = true;
- $counter = 1;
- foreach ($extra_fields as &$extra) {
- $extra_field_obj= new ExtraField('session');
- $extra_field_info = $extra_field_obj->get($extra['id']);
- $extra['extra_field_info'] = $extra_field_info;
-
- if (in_array($extra_field_info['field_type'], array(
- ExtraField::FIELD_TYPE_SELECT,
- ExtraField::FIELD_TYPE_SELECT,
- ExtraField::FIELD_TYPE_DOUBLE_SELECT
- ))
- ) {
- $inject_extra_fields .= " fvo$counter.option_display_text as {$extra['field']}, ";
- } else {
- $inject_extra_fields .= " fv$counter.field_value as {$extra['field']}, ";
- }
-
- if (isset($extra_fields_info[$extra['id']])) {
- $info = $extra_fields_info[$extra['id']];
- } else {
- $info = $extra_field->get($extra['id']);
- $extra_fields_info[$extra['id']] = $info;
- }
- if ($info['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
- $double_fields[$info['id']] = $info;
- }
- $counter++;
- }
- }
- }
-
- $options_by_double = array();
- foreach ($double_fields as $double) {
- $my_options = $extra_field_option->get_field_options_by_field($double['id'], true);
- $options_by_double['extra_'.$double['field_variable']] = $my_options;
- }
+ $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";
@@ -266,70 +221,20 @@ class SessionManager
" s.id ";
}
- //filter can be all/any = and/or
- $inject_joins = null;
- $inject_where = null;
- $field_value_to_join = array();
-
- if (!empty($options['where'])) {
- if (!empty($options['extra'])) {
- //Removing double 1=1
- $options['where'] = str_replace(' 1 = 1 AND', '', $options['where']);
- //Always OR
- $counter = 1;
- foreach ($extra_fields as $extra_info) {
- $extra_field_info = $extra_info['extra_field_info'];
-
- $inject_joins .= " INNER JOIN $tbl_session_field_values fv$counter ON (s.id = fv$counter.session_id) ";
-
- //Add options
- if (in_array($extra_field_info['field_type'], array(
- ExtraField::FIELD_TYPE_SELECT,
- ExtraField::FIELD_TYPE_SELECT,
- ExtraField::FIELD_TYPE_DOUBLE_SELECT
- ))
- ) {
- $options['where'] = str_replace($extra_info['field'], 'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fvo'.$counter.'.option_value', $options['where']);
- $inject_joins .= " INNER JOIN $tbl_session_field_options fvo$counter ".
- " ON (fv$counter.field_id = fvo$counter.field_id AND fv$counter.field_value = fvo$counter.option_value) ";
- } else {
- //text, textarea, etc
- $options['where'] = str_replace($extra_info['field'], 'fv'.$counter.'.field_id = '.$extra_info['id'].' AND fv'.$counter.'.field_value', $options['where']);
- }
-
- $field_value_to_join[] = " fv$counter.session_id ";
- $counter++;
- }
- if (!empty($field_value_to_join)) {
- //$inject_where .= " AND s.id = ".implode(' = ', $field_value_to_join);
- }
- }
- $where .= ' AND '.$options['where'];
- }
-
$query = "$select FROM $tbl_session s $inject_joins $where $inject_where";
if (api_is_multiple_url_enabled()) {
$table_access_url_rel_session= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
- //" LEFT JOIN $tbl_session_rel_course src ON (src.id_session = s.id) ".
if ($access_url_id != -1) {
$where.= " AND ar.access_url_id = $access_url_id ";
$query = "$select FROM $tbl_session s $inject_joins INNER JOIN $table_access_url_rel_session ar ON (ar.session_id = s.id) $where";
}
}
- if (!empty($options['order'])) {
- $query .= " ORDER BY ".$options['order'];
- }
-
- if (!empty($options['limit'])) {
- $query .= " LIMIT ".$options['limit'];
- }
+ $query .= $order;
+ $query .= $limit;
- if ($get_count == false) {
- //echo $query;exit;
- }
$result = Database::query($query);
$formatted_sessions = array();
@@ -340,6 +245,7 @@ class SessionManager
return $sessions[0]['total_rows'];
}
foreach ($sessions as $session) {
+
$session_id = $session['id'];
$session['name'] = Display::url($session['name'], "resume_session.php?id_session=".$session['id']);
@@ -365,8 +271,7 @@ class SessionManager
break;
}
- //Cleaning double selects
-
+ // Cleaning double selects.
foreach ($session as $key => &$value) {
if (isset($options_by_double[$key]) || isset($options_by_double[$key.'_second'])) {
$options = explode('::', $value);
@@ -666,7 +571,8 @@ class SessionManager
/**
*
*/
- static function compare_arrays_to_merge($array1, $array2) {
+ static function compare_arrays_to_merge($array1, $array2)
+ {
if (empty($array2)) {
return $array1;
}
@@ -2614,7 +2520,7 @@ class SessionManager
break;
}
- //Inject extra session fields
+ // Inject extra session fields
$session_field = new SessionField();
$rules = $session_field->getRules($columns, $column_model);
@@ -2634,7 +2540,8 @@ class SessionManager
return $return_array;
}
- static function getSessionsByCategory($categoryId) {
+ static function getSessionsByCategory($categoryId)
+ {
$categoryId = intval($categoryId);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "select * FROM $tableSession WHERE session_category_id = $categoryId";
diff --git a/main/session/session_list.php b/main/session/session_list.php
index 87d86ec66a..a4580b7d6a 100644
--- a/main/session/session_list.php
+++ b/main/session/session_list.php
@@ -232,13 +232,12 @@ $(function() {
prmSearch
);
- // create the searching dialog
+ // Create the searching dialog.
grid.searchGrid(prmSearch);
- //Fixes search table
+ // Fixes search table.
var searchDialogAll = $("#fbox_"+grid[0].id);
searchDialogAll.addClass("table");
-
var searchDialog = $("#searchmodfbox_"+grid[0].id);
searchDialog.addClass("ui-jqgrid ui-widget ui-widget-content ui-corner-all");
searchDialog.css({position:"relative", "z-index":"auto", "float":"left"})
diff --git a/main/template/default/admin/questionmanager/question_categories.tpl b/main/template/default/admin/questionmanager/question_categories.tpl
index 6a176e1a3f..cc20feef43 100644
--- a/main/template/default/admin/questionmanager/question_categories.tpl
+++ b/main/template/default/admin/questionmanager/question_categories.tpl
@@ -18,13 +18,17 @@
}
$(function() {
-
{% if app.request.get('categoryId') %}
var categoryId = '{{ app.request.get('categoryId') }}';
loadQuestions(categoryId);
{% endif %}
$('.load_categories li').on('click', 'a', function() {
+
+ $('.load_categories li').each(function() {
+ $(this).removeClass('active');
+ });
+ $(this).parent().addClass('active');
var url = $(this).attr('href');
var id = url.replace(/[^\d\.]/g, '');
loadQuestions(id);
@@ -39,6 +43,7 @@
{{ global_category_tree }}
{% endblock %}
+
{% block right_column %}