/** * Process single column * * @param string $column_name * @param array $column_options * @param array $data * @param array $options * @return array */ public static function process_single_column($column_name, $column_options, $data, $options = []) { $result = []; // process domain if (!empty($options['process_domains'])) { $temp = [$column_name => $column_options]; $temp = object_data_common::process_domains($temp); $column_options = $temp[$column_name]; } // if we ignoring not set fields if (!empty($options['ignore_not_set_fields']) && !array_key_exists($column_name, $data)) { return $result; } // processing $value = $data[$column_name] ?? null; if (is_array($value)) { $result2 = []; foreach ($value as $k => $v) { $temp = self::process_single_column_type($column_name, $column_options, $v, ['ignore_defaults' => $options['ignore_defaults'] ?? false]); if (array_key_exists($column_name, $temp) && $temp[$column_name] !== null) { $result2[] = $temp[$column_name]; } } $result[$column_name] = $result2; } else { $result = self::process_single_column_type($column_name, $column_options, $value, ['ignore_defaults' => $options['ignore_defaults'] ?? false]); } return $result; }
/** * Add element to the row * * @param string $container_link * @param string $row_link * @param string $element_link * @param array $options */ public function element($container_link, $row_link, $element_link, $options = []) { // presetting options for buttons, making them last if (in_array($row_link, [$this::buttons, $this::batch_buttons])) { $options['row_type'] = 'grid'; if (!isset($options['row_order'])) { $options['row_order'] = PHP_INT_MAX - 500; } } // processing row and container $this->container($container_link, array_key_extract_by_prefix($options, 'container_')); $this->row($container_link, $row_link, array_key_extract_by_prefix($options, 'row_')); // setting value if (!isset($this->data[$container_link]['rows'][$row_link]['elements'][$element_link])) { if (!empty($options['container'])) { $this->data[$options['container']]['flag_child'] = true; $type = 'tab'; $container = $options['container']; // need to add a container to the tabs $this->misc_settings['tabs'][$container] = $this->data[$container_link]['rows'][$row_link]['options']['label_name']; } else { // name & id if ($this->data[$container_link]['type'] == 'details' || $this->data[$container_link]['type'] == 'subdetails') { // details & subdetails $options['values_key'] = $options['error_name'] = $options['name'] = null; $options['id'] = null; $options['details_key'] = $this->data[$container_link]['options']['details_key']; $options['details_parent_key'] = $this->data[$container_link]['options']['details_parent_key'] ?? null; $options['details_field_name'] = $element_link; $options['details_collection_key'] = $this->data[$container_link]['options']['details_collection_key']; } else { // regular fields $options['error_name'] = $options['name'] = $element_link; $options['values_key'] = [$element_link]; $options['id'] = "form_{$this->form_link}_element_{$element_link}"; $options['details_collection_key'] = null; // we do not validate preset fields if (!empty($options['preset'])) { $options['options_manual_validation'] = true; $options['tree'] = true; $options['searchable'] = true; } } // multiple column if (!empty($options['multiple_column'])) { $options['details_collection_key'] = array_merge($options['details_collection_key'] ?? [], ['details', $element_link]); } // process domain & type $temp = object_data_common::process_domains(['options' => $options]); $options = $temp['options']; $options['row_link'] = $row_link; $options['container_link'] = $container_link; // fix boolean type if (($options['type'] ?? '') == 'boolean' && !isset($options['method'])) { $options['method'] = 'select'; $options['no_choose'] = true; $options['options_model'] = 'object_data_model_inactive'; $options['searchable'] = false; } // put data into fields array $field = ['id' => $options['id'], 'name' => $options['name'], 'options' => $options, 'order' => $options['order'] ?? 0, 'row_order' => $this->data[$container_link]['rows'][$row_link]['order']]; // we need to put values into fields and details $persistent_key = []; if ($this->data[$container_link]['type'] == 'details') { array_key_set($this->detail_fields, [$this->data[$container_link]['options']['details_key'], 'elements', $element_link], $field); array_key_set($this->detail_fields, [$this->data[$container_link]['options']['details_key'], 'options'], $this->data[$container_link]['options']); // details_unique_select if (!empty($field['options']['details_unique_select'])) { $this->misc_settings['details_unique_select'][$this->data[$container_link]['options']['details_key']][$element_link] = []; } // persistent $persistent_key[] = 'details'; $persistent_key[] = $this->data[$container_link]['options']['details_key']; $persistent_key[] = $element_link; } else { if ($this->data[$container_link]['type'] == 'subdetails') { $this->data[$container_link]['options']['container_link'] = $container_link; array_key_set($this->detail_fields, [$this->data[$container_link]['options']['details_parent_key'], 'subdetails', $this->data[$container_link]['options']['details_key'], 'elements', $element_link], $field); array_key_set($this->detail_fields, [$this->data[$container_link]['options']['details_parent_key'], 'subdetails', $this->data[$container_link]['options']['details_key'], 'options'], $this->data[$container_link]['options']); // details_unique_select if (!empty($field['options']['details_unique_select'])) { $this->misc_settings['details_unique_select'][$this->data[$container_link]['options']['details_parent_key'] . '::' . $this->data[$container_link]['options']['details_key']][$element_link] = []; } // persistent $persistent_key[] = 'subdetails'; $persistent_key[] = $this->data[$container_link]['options']['details_parent_key']; $persistent_key[] = $this->data[$container_link]['options']['details_key']; $persistent_key[] = $element_link; } else { // persistent array_key_set($this->fields, $element_link, $field); $persistent_key[] = 'fields'; $persistent_key[] = $element_link; } } // persistent if (!empty($field['options']['persistent']) && !empty($persistent_key)) { array_key_set($this->misc_settings['persistent'], $persistent_key, $field['options']['persistent']); } // type is field by default $type = 'field'; $container = null; // process submit elements if (!empty($options['process_submit'])) { $this->process_submit_all[$element_link] = false; } } // setting data $this->data[$container_link]['rows'][$row_link]['elements'][$element_link] = ['type' => $type, 'container' => $container, 'options' => $options, 'order' => $options['order'] ?? 0]; // we need to set few misc options if (!empty($options['options_model'])) { $temp = explode('::', $options['options_model']); $name = []; if (isset($this->misc_settings['tabs'][$container_link])) { $name[] = $this->misc_settings['tabs'][$container_link]; } $name[] = $options['label_name']; $this->misc_settings['option_models'][$element_link] = ['model' => $temp[0], 'field_code' => $element_link, 'field_name' => implode(': ', $name)]; } } else { $this->data[$container_link]['rows'][$row_link]['elements'][$element_link]['options'] = array_merge_hard($this->data[$container_link]['rows'][$row_link]['elements'][$element_link], $options); } }
/** * Constructing object * * @throws Exception */ public function __construct() { // we need to handle overrrides parent::override_handle($this); // we need to determine db link if (empty($this->db_link)) { // get from flags first if (!empty($this->db_link_flag)) { $this->db_link = application::get($this->db_link_flag); } // get default link if (empty($this->db_link)) { $this->db_link = application::get('flag.global.db.default_db_link'); } // if we could not determine the link we throw exception if (empty($this->db_link)) { throw new Exception('Could not determine db link in model!'); } } // processing table name $this->history_name = $this->name . '__history'; // process relations if we have a module if (!empty($this->relation) && application::get('dep.submodule.numbers.data.relations')) { // add a column if not exists if (empty($this->columns[$this->relation['field']])) { $this->columns[$this->relation['field']] = ['name' => 'Relation #', 'domain' => 'relation_id_sequence']; // add unique constraint $this->constraints[$this->relation['field'] . '_un'] = ['type' => 'unique', 'columns' => [$this->relation['field']]]; } } else { $this->relation = false; } // optimistic lock if ($this->optimistic_lock) { $this->optimistic_lock_column = $this->column_prefix . 'optimistic_lock'; $this->columns[$this->optimistic_lock_column] = ['name' => 'Optimistic Lock', 'domain' => 'optimistic_lock']; } // who if (!empty($this->who)) { foreach ($this->who as $k => $v) { $k = strtolower($k); $this->columns[$this->column_prefix . $k . '_timestamp'] = ['name' => ucwords($k) . ' Datetime', 'type' => 'timestamp', 'null' => $k != 'inserted']; $this->columns[$this->column_prefix . $k . '_entity_id'] = ['name' => ucwords($k) . ' Entity #', 'domain' => 'entity_id', 'null' => true]; } } // process domain in columns $this->columns = object_data_common::process_domains($this->columns); // schema & title $temp = explode('_', $this->name); if (empty($this->schema)) { $this->schema = $temp[0]; } unset($temp[0]); if (empty($this->title)) { $this->title = ucwords(implode(' ', $temp)); } // initialize db object $this->db_object = new db($this->db_link); // process widgets foreach (object_widgets::widget_models as $widget) { if (!object_widgets::enabled($widget)) { $this->{$widget} = false; } else { if ($this->{$widget}) { $temp = $widget . '_model'; $this->{$temp} = get_class($this) . '__virtual__' . $widget; } } } }
/** * Constructor */ public function __construct() { // we need to handle overrrides parent::override_handle($this); // we must have columns if (empty($this->columns)) { throw new Exception('object_data ' . get_called_class() . ' children must have columns!'); } // process domain in columns, we skip domain model $class = get_called_class(); if ($class != 'object_data_domains') { if ($class == 'object_data_types') { $this->columns = object_data_common::process_domains($this->columns, $this->data); } else { $this->columns = object_data_common::process_domains($this->columns); } } }
/** * Constructor * * @param string $list_link * @param array $options */ public function __construct($options = []) { $this->options = $options; // processing model if (!empty($this->model)) { $this->model_object = factory::model($this->model); } if (empty($this->columns) && !empty($this->model)) { $this->columns = $this->model_object->columns; } // check if we have columns if (empty($this->columns)) { throw new Exception('List must have columns!'); } // process domains foreach ($this->columns as $k => $v) { $temp = object_data_common::process_domains(['options' => $v]); $this->columns[$k] = $temp['options']; } // limit $limit = intval($options['input']['limit'] ?? 0); if ($limit > 0) { $this->limit = $limit; } // we need to set maximum limit if we are exporting if (!empty($this->options['input']['submit_export']) && !empty($this->options['input']['export']['format'])) { $this->limit = PHP_INT_MAX; } // offset $offset = intval($options['input']['offset'] ?? 0); if ($offset > 0) { $this->offset = $offset; } // filter $where = []; if (!empty($this->options['input']['filter'])) { $where = numbers_frontend_html_list_filter::where($this); if (!empty($where)) { $this->filtered = true; } } // sort if (!empty($this->options['input']['sort'])) { $this->orderby = []; foreach ($this->options['input']['sort'] as $k => $v) { if (!empty($v['column']) && !empty($this->columns[$v['column']])) { $this->orderby[$v['column']] = $v['order'] ?? SORT_ASC; } else { if (!empty($v['column']) && $v['column'] == 'full_text_search' && !empty($this->filter['full_text_search'])) { $this->orderby['full_text_search'] = $v['order'] ?? SORT_ASC; } } } } // datasources, count first if (empty($this->datasources['count']) && !empty($this->model)) { $this->datasources['count'] = ['model' => 'numbers_frontend_html_list_model_datasource_count', 'options' => ['model' => $this->model, 'where' => $where]]; } else { if (!empty($this->datasources['count'])) { $this->datasources['count'] = ['model' => $this->datasources['count'], 'options' => ['where' => $where]]; } } // datasources, data second if (empty($this->datasources['data']) && !empty($this->model)) { $this->datasources['data'] = ['model' => 'numbers_frontend_html_list_model_datasource_data', 'options' => ['model' => $this->model, 'offset' => $this->offset, 'limit' => $this->limit, 'orderby' => $this->orderby, 'where' => $where]]; } else { if (!empty($this->datasources['data'])) { $this->datasources['data'] = ['model' => $this->datasources['data'], 'options' => ['offset' => $this->offset, 'limit' => $this->limit, 'orderby' => $this->orderby, 'where' => $where]]; } } // actions if (!empty($this->options['actions'])) { $this->actions = array_merge($this->actions, $this->options['actions']); } }