/** * * Add a new record. * * @return void * */ public function actionAdd() { // is the user allowed access? if (!$this->_isUserAllowed()) { return; } // process: cancel if ($this->_isProcess('cancel')) { // forward back to browse return $this->_redirect("/{$this->_controller}/browse"); } // set a new record $this->_setItemNew(); // process: save if ($this->_isProcess('save') && $this->_saveItem()) { // save a flash value for the next page $this->_session->setFlash('success_added', true); // redirect to editing using the primary-key value $id = $this->item->getPrimaryVal(); return $this->_redirectNoCache("/{$this->_controller}/edit/{$id}"); } // set the form-building hints for the item $this->_setFormItem(); // turn off http caching $this->_response->setNoCache(); }
/** * * Given a record object, looks up its offset value in the collection. * * For this to work, the record primary key must exist in the collection, * **and** the record looked up in the collection must have the same * primary key and be of the same class. * * Note that the returned offset may be zero, indicating the first element * in the collection. As such, you should check the return for boolean * false to indicate failure. * * @param Solar_Sql_Model_Record $record The record to find in the * collection. * * @return mixed The record offset (which may be zero), or boolean false * if the same record was not found in the collection. * */ public function getRecordOffset($record) { // the primary value of the record $val = $record->getPrimaryVal(); // mapping of primary-key values to offset values $map = array_flip($this->getPrimaryVals()); // does the record primary value exist in the collection? // use array_key_exists() instead of empty() so we can honor zeroes. if (!array_key_exists($val, $map)) { return false; } // retain the offset value $offset = $map[$val]; // look up the record inside the collection $lookup = $this->__get($offset); // the primary keys are already known to be the same from above. // if the classes match as well, consider records to be "the same". if (get_class($lookup) === get_class($record)) { return $offset; } else { return false; } }