/** * 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']); } }