Beispiel #1
0
 /**
  * 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);
         }
     }
 }
 /**
  * Constructing object
  *
  * @param $options
  */
 public function __construct($options = [])
 {
     // we need to handle overrrides
     parent::override_handle($this);
     // data can be passed in constructor
     if (!empty($options['data'])) {
         $this->data = $options['data'];
     }
     // primary model & pk
     $this->primary_model = factory::model($this->data['model']);
     $this->data['model_object'] =& $this->primary_model;
     $this->data['serial'] = false;
     if (empty($this->data['pk'])) {
         $this->data['pk'] = $this->primary_model->pk;
     }
     // if we have serial type in pk
     foreach ($this->data['pk'] as $v) {
         if (strpos($this->primary_model->columns[$v]['type'], 'serial') !== false) {
             $this->data['serial'] = true;
         }
     }
 }
Beispiel #3
0
 /**
  * Constructor
  */
 public function __construct()
 {
     // we need to handle overrrides
     parent::override_handle($this);
 }
Beispiel #4
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;
             }
         }
     }
 }