コード例 #1
0
 /**
  * Gets a structured array of the original item and its extra values, using
  * a specific original item and a field name (like "branch", or "birthdate")
  * @param int Item ID from the original table
  * @param string The name of the field we are looking for
  * @return mixed Array of results, or false on error or not found
  * @assert (-1,'') === false
  */
 public function get_values_by_handler_and_field_variable($item_id, $field_variable, $transform = false)
 {
     $item_id = Database::escape_string($item_id);
     $field_variable = Database::escape_string($field_variable);
     $sql = "SELECT s.*, field_type FROM {$this->table} s\n                INNER JOIN {$this->table_handler_field} sf\n                ON (s.field_id = sf.id)\n                WHERE\n                    {$this->handler_id} = '{$item_id}'  AND\n                    field_variable = '" . $field_variable . "'\n                ORDER BY id";
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         $result = Database::fetch_array($result, 'ASSOC');
         if ($transform) {
             if ($result['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
                 if (!empty($result['field_value'])) {
                     $field_option = new ExtraFieldOption($this->type);
                     $options = explode('::', $result['field_value']);
                     // only available for PHP 5.4  :( $result['field_value'] = $field_option->get($options[0])['id'].' -> ';
                     $result = $field_option->get($options[0]);
                     $result_second = $field_option->get($options[1]);
                     if (!empty($result)) {
                         $result['field_value'] = $result['option_display_text'] . ' -> ';
                         $result['field_value'] .= $result_second['option_display_text'];
                     }
                 }
             }
         }
         return $result;
     } else {
         return false;
     }
 }
コード例 #2
0
 /**
  * Gets a structured array of the original item and its extra values, using
  * a specific original item and a field name (like "branch", or "birthdate")
  * @param int $item_id Item ID from the original table
  * @param string $field_variable The name of the field we are looking for
  * @param bool $transform
  * @param bool $allVisibility
  *
  * @return mixed Array of results, or false on error or not found
  * @assert (-1,'') === false
  */
 public function get_values_by_handler_and_field_variable($item_id, $field_variable, $transform = false, $filterByVisibility = false, $visibility = 0)
 {
     $item_id = intval($item_id);
     $field_variable = Database::escape_string($field_variable);
     $extraFieldType = $this->getExtraField()->getExtraFieldType();
     $sql = "SELECT s.*, field_type\n                FROM {$this->table} s\n                INNER JOIN {$this->table_handler_field} sf\n                ON (s.field_id = sf.id)\n                WHERE\n                    item_id = '{$item_id}'  AND\n                    variable = '" . $field_variable . "' AND\n                    sf.extra_field_type = {$extraFieldType}\n                ";
     if ($filterByVisibility) {
         $visibility = intval($visibility);
         $sql .= " AND visible = {$visibility} ";
     }
     $sql .= " ORDER BY id";
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         $result = Database::fetch_array($result, 'ASSOC');
         if ($transform) {
             if ($result['field_type'] == ExtraField::FIELD_TYPE_DOUBLE_SELECT) {
                 if (!empty($result['value'])) {
                     $field_option = new ExtraFieldOption($this->type);
                     $options = explode('::', $result['value']);
                     $result = $field_option->get($options[0]);
                     $result_second = $field_option->get($options[1]);
                     if (!empty($result)) {
                         $result['value'] = $result['display_text'] . ' -> ';
                         $result['value'] .= $result_second['display_text'];
                     }
                 }
             }
         }
         return $result;
     } else {
         return false;
     }
 }
コード例 #3
0
 /**
  * Gets the admin session list callback of the session/session_list.php
  * page with all user/details in the right fomat
  * @param array
  * @result array Array of rows results
  * @asset ('a') === false
  */
 public static function get_sessions_admin_complete($options = array())
 {
     if (!is_array($options)) {
         return false;
     }
     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
     $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
     $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
     $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
     $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
     $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);
     $where = 'WHERE 1 = 1 ';
     $user_id = api_get_user_id();
     if (!api_is_platform_admin()) {
         if (api_is_session_admin() && api_get_setting('allow_session_admins_to_manage_all_sessions') == 'false') {
             $where .= " AND s.session_admin_id = {$user_id} ";
         }
     }
     $coach_name = " CONCAT(u.lastname , ' ', u.firstname) as coach_name ";
     if (api_is_western_name_order()) {
         $coach_name = " CONCAT(u.firstname, ' ', u.lastname) as coach_name ";
     }
     $today = api_get_utc_datetime();
     $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');
     if (isset($options['extra'])) {
         $extra_fields = $options['extra'];
         if (!empty($extra_fields)) {
             foreach ($extra_fields as $extra) {
                 $inject_extra_fields .= " IF (fv.field_id = {$extra['id']}, fvo.option_display_text, NULL ) 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;
                 }
             }
         }
     }
     $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;
     }
     //sc.name as category_name,
     $select = "\n                SELECT * FROM (\n                    SELECT DISTINCT\n                         IF (\n                            (s.access_start_date <= '{$today}' AND '{$today}' < s.access_end_date) OR\n                            (s.access_start_date  = '0000-00-00 00:00:00' AND s.access_end_date  = '0000-00-00 00:00:00' ) OR\n                            (s.access_start_date  IS NULL AND s.access_end_date IS NULL) OR\n                            (s.access_start_date <= '{$today}' AND ('0000-00-00 00:00:00' = s.access_end_date OR s.access_end_date IS NULL )) OR\n                            ('{$today}' < s.access_end_date AND ('0000-00-00 00:00:00' = s.access_start_date OR s.access_start_date IS NULL) )\n                        , 1, 0) as session_active,\n                s.name,\n                s.nbr_courses,\n                s.nbr_users,\n                s.display_start_date,\n                s.display_end_date,\n                {$coach_name},\n                access_start_date,\n                access_end_date,\n                s.visibility,\n                u.user_id,\n                {$inject_extra_fields}\n                c.title as course_title,\n                s.id ";
     if (!empty($options['where'])) {
         if (!empty($options['extra'])) {
             $options['where'] = str_replace(' 1 = 1  AND', '', $options['where']);
             $options['where'] = str_replace('AND', 'OR', $options['where']);
             foreach ($options['extra'] as $extra) {
                 $options['where'] = str_replace($extra['field'], 'fv.field_id = ' . $extra['id'] . ' AND fvo.option_value', $options['where']);
             }
         }
         $options['where'] = str_replace('course_title', 'c.title', $options['where']);
         $where .= ' AND ' . $options['where'];
     }
     if (!empty($options['limit'])) {
         $where .= " LIMIT " . $options['limit'];
     }
     $query = "{$select} FROM {$tbl_session} s\n                    LEFT JOIN {$tbl_session_field_values} fv ON (fv.session_id = s.id)\n                    LEFT JOIN {$tbl_session_field_options} fvo ON (fv.field_id = fvo.field_id)\n                    LEFT JOIN {$tbl_session_rel_course} src ON (src.id_session = s.id)\n                    LEFT JOIN {$tbl_course} c ON (src.c_id = c.id)\n                    LEFT JOIN {$tbl_session_category} sc ON (s.session_category_id = sc.id)\n                    INNER JOIN {$tbl_user} u ON (s.id_coach = u.user_id) " . $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();
         if ($access_url_id != -1) {
             $where .= " AND ar.access_url_id = {$access_url_id} ";
             $query = "{$select}\n                    FROM {$tbl_session} s\n                    LEFT JOIN {$tbl_session_field_values} fv ON (fv.session_id = s.id)\n                    LEFT JOIN {$tbl_session_field_options} fvo ON (fv.field_id = fvo.field_id)\n                    LEFT JOIN {$tbl_session_rel_course} src ON (src.id_session = s.id)\n                    LEFT JOIN {$tbl_course} c ON (src.c_id = c.id)\n                    LEFT JOIN {$tbl_session_category} sc ON (s.session_category_id = sc.id)\n                    INNER JOIN {$tbl_user} u ON (s.id_coach = u.user_id)\n                    INNER JOIN {$table_access_url_rel_session} ar ON (ar.session_id = s.id)\n                    {$where}";
         }
     }
     $query .= ") AS session_table";
     if (!empty($options['order'])) {
         $query .= " ORDER BY " . $options['order'];
     }
     //error_log($query);
     //echo $query;
     $result = Database::query($query);
     $formatted_sessions = array();
     if (Database::num_rows($result)) {
         $sessions = Database::store_result($result, 'ASSOC');
         foreach ($sessions as $session) {
             $session_id = $session['id'];
             $session['name'] = Display::url($session['name'], "resume_session.php?id_session=" . $session['id']);
             $session['coach_name'] = Display::url($session['coach_name'], "user_information.php?user_id=" . $session['user_id']);
             if ($session['session_active'] == 1) {
                 $session['session_active'] = Display::return_icon('accept.png', get_lang('Active'), array(), ICON_SIZE_SMALL);
             } else {
                 $session['session_active'] = Display::return_icon('error.png', get_lang('Inactive'), array(), ICON_SIZE_SMALL);
             }
             $session = self::convert_dates_to_local($session);
             switch ($session['visibility']) {
                 case SESSION_VISIBLE_READ_ONLY:
                     //1
                     $session['visibility'] = get_lang('ReadOnly');
                     break;
                 case SESSION_VISIBLE:
                     //2
                 //2
                 case SESSION_AVAILABLE:
                     //4
                     $session['visibility'] = get_lang('Visible');
                     break;
                 case SESSION_INVISIBLE:
                     //3
                     $session['visibility'] = api_ucfirst(get_lang('Invisible'));
                     break;
             }
             //Cleaning double selects
             foreach ($session as $key => &$value) {
                 if (isset($options_by_double[$key]) || isset($options_by_double[$key . '_second'])) {
                     $options = explode('::', $value);
                 }
                 $original_key = $key;
                 if (strpos($key, '_second') === false) {
                 } else {
                     $key = str_replace('_second', '', $key);
                 }
                 if (isset($options_by_double[$key])) {
                     if (isset($options[0])) {
                         if (isset($options_by_double[$key][$options[0]])) {
                             if (strpos($original_key, '_second') === false) {
                                 $value = $options_by_double[$key][$options[0]]['option_display_text'];
                             } else {
                                 $value = $options_by_double[$key][$options[1]]['option_display_text'];
                             }
                         }
                     }
                 }
             }
             //Magic filter
             if (isset($formatted_sessions[$session_id])) {
                 $formatted_sessions[$session_id] = self::compare_arrays_to_merge($formatted_sessions[$session_id], $session);
             } else {
                 $formatted_sessions[$session_id] = $session;
             }
         }
     }
     return $formatted_sessions;
 }
コード例 #4
0
ファイル: model.ajax.php プロジェクト: jloguercio/chamilo-lms
             $grade = "";
             if (!empty($arrGrade[$user['user_id']][$quizID]) || $arrGrade[$user['user_id']][$quizID] == 0) {
                 $finalScore += $grade = $arrGrade[$user['user_id']][$quizID];
             }
             $result[$i]['exer' . $j] = $grade;
             $j++;
         }
         if ($finalScore > 20) {
             $finalScore = 20;
         }
         $result[$i]['finalScore'] = number_format($finalScore, 2);
         $i++;
     }
     break;
 case 'get_extra_field_options':
     $obj = new ExtraFieldOption($type);
     $columns = array('display_text', 'option_value', 'option_order');
     $result = Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
     break;
 case 'get_usergroups_teacher':
     $columns = array('name', 'users', 'status', 'group_type', 'actions');
     $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}");
     $options['course_id'] = $course_id;
     switch ($type) {
         case 'not_registered':
             $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
             $result = $obj->getUserGroupNotInCourse($options, $groupFilter);
             break;
         case 'registered':
             $options['where'] = array(" usergroup.course_id = ? " => $course_id);
             $result = $obj->getUserGroupInCourse($options, $groupFilter);
コード例 #5
0
//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
         return \'<a href="?action=edit&' . $params . '&id=\'+options.rowId+\'">' . Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL) . '</a>' . '&nbsp;<a onclick="javascript:if(!confirm(' . "\\'" . addslashes(get_lang("ConfirmYourChoice")) . "\\'" . ')) return false;"  href="?sec_token=' . $token . '&action=delete&' . $params . '&id=\'+options.rowId+\'">' . Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>' . '\';
 }';
$htmlHeadXtra[] = '
<script>
$(function() {
    // grid definition see the $obj->display() function
    ' . Display::grid_js('extra_field_options', $url, $columns, $column_model, $extra_params, array(), $action_links, true) . '

});
</script>';
// The header.
Display::display_header($tool_name);
echo Display::page_header($extra_field_info['field_display_text']);
$obj = new ExtraFieldOption($extra_field->type);
$obj->field_id = $field_id;
// Action handling: Add
switch ($action) {
    case 'add':
        if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
            api_not_allowed();
        }
        $url = api_get_self() . '?action=' . Security::remove_XSS($_GET['action']) . '&' . $params;
        $form = $obj->return_form($url, 'add');
        // The validation or display
        if ($form->validate()) {
            if ($check) {
                $values = $form->exportValues();
                $res = $obj->save_one_item($values);
                if ($res) {
コード例 #6
0
 /**
  * @param array $options
  * @return array
  */
 public 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 (isset($extra_field_info['field_type']) && 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 (isset($info['field_type']) && $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 (isset($extra_field_info['field_type']) && 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);
 }
コード例 #7
0
     $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order');
     $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
     $new_result = array();
     if (!empty($result)) {
         foreach ($result as $item) {
             $item['field_type'] = $obj->get_field_type_by_id($item['field_type']);
             $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
             $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
             $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
             $new_result[] = $item;
         }
         $result = $new_result;
     }
     break;
 case 'get_extra_field_options':
     $obj = new ExtraFieldOption($type);
     $columns = array('option_display_text', 'option_value', 'option_order');
     $result = Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
     break;
 case 'get_usergroups_teacher':
     $columns = array('name', 'users', 'actions');
     $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}");
     $options['course_id'] = $course_id;
     switch ($type) {
         case 'not_registered':
             $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
             $result = $obj->get_usergroup_not_in_course($options);
             break;
         case 'registered':
             $options['where'] = array(" usergroup.course_id = ? " => $course_id);
             $result = $obj->get_usergroup_in_course($options);
コード例 #8
0
<?php

/* For licensing terms, see /license.txt */
//require_once '../global.inc.php';
$action = isset($_GET['a']) ? $_GET['a'] : '';
switch ($action) {
    case 'get_second_select_options':
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
        $option_value_id = isset($_REQUEST['option_value_id']) ? $_REQUEST['option_value_id'] : null;
        if (!empty($type) && !empty($field_id) && !empty($option_value_id)) {
            $field_options = new ExtraFieldOption($type);
            echo $field_options->get_second_select_field_options_by_field($field_id, $option_value_id, true);
        }
        break;
    case 'search_tags':
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
        $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : null;
        $extraFieldOption = new ExtraFieldOption($type);
        $result = [];
        $tags = Database::getManager()->getRepository('ChamiloCoreBundle:Tag')->createQueryBuilder('t')->where("t.tag LIKE :tag")->andWhere('t.fieldId = :field')->setParameter('field', $fieldId)->setParameter('tag', "{$tag}%")->getQuery()->getResult();
        foreach ($tags as $tag) {
            $result[] = ['caption' => $tag->getTag(), 'value' => $tag->getTag()];
        }
        echo json_encode($result);
        break;
    default:
        exit;
        break;
}
コード例 #9
0
 static function get_horario_value($session_id)
 {
     $extra_field_value = new ExtraFieldValue('session');
     //Getting horario info
     $extra_field = new ExtraField('session');
     $extra_field_info = $extra_field->get_handler_field_info_by_field_variable('horario');
     $horario_info = $extra_field_value->get_values_by_handler_and_field_id($session_id, $extra_field_info['id']);
     $extra_field_option = new ExtraFieldOption('session');
     $horario_info = $extra_field_option->get_field_option_by_field_and_option($extra_field_info['id'], $horario_info['field_value']);
     $time = "08:00";
     if (isset($horario_info) && isset($horario_info[0])) {
         $horario = $horario_info[0]['option_display_text'];
         $horario_array = explode(' ', $horario);
         //Schedule format is "(01) 07:00 09:00" in this case. Adapt to your case
         if (isset($horario_array[1])) {
             $time = $horario_array[1];
         }
     }
     return $time;
 }
コード例 #10
0
 /**
  * Helper function to create extra fields in the Chamilo database. If the
  * extra field aleady exists, then just return the ID of this field. If
  * options are provided ('options' sub-array), then options are inserted in
  * the corresponding x_field_options table.
  * @param Array An array containing an 'extra_fields' entry with details about the required extra fields
  * @return void
  */
 private function _create_extra_fields(&$table)
 {
     $extra_fields = array();
     error_log('Inserting (if not exist) extra fields for : ' . $table['dest_table'] . " \n");
     foreach ($table['extra_fields'] as $extra_field) {
         //error_log('Preparing for insertion of extra field ' . $extra_field['field_display_text'] . "\n");
         $options = isset($extra_field['options']) ? $extra_field['options'] : null;
         unset($extra_field['options']);
         $extra_field_obj = new ExtraField($table['dest_table']);
         $extra_field_id = $extra_field_obj->save($extra_field);
         $selected_fields = self::prepare_field_match($options);
         //Adding options. This is only processed if the corresponding
         // extra_field has an 'options' sub-aray defined
         if (!empty($options)) {
             $extra_field_option_obj = new ExtraFieldOption($table['dest_table']);
             // use the query defined in the 'query' item as returned in a select by prepare_field_match above
             $this->select_all($options['orig_table'], $selected_fields);
             $num_rows = $this->num_rows();
             if ($num_rows) {
                 $data_to_insert = array();
                 $data_to_insert['field_id'] = $extra_field_id;
                 while ($row = $this->fetch_array()) {
                     $data = self::execute_field_match($options, $row);
                     $data_to_insert = array_merge($data_to_insert, $data);
                     $extra_field_option_obj->save_one_item($data_to_insert, false, false);
                     //error_log(print_r($extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']], 1));
                     $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']]['options'][] = $data_to_insert;
                     $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']]['field_type'] = $extra_field['field_type'];
                 }
                 //$extra_fields[$table['dest_table']]['extra_field_'.$extra_field['field_variable']]['selected_option'] =
                 //error_log('$data: ' . print_r($data_to_insert, 1));
             }
         } else {
             // if there are no pre-defined options, then just return the field_id for this variable
             $extra_fields[$table['dest_table']]['extra_field_' . $extra_field['field_variable']] = $extra_field_id;
         }
     }
     return $extra_fields;
 }
コード例 #11
0
<?php

/* For licensing terms, see /license.txt */
$language_file = array('admin', 'registration', 'userInfo');
require_once '../global.inc.php';
$action = $_GET['a'];
switch ($action) {
    case 'get_second_select_options':
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
        $option_value_id = isset($_REQUEST['option_value_id']) ? $_REQUEST['option_value_id'] : null;
        if (!empty($type) && !empty($field_id) && !empty($option_value_id)) {
            $field_options = new ExtraFieldOption($type);
            echo $field_options->get_second_select_field_options_by_field($field_id, $option_value_id, true);
        }
        break;
    case 'search_tags':
        $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null;
        $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null;
        $tag = isset($_REQUEST['tag']) ? $_REQUEST['tag'] : null;
        $extraFieldOption = new ExtraFieldOption($type);
        echo $extraFieldOption->getSearchOptionsByField($tag, $fieldId, 10, 'json');
        break;
    default:
        exit;
        break;
}
exit;
コード例 #12
0
 /**
  * @param Application $app
  * @return string
  */
 public function indexAction(Application $app)
 {
     $request = $app['request'];
     $language_file = array('admin', 'exercice', 'gradebook', 'tracking');
     // 1. Setting variables needed by jqgrid
     $action = $request->get('a');
     $page = $request->get('page');
     //page
     $limit = $request->get('rows');
     //quantity of rows
     $sidx = $request->get('sidx');
     //index (field) to filter
     $sord = $request->get('sord');
     //asc or desc
     if (strpos(strtolower($sidx), 'asc') !== false) {
         $sidx = str_replace(array('asc', ','), '', $sidx);
         $sord = 'asc';
     }
     if (strpos(strtolower($sidx), 'desc') !== false) {
         $sidx = str_replace(array('desc', ','), '', $sidx);
         $sord = 'desc';
     }
     if (!in_array($sord, array('asc', 'desc'))) {
         $sord = 'desc';
     }
     if (!in_array($action, array('get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_user_skill_ranking', 'get_usergroups_teacher', 'get_question_list', 'get_user_list_plugin_widescale'))) {
         api_protect_admin_script(true);
     }
     if ($action == 'get_user_list_plugin_widescale') {
         $allowed = api_is_drh() || api_is_platform_admin();
         if (!$allowed) {
             api_not_allowed();
         }
     }
     // Search features.
     // If there is no search request sent by jqgrid, $where should be empty.
     $where_condition = "";
     $operation = $request->get('oper');
     $export_format = $request->get('export_format');
     $search_field = $request->get('searchField');
     $search_oper = $request->get('searchOper');
     $search_string = $request->get('searchString');
     $isSearch = $request->get('_search');
     $filters = $request->get('filters');
     $type = $request->get('type');
     $extra_fields = array();
     $questionFields = array();
     if ($isSearch == 'true') {
         $where_condition = ' 1 = 1 ';
         $where_condition_in_form = $this->getWhereClause($search_field, $search_oper, $search_string);
         if (!empty($where_condition_in_form)) {
             $where_condition .= ' AND ' . $where_condition_in_form;
         }
         $filters = isset($filters) ? json_decode($filters) : false;
         // for now
         if (!empty($filters)) {
             switch ($action) {
                 case 'get_questions':
                     $extraFieldtype = 'question';
                     break;
                 case 'get_sessions':
                     $extraFieldtype = 'session';
                     break;
             }
             // Extra field.
             $extraField = new \ExtraField($extraFieldtype);
             $result = $extraField->getExtraFieldRules($filters, 'extra_');
             $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 .= ' ) ';
             }
             // Question field.
             $resultQuestion = $extraField->getExtraFieldRules($filters, 'question_');
             $questionFields = $resultQuestion['extra_fields'];
             $condition_array = $resultQuestion['condition_array'];
             if (!empty($condition_array)) {
                 $where_condition .= ' AND ( ';
                 $where_condition .= implode($filters->groupOp, $condition_array);
                 $where_condition .= ' ) ';
             }
         }
     }
     // get index row - i.e. user click to sort $sord = $_GET['sord'];
     // get the direction
     if (!$sidx) {
         $sidx = 1;
     }
     //2. Selecting the count FIRST
     //@todo rework this
     switch ($action) {
         case 'get_questions':
             $categoryId = $request->get('categoryId');
             $exerciseId = $request->get('exerciseId');
             //$courseId = null; //$request->get('courseId');
             $courseId = $request->get('courseId');
             // Question manager can view all questions
             if (api_is_question_manager()) {
                 $courseId = null;
             }
             $count = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'extra' => $extra_fields, 'question' => $questionFields), true);
             break;
         case 'get_user_list_plugin_widescale':
             $count = \UserManager::get_user_data(null, null, null, null, true);
             break;
         case 'get_question_list':
             require_once api_get_path(SYS_CODE_PATH) . 'exercice/exercise.class.php';
             $exerciseId = $request->get('exerciseId');
             $exercise = new \Exercise(api_get_course_int_id());
             $exercise->read($exerciseId);
             $count = $exercise->selectNbrQuestions();
             break;
         case 'get_group_reporting':
             $course_id = $request->get('course_id');
             $group_id = $request->get('gidReq');
             $count = \Tracking::get_group_reporting($course_id, $group_id, 'count');
             break;
         case 'get_user_course_report_resumed':
             $count = \CourseManager::get_count_user_list_from_course_code(true, 'ruc');
             break;
         case 'get_user_course_report':
             $count = \CourseManager::get_count_user_list_from_course_code(false);
             break;
         case 'get_course_exercise_medias':
             $course_id = api_get_course_int_id();
             $count = \Question::get_count_course_medias($course_id);
             break;
         case 'get_user_skill_ranking':
             $skill = new \Skill();
             $count = $skill->get_user_list_skill_ranking_count();
             break;
         case 'get_work_user_list':
             require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php';
             $work_id = $request->get('work_id');
             //$_REQUEST['work_id'];
             $count = get_count_work($work_id);
             break;
         case 'get_exercise_results':
             $exercise_id = $request->get('exerciseId');
             //$_REQUEST['exerciseId'];
             $filter_by_user = $request->get('filter_by_user');
             if (isset($filter_by_user) && !empty($filter_by_user)) {
                 $filter_user = intval($filter_by_user);
                 if ($where_condition == "") {
                     $where_condition .= " te.exe_user_id  = '{$filter_user}'";
                 } else {
                     $where_condition .= " AND te.exe_user_id  = '{$filter_user}'";
                 }
             }
             $count = \ExerciseLib::get_count_exam_results($exercise_id, $where_condition);
             break;
         case 'get_hotpotatoes_exercise_results':
             $hotpot_path = $request->get('path');
             //$_REQUEST['path'];
             $count = \ExerciseLib::get_count_exam_hotpotatoes_results($hotpot_path);
             break;
         case 'get_sessions':
             $list_type = $request->get('list_type');
             if ($list_type == 'simple' || empty($list_type)) {
                 $count = \SessionManager::get_sessions_admin(array('where' => $where_condition, 'extra' => $extra_fields), true);
             } else {
                 $count = \SessionManager::get_count_admin_complete(array('where' => $where_condition, 'extra' => $extra_fields));
             }
             break;
         case 'get_extra_fields':
             $obj = new \ExtraField($type);
             $count = $obj->get_count();
             break;
         case 'get_extra_field_options':
             $field_id = $request->get('field_id');
             $obj = new \ExtraFieldOption($type);
             $count = $obj->get_count_by_field_id($field_id);
             break;
         case 'get_timelines':
             $obj = new \Timeline();
             $count = $obj->get_count();
             break;
         case 'get_gradebooks':
             $obj = new \Gradebook();
             $count = $obj->get_count();
             break;
         case 'get_event_email_template':
             $obj = new \EventEmailTemplate();
             $count = $obj->get_count();
             break;
         case 'get_careers':
             $obj = new \Career();
             $count = $obj->get_count();
             break;
         case 'get_promotions':
             $obj = new \Promotion();
             $count = $obj->get_count();
             break;
         case 'get_grade_models':
             $obj = new \GradeModel();
             $count = $obj->get_count();
             break;
         case 'get_usergroups':
             $obj = new \UserGroup();
             $count = $obj->get_count();
             break;
         case 'get_usergroups_teacher':
             $obj = new \UserGroup();
             $course_id = api_get_course_int_id();
             if ($type == 'registered') {
                 $count = $obj->get_usergroup_by_course_with_data_count($course_id);
             } else {
                 $count = $obj->get_count();
             }
             break;
         default:
             exit;
     }
     //3. Calculating first, end, etc
     $total_pages = 0;
     if ((int) $count > 0) {
         if (!empty($limit)) {
             $total_pages = ceil($count / $limit);
         }
     }
     if ($page > $total_pages) {
         $page = $total_pages;
     }
     $start = $limit * $page - $limit;
     if ($start < 0) {
         $start = 0;
     }
     //4. Deleting an element if the user wants to
     if ($operation == 'del') {
         $obj->delete($request->get('id'));
     }
     $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 = \Question::getQuestionColumns(api_get_course_id(), $extra_fields, $questionFields, true);
             $columns = $columns['simple_column_name'];
             $result = \Question::getQuestions($app, $categoryId, $exerciseId, $courseId, array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'question' => $questionFields, 'limit' => "{$start} , {$limit}"));
             //var_dump($result);
             break;
         case 'get_user_list_plugin_widescale':
             $columns = array('username', 'firstname', 'lastname', 'exam_password');
             $column_names = array(get_lang('Username'), get_lang('Firstname'), get_lang('Lastname'), get_lang('Password'));
             $result = \UserManager::get_user_data($start, $limit, $sidx, $sord);
             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);
             }
             break;
         case 'get_group_reporting':
             $columns = array('name', 'time', 'progress', 'score', 'works', 'messages', 'actions');
             $result = \Tracking::get_group_reporting($course_id, $group_id, 'all', $start, $limit, $sidx, $sord, $where_condition);
             break;
         case 'get_course_exercise_medias':
             $columns = array('question');
             $result = \Question::get_course_medias($course_id, $start, $limit, $sidx, $sord, $where_condition);
             if (!empty($result)) {
                 foreach ($result as &$media) {
                     $media['id'] = $media['iid'];
                 }
             }
             break;
         case 'get_user_course_report_resumed':
             $columns = array('extra_ruc', 'training_hours', 'count_users', 'count_users_registered', 'average_hours_per_user', 'count_certificates');
             $column_names = array(get_lang('Company'), get_lang('TrainingHoursAccumulated'), get_lang('CountOfSubscriptions'), get_lang('CountOfUsers'), get_lang('AverageHoursPerStudent'), get_lang('CountCertificates'));
             $result = \CourseManager::get_user_list_from_course_code(null, null, "LIMIT {$start}, {$limit}", " {$sidx} {$sord}", null, null, true, true, 'ruc');
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $row) {
                     $row['training_hours'] = api_time_to_hms($row['training_hours']);
                     $row['average_hours_per_user'] = api_time_to_hms($row['average_hours_per_user']);
                     $new_result[] = $row;
                 }
                 $result = $new_result;
             }
             break;
         case 'get_user_course_report':
             $columns = array('course', 'user', 'time', 'certificate', 'progress_100', 'progress');
             $column_names = array(get_lang('Course'), get_lang('User'), get_lang('ManHours'), get_lang('CertificateGenerated'), get_lang('Approved'), get_lang('CourseAdvance'));
             $extra_fields = \UserManager::get_extra_fields(0, 100, null, null, true, true);
             if (!empty($extra_fields)) {
                 foreach ($extra_fields as $extra) {
                     $columns[] = $extra['1'];
                     $column_names[] = $extra['3'];
                 }
             }
             $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);
             $result = \ArrayClass::msort($result, 'skills_acquired', 'asc');
             $skills_in_course = array();
             if (!empty($result)) {
                 //$counter = 1;
                 foreach ($result as &$item) {
                     $user_info = api_get_user_info($item['user_id']);
                     $personal_course_list = \UserManager::get_personal_session_course_list($item['user_id']);
                     $count_skill_by_course = array();
                     foreach ($personal_course_list as $course_item) {
                         if (!isset($skills_in_course[$course_item['code']])) {
                             $count_skill_by_course[$course_item['code']] = $skill->get_count_skills_by_course($course_item['code']);
                             $skills_in_course[$course_item['code']] = $count_skill_by_course[$course_item['code']];
                         } else {
                             $count_skill_by_course[$course_item['code']] = $skills_in_course[$course_item['code']];
                         }
                     }
                     $item['photo'] = \Display::img($user_info['avatar_small']);
                     $item['currently_learning'] = !empty($count_skill_by_course) ? array_sum($count_skill_by_course) : 0;
                 }
             }
             break;
         case 'get_work_user_list':
             if (isset($type) && $type == 'simple') {
                 $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'qualification', 'sent_date', 'qualificator_id', 'actions');
             } else {
                 $columns = array('type', 'firstname', 'lastname', 'username', 'title', 'sent_date', 'actions');
             }
             $result = get_work_user_list($start, $limit, $sidx, $sord, $work_id, $where_condition);
             break;
         case 'get_exercise_results':
             $course = api_get_course_info();
             //used inside get_exam_results_data()
             $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
             if ($is_allowedToEdit) {
                 $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions');
             } else {
                 //$columns = array('exe_duration', 'start_date', 'exe_date', 'score', 'status', 'actions');
             }
             $result = \ExerciseLib::get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
             break;
         case 'get_hotpotatoes_exercise_results':
             $course = api_get_course_info();
             //used inside get_exam_results_data()
             $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document";
             $columns = array('firstname', 'lastname', 'username', 'group_name', 'exe_date', 'score', 'actions');
             $result = ExerciseLib::get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition);
             //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
             break;
         case 'get_sessions':
             $session_columns = \SessionManager::get_session_columns($list_type);
             $columns = $session_columns['simple_column_name'];
             if ($list_type == 'simple') {
                 $result = SessionManager::get_sessions_admin(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"), false);
             } else {
                 $result = SessionManager::get_sessions_admin_complete(array('where' => $where_condition, 'order' => "{$sidx} {$sord}", 'extra' => $extra_fields, 'limit' => "{$start} , {$limit}"));
             }
             break;
         case 'get_timelines':
             $columns = array('headline', 'actions');
             //$columns = array('headline', 'type', 'start_date', 'end_date', 'text', 'media', 'media_credit', 'media_caption', 'title_slide', 'parent_id');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'headline';
             }
             $course_id = api_get_course_int_id();
             $result = Database::select('*', $obj->table, array('where' => array('parent_id = ? AND c_id = ?' => array('0', $course_id)), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $item['headline'] = Display::url($item['headline'], api_get_path(WEB_CODE_PATH) . 'timeline/view.php?id=' . $item['id']);
                 $item['actions'] = Display::url(Display::return_icon('add.png', get_lang('AddItems')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=add_item&parent_id=' . $item['id']);
                 $item['actions'] .= Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=edit&id=' . $item['id']);
                 $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'timeline/?action=delete&id=' . $item['id']);
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_gradebooks':
             $columns = array('name', 'certificates', 'skills', 'actions', 'has_certificates');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if ($item['parent_id'] != 0) {
                     continue;
                 }
                 $skills = $obj->get_skills_by_gradebook($item['id']);
                 //Fixes bug when gradebook doesn't have names
                 if (empty($item['name'])) {
                     $item['name'] = $item['course_code'];
                 } else {
                     //$item['name'] =  $item['name'].' ['.$item['course_code'].']';
                 }
                 $item['name'] = Display::url($item['name'], api_get_path(WEB_CODE_PATH) . 'gradebook/index.php?id_session=0&cidReq=' . $item['course_code']);
                 if (!empty($item['certif_min_score']) && !empty($item['document_id'])) {
                     $item['certificates'] = Display::return_icon('accept.png', get_lang('WithCertificate'), array(), ICON_SIZE_SMALL);
                     $item['has_certificates'] = '1';
                 } else {
                     $item['certificates'] = Display::return_icon('warning.png', get_lang('NoCertificate'), array(), ICON_SIZE_SMALL);
                     $item['has_certificates'] = '0';
                 }
                 if (!empty($skills)) {
                     foreach ($skills as $skill) {
                         $item['skills'] .= Display::span($skill['name'], array('class' => 'label_tag skill'));
                     }
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_event_email_template':
             $columns = array('subject', 'event_type_name', 'language_id', 'activated', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'subject';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 $language_info = api_get_language_info($item['language_id']);
                 $item['language_id'] = $language_info['english_name'];
                 $item['actions'] = Display::url(Display::return_icon('edit.png', get_lang('Edit')), api_get_path(WEB_CODE_PATH) . 'admin/event_type.php?action=edit&event_type_name=' . $item['event_type_name']);
                 $item['actions'] .= Display::url(Display::return_icon('delete.png', get_lang('Delete')), api_get_path(WEB_CODE_PATH) . 'admin/event_controller.php?action=delete&id=' . $item['id']);
                 /*if (!$item['status']) {
                       $item['name'] = '<font style="color:#AAA">'.$item['subject'].'</font>';
                   }*/
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_careers':
             $columns = array('name', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_promotions':
             $columns = array('name', 'career', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('p.id,p.name, p.description, c.name as career, p.status', "{$obj->table} p LEFT JOIN " . Database::get_main_table(TABLE_CAREER) . " c  ON c.id = p.career_id ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 if (!$item['status']) {
                     $item['name'] = '<font style="color:#AAA">' . $item['name'] . '</font>';
                 }
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_grade_models':
             $columns = array('name', 'description', 'actions');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             $result = Database::select('*', "{$obj->table} ", array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             foreach ($result as $item) {
                 $new_result[] = $item;
             }
             $result = $new_result;
             break;
         case 'get_usergroups':
             $columns = array('name', 'users', 'courses', 'sessions', 'group_type', 'actions');
             $result = Database::select('*', $obj->table, array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $group) {
                     $group['sessions'] = count($obj->get_sessions_by_usergroup($group['id']));
                     $group['courses'] = count($obj->get_courses_by_usergroup($group['id']));
                     $group['users'] = count($obj->get_users_by_usergroup($group['id']));
                     switch ($group['group_type']) {
                         case '0':
                             $group['group_type'] = Display::label(get_lang('Class'), 'info');
                             break;
                         case '1':
                             $group['group_type'] = Display::label(get_lang('Social'), 'success');
                             break;
                     }
                     $new_result[] = $group;
                 }
                 $result = $new_result;
             }
             $columns = array('name', 'users', 'courses', 'sessions', 'group_type');
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             //Multidimensional sort
             ArrayClass::msort($result, $sidx);
             break;
         case 'get_extra_fields':
             $obj = new \ExtraField($type);
             $columns = array('field_display_text', 'field_variable', 'field_type', 'field_changeable', 'field_visible', 'field_filter', 'field_order');
             $result = \Database::select('*', $obj->table, array('order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $item) {
                     $item['field_type'] = $obj->get_field_type_by_id($item['field_type']);
                     $item['field_changeable'] = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $item['field_visible'] = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $item['field_filter'] = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                     $new_result[] = $item;
                 }
                 $result = $new_result;
             }
             break;
         case 'get_extra_field_options':
             $obj = new \ExtraFieldOption($type);
             $columns = array('option_display_text', 'option_value', 'option_order');
             $result = \Database::select('*', $obj->table, array('where' => array("field_id = ? " => $field_id), 'order' => "{$sidx} {$sord}", 'LIMIT' => "{$start} , {$limit}"));
             /*$new_result = array();
               if (!empty($result)) {
                   foreach ($result as $item) {
                       $item['field_type']         = $obj->get_field_type_by_id($item['field_type']);
                       $item['field_changeable']   = $item['field_changeable'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $item['field_visible']      = $item['field_visible'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $item['field_filter']       = $item['field_filter'] ? Display::return_icon('right.gif') : Display::return_icon('wrong.gif');
                       $new_result[]        = $item;
                   }
                   $result = $new_result;
               }*/
             break;
         case 'get_usergroups_teacher':
             $columns = array('name', 'users', 'actions');
             $options = array('order' => "name {$sord}", 'LIMIT' => "{$start} , {$limit}");
             $options['course_id'] = $course_id;
             switch ($type) {
                 case 'not_registered':
                     $options['where'] = array(" (course_id IS NULL OR course_id != ?) " => $course_id);
                     $result = $obj->get_usergroup_not_in_course($options);
                     break;
                 case 'registered':
                     $options['where'] = array(" usergroup.course_id = ? " => $course_id);
                     $result = $obj->get_usergroup_in_course($options);
                     break;
             }
             $new_result = array();
             if (!empty($result)) {
                 foreach ($result as $group) {
                     $group['users'] = count($obj->get_users_by_usergroup($group['id']));
                     if ($obj->usergroup_was_added_in_course($group['id'], $course_id)) {
                         $url = 'class.php?action=remove_class_from_course&id=' . $group['id'];
                         $icon = Display::return_icon('delete.png', get_lang('Remove'));
                     } else {
                         $url = 'class.php?action=add_class_to_course&id=' . $group['id'];
                         $icon = Display::return_icon('add.png', get_lang('Add'));
                     }
                     $group['actions'] = Display::url($icon, $url);
                     $new_result[] = $group;
                 }
                 $result = $new_result;
             }
             if (!in_array($sidx, $columns)) {
                 $sidx = 'name';
             }
             //Multidimensional sort
             \ArrayClass::msort($result, $sidx);
             break;
         default:
             exit;
     }
     $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_usergroups_teacher', 'get_gradebooks', 'get_sessions', 'get_exercise_results', 'get_hotpotatoes_exercise_results', 'get_work_user_list', 'get_timelines', 'get_grade_models', 'get_event_email_template', 'get_user_skill_ranking', 'get_extra_fields', 'get_extra_field_options', 'get_course_exercise_medias', 'get_user_course_report', 'get_user_course_report_resumed', 'get_group_reporting', 'get_question_list', 'get_user_list_plugin_widescale', 'get_questions');
     //5. Creating an obj to return a json
     if (in_array($action, $allowed_actions)) {
         $response = new \stdClass();
         $response->page = $page;
         $response->total = $total_pages;
         $response->records = $count;
         if ($operation && $operation == 'excel') {
             $j = 1;
             $array = array();
             if (empty($column_names)) {
                 $column_names = $columns;
             }
             //Headers
             foreach ($column_names as $col) {
                 $array[0][] = $col;
             }
             foreach ($result as $row) {
                 foreach ($columns as $col) {
                     $array[$j][] = strip_tags($row[$col]);
                 }
                 $j++;
             }
             switch ($export_format) {
                 case 'xls':
                     Export::export_table_xls($array, 'company_report');
                     break;
                 case 'csv':
                 default:
                     Export::export_table_csv($array, 'company_report');
                     break;
             }
             exit;
         }
         $i = 0;
         if (!empty($result)) {
             foreach ($result as $row) {
                 //print_r($row);
                 // if results tab give not id, set id to $i otherwise id="null" for all <tr> of the jqgrid - ref #4235
                 if (!isset($row['id']) || isset($row['id']) && $row['id'] == "") {
                     $response->rows[$i]['id'] = $i;
                 } else {
                     $response->rows[$i]['id'] = $row['id'];
                 }
                 $array = array();
                 foreach ($columns as $col) {
                     $array[] = isset($row[$col]) ? $row[$col] : null;
                 }
                 $response->rows[$i]['cell'] = $array;
                 $i++;
             }
         }
         return json_encode($response);
     }
 }
コード例 #13
0
 public function __construct()
 {
     parent::__construct('session');
 }