Example #1
0
 /**
  * Load primary key from values
  */
 public final function load_pk(&$values)
 {
     $this->pk = [];
     $this->full_pk = true;
     if (!empty($this->collection_object)) {
         foreach ($this->collection_object->data['pk'] as $v) {
             if (isset($values[$v])) {
                 $temp = object_table_columns::process_single_column_type($v, $this->collection_object->primary_model->columns[$v], $values[$v]);
                 if (!empty($temp[$v])) {
                     // pk can not be empty
                     $this->pk[$v] = $temp[$v];
                 } else {
                     $this->full_pk = false;
                 }
             } else {
                 $this->full_pk = false;
             }
         }
     } else {
         $this->full_pk = false;
     }
 }
Example #2
0
 /**
  * Format filter string as human readable
  *
  * @param object $object
  * @return array
  */
 public static function human($object)
 {
     $input = $object->options['input'];
     $filter = $object->filter;
     $full_text_search = $filter['full_text_search'] ?? null;
     unset($filter['full_text_search']);
     // generate values
     $result = [];
     foreach ($filter as $k => $v) {
         if (!empty($v['range'])) {
             $start = object_table_columns::process_single_column($k, $v, $input['filter'] ?? [], ['process_domains' => true, 'ignore_defaults' => true, 'ignore_not_set_fields' => true]);
             $end = object_table_columns::process_single_column($k . '2', $v, $input['filter'] ?? [], ['process_domains' => true, 'ignore_defaults' => true, 'ignore_not_set_fields' => true]);
             $result[i18n(null, $v['name'])] = '(' . ($start[$k] ?? null) . ') - (' . ($end[$k . '2'] ?? null) . ')';
         } else {
             $start = object_table_columns::process_single_column($k, $v, $input['filter'] ?? [], ['process_domains' => true, 'ignore_defaults' => true, 'ignore_not_set_fields' => true]);
             // we need to process arrays
             if (isset($start[$k]) && is_array($start[$k])) {
                 if (!empty($v['options_model'])) {
                     $params = $v['options_params'] ?? [];
                     $start[$k] = array_options_to_string(factory::model($v['options_model'])->options(['where' => $params, 'i18n' => true]), $start[$k]);
                 } else {
                     $start[$k] = implode(', ', $start[$k]);
                 }
             }
             $result[i18n(null, $v['name'])] = $start[$k] ?? null;
         }
     }
     // full text search
     if (!empty($full_text_search)) {
         $names = [];
         foreach ($full_text_search as $v) {
             $names[] = i18n(null, $filter[$v]['name']);
         }
         $result[i18n(null, 'Text Search')] = ($input['filter']['full_text_search'] ?? null) . ' (' . implode(', ', $names) . ')';
     }
     return $result;
 }
Example #3
0
 /**
  * Convert input into array
  *
  * @param array $data
  * @param array $options
  *		boolean ignore_not_set_fields
  *		boolean skip_type_validation
  * @return array
  */
 public function process_columns(&$data, $options = [])
 {
     $save = [];
     foreach ($this->columns as $k => $v) {
         if (!empty($options['ignore_not_set_fields']) && !array_key_exists($k, $data)) {
             continue;
         }
         if (empty($options['skip_type_validation'])) {
             $temp = object_table_columns::process_single_column_type($k, $v, $data[$k] ?? null);
             if (array_key_exists($k, $temp)) {
                 $save[$k] = $temp[$k];
             }
         } else {
             $save[$k] = $data[$k];
         }
     }
     $data = $save;
 }