function store() { $query = $this->_db->getQuery(true); if (!isset($this->id)) { // Fetch the document primary key with the unique key $query->clear(); $query->select(' id '); $query->from(' ' . $this->_tbl . ' '); $query->where(' file = ' . $this->_db->quote($this->file) . ' '); $query->where(' app_id = ' . $this->app_id . ' '); // fetch and save the primary key $this->_db->setQuery($query); $document_id = $this->_db->loadResult(); if ($document_id) { // record exists, set the primary key for updating the record with store $this->id = $document_id; } else { // new document record $query->clear(); $query->select(' MAX( id ) '); $query->from(' ' . $this->_tbl . ' '); $query->where(' app_id = ' . $this->app_id . ' '); // fetch and save the primary key $this->_db->setQuery($query); $max_id = $this->_db->loadResult(); $new_id = (int) trim($max_id, 'D'); $new_id = $new_id + 1; // unset the primary key, so the store function will insert a new record $this->id = sprintf('D%010s', $new_id); } } // Store the document $ret = parent::store(); if ($ret) { // everything went ok return $this->id; } else { return false; } }
public function store($updateNulls = false) { if (!empty($this->familyName)) { $this->indexNam = mb_strtoupper(mb_substr($this->familyName, 0, 1)); } return parent::store($updateNulls); }