/** * Returns the data in $this->_current as a FOFTable instance * * @return FOFTable * * @throws OutOfBoundsException */ protected function getTable() { if (!$this->valid()) { throw new OutOfBoundsException('Cannot get item past iterator\'s bounds', 500); } $this->_tableObject->bind($this->_current); return $this->_tableObject; }
/** * Returns a single item. It uses the id set with setId, or the first ID in * the list of IDs for batch operations * * @param integer $id Force a primary key ID to the model. Use null to use the id from the state. * * @return FOFTable A copy of the item's FOFTable array */ public function &getItem($id = null) { if (!is_null($id)) { $this->record = null; $this->setId($id); } if (empty($this->record)) { $table = $this->getTable($this->table); $table->load($this->id); $this->record = $table; // Do we have saved data? $session = JFactory::getSession(); if ($this->_savestate) { $serialized = $session->get($this->getHash() . 'savedata', null); if (!empty($serialized)) { $data = @unserialize($serialized); if ($data !== false) { $k = $table->getKeyName(); if (!array_key_exists($k, $data)) { $data[$k] = null; } if ($data[$k] != $this->id) { $session->set($this->getHash() . 'savedata', null); } else { $this->record->bind($data); } } } } $this->onAfterGetItem($this->record); } return $this->record; }
/** * This method runs before the $data is saved to the $table. Return false to * stop saving. * * @param array $data The data to save * @param FOFTable $table The table to save the data to * * @return boolean Return false to prevent saving, true to allow it */ protected function onBeforeSave(&$data, &$table) { list($isCLI, $isAdmin) = FOFDispatcher::isCliAdmin(); // Let's import the plugin only if we're not in CLI (content plugin needs a user) if (!$isCLI) { JPluginHelper::importPlugin('content'); } $dispatcher = JDispatcher::getInstance(); try { // Do I have a new record? $key = $table->getKeyName(); if ($data instanceof FOFTable) { $allData = $data->getData(); } elseif (is_object($data)) { $allData = (array) $data; } else { $allData = $data; } $pk = !empty($allData[$key]) ? $allData[$key] : 0; $this->_isNewRecord = $pk <= 0; // Bind the data $table->bind($allData); // Call the plugin $name = $this->name; $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $name, &$table, $this->_isNewRecord)); if (in_array(false, $result, true)) { // Plugin failed, return false $this->setError($table->getError()); return false; } else { // Plugin successful, refetch the possibly modified data if ($data instanceof FOFTable) { $data->bind($allData); } elseif (is_object($data)) { $data = (object) $allData; } else { $data = $allData; } } } catch (Exception $e) { // Oops, an exception occured! $this->setError($e->getMessage()); return false; } return true; }