public function store()
 {
     if (is_string($this->data)) {
         $data = unserialize(USER_SETTINGS);
         if (empty($this->data)) {
             $this->data = $data;
         } else {
             $this->data = array_merge($data, json_decode($this->data));
         }
     }
     if (is_array($this->data) || is_object($this->data)) {
         $this->data = json_encode($this->data);
     }
     return parent::store();
 }
Example #2
0
 /**
  * If table key (id) is NULL : inserts a new row
  * otherwise updates existing row in the database table
  *
  * This override handles assigning orderings of new records if unset.
  * Can be overridden or overloaded by the child class
  *
  * @param  boolean  $updateNulls  TRUE: null object variables are also updated, FALSE: not.
  * @return boolean                TRUE if successful otherwise FALSE
  *
  * @throws \RuntimeException
  */
 public function store($updateNulls = false)
 {
     $k = $this->_tbl_key;
     if ($this->{$k} === null) {
         // new record without any ordering: Give it highest ordering (below 10000 which is our ordering limit):
         foreach ($this->_orderings as $ordering => $orderingGroups) {
             if (property_exists($this, $ordering) && $this->{$ordering} <= 0) {
                 $where = array($this->_db->NameQuote($ordering) . ' < 9998');
                 foreach ($orderingGroups as $ordGrpField) {
                     if ($this->{$ordGrpField} !== null) {
                         $where[] = $this->_db->NameQuote($ordGrpField) . ' = ' . $this->_db->Quote($this->{$ordGrpField});
                     }
                 }
                 $sql = 'SELECT MAX(' . $this->_db->NameQuote($ordering) . ')' . "\n FROM " . $this->_db->NameQuote($this->_tbl) . "\n WHERE " . implode(' AND ', $where);
                 $this->_db->SetQuery($sql);
                 $max = $this->_db->LoadResult();
                 $this->{$ordering} = $max + 1;
             }
         }
     }
     return parent::store($updateNulls);
 }