Example #1
0
 /**
  * Override insert() to add child records to the same lot as parent
  */
 public function insert($pa_options = null)
 {
     if ($vn_parent_id = $this->get('parent_id')) {
         $t_parent = new ca_objects();
         if ($this->inTransaction()) {
             $t_parent->setTransaction($this->getTransaction());
         }
         if ($t_parent->load($vn_parent_id) && ($vn_lot_id = $t_parent->get('lot_id'))) {
             $this->set('lot_id', $vn_lot_id);
         }
     }
     return parent::insert($pa_options);
 }
Example #2
0
 public function insert($pa_options = null)
 {
     if (!$this->inTransaction()) {
         $this->setTransaction(new Transaction());
     }
     if ($this->get('is_default')) {
         $this->getDb()->query("\n\t\t\t\tUPDATE ca_list_items \n\t\t\t\tSET is_default = 0 \n\t\t\t\tWHERE list_id = ?\n\t\t\t", (int) $this->get('list_id'));
     }
     $vn_rc = parent::insert($pa_options);
     if ($this->getPrimaryKey()) {
         $t_list = new ca_lists();
         $o_trans = $this->getTransaction();
         $t_list->setTransaction($o_trans);
         if ($t_list->load($this->get('list_id')) && $t_list->get('list_code') == 'place_hierarchies' && $this->get('parent_id')) {
             // insert root or place hierarchy when creating non-root items in 'place_hierarchies' list
             $t_locale = new ca_locales();
             $va_locales = $this->getAppConfig()->getList('locale_defaults');
             $vn_locale_id = $t_locale->localeCodeToID($va_locales[0]);
             // create root in ca_places
             $t_place = new ca_places();
             $t_place->setTransaction($o_trans);
             $t_place->setMode(ACCESS_WRITE);
             $t_place->set('hierarchy_id', $this->getPrimaryKey());
             $t_place->set('locale_id', $vn_locale_id);
             $t_place->set('type_id', null);
             $t_place->set('parent_id', null);
             $t_place->set('idno', 'Root node for ' . $this->get('idno'));
             $t_place->insert();
             if ($t_place->numErrors()) {
                 $this->delete();
                 $this->errors = array_merge($this->errors, $t_place->errors);
                 return false;
             }
             $t_place->addLabel(array('name' => 'Root node for ' . $this->get('idno')), $vn_locale_id, null, true);
         }
     }
     if ($this->numErrors()) {
         $this->getTransaction()->rollback();
     } else {
         $this->getTransaction()->commit();
         $this->_setSettingsForList();
     }
     return $vn_rc;
 }
 public function insert($pa_options = null)
 {
     $vb_web_set_transaction = false;
     if (!$this->inTransaction()) {
         $this->setTransaction(new Transaction($this->getDb()));
         $vb_web_set_transaction = true;
     }
     $o_trans = $this->getTransaction();
     if (!strlen($this->get('is_enabled'))) {
         $this->set('is_enabled', 1);
     }
     $vn_rc = parent::insert($pa_options);
     if ($this->numErrors()) {
         if ($vb_web_set_transaction) {
             $o_trans->rollback();
         }
     } else {
         if ($vb_web_set_transaction) {
             $o_trans->commit();
         }
     }
     return $vn_rc;
 }