コード例 #1
0
 /**
  * Returns the value of the given extra field on the given resource
  * @param int $item_id Item ID (It could be a session_id, course_id or user_id)
  * @param int $field_id Field ID (the ID from the *_field table)
  * @param bool $transform Whether to transform the result to a human readable strings
  * @return mixed A structured array with the field_id and field_value, or false on error
  * @assert (-1,-1) === false
  */
 public function get_values_by_handler_and_field_id($item_id, $field_id, $transform = false)
 {
     $field_id = intval($field_id);
     $item_id = Database::escape_string($item_id);
     $sql = "SELECT s.*, field_type FROM {$this->table} s\n                INNER JOIN {$this->table_handler_field} sf ON (s.field_id = sf.id)\n                WHERE\n                    item_id = '{$item_id}' AND\n                    field_id = '" . $field_id . "' AND\n                    sf.extra_field_type = " . $this->getExtraField()->getExtraFieldType() . "\n                ORDER BY id";
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         $result = Database::fetch_array($result, 'ASSOC');
         if ($transform) {
             if (!empty($result['value'])) {
                 switch ($result['field_type']) {
                     case ExtraField::FIELD_TYPE_DOUBLE_SELECT:
                         $field_option = new ExtraFieldOption($this->type);
                         $options = explode('::', $result['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['value'] = $result['display_text'] . ' -> ';
                             $result['value'] .= $result_second['display_text'];
                         }
                         break;
                     case ExtraField::FIELD_TYPE_SELECT:
                         $field_option = new ExtraFieldOption($this->type);
                         $extra_field_option_result = $field_option->get_field_option_by_field_and_option($result['field_id'], $result['value']);
                         if (isset($extra_field_option_result[0])) {
                             $result['value'] = $extra_field_option_result[0]['display_text'];
                         }
                         break;
                 }
             }
         }
         return $result;
     } else {
         return false;
     }
 }
コード例 #2
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;
 }