Esempio n. 1
0
 /**
  * Add row to the container
  *
  * @param string $container_link
  * @param string $row_link
  * @param array $options
  */
 public function row($container_link, $row_link, $options = [])
 {
     $this->container($container_link, array_key_extract_by_prefix($options, 'container_'));
     if (!isset($this->data[$container_link]['rows'][$row_link])) {
         // hidden rows
         if ($row_link == $this::hidden) {
             $options['order'] = PHP_INT_MAX - 1000;
         }
         // validating row type
         $types = object_html_form_row_types::get_static();
         if (!isset($options['type']) || !isset($types[$options['type']])) {
             $options['type'] = $this->data[$container_link]['default_row_type'];
         }
         $options['container_link'] = $container_link;
         $options['row_link'] = $row_link;
         // setting values
         $this->data[$container_link]['rows'][$row_link] = ['type' => $options['type'], 'elements' => [], 'options' => $options, 'order' => $options['order'] ?? 0];
         // handling widgets
         if ($this->data[$container_link]['type'] == 'tabs' && !empty($options['widget'])) {
             $options['type'] = 'tabs';
             // we skip if widgets are not enabled
             if (!object_widgets::enabled($options['widget']) || !$this->process_widget($options)) {
                 unset($this->data[$container_link]['rows'][$row_link]);
                 return;
             }
         }
     } else {
         $this->data[$container_link]['rows'][$row_link]['options'] = array_merge_hard($this->data[$container_link]['rows'][$row_link]['options'], $options);
         if (isset($options['order'])) {
             $this->data[$container_link]['rows'][$row_link]['order'] = $options['order'];
         }
     }
 }
Esempio n. 2
0
 /**
  * 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;
             }
         }
     }
 }