/** * Create or update a record to * DB from POST data or input array of data * * @param array $dataArray an array holding data to save. If empty, $_POST is used * @return integer id of created or updated record */ public function save($dataArray = null) { // get required tools jimport('joomla.database.table'); $this->_data = JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); $post = is_null($dataArray) ? JRequest::get('post') : $dataArray; // use table save method try { $status = $this->_data->save($post); } catch (Exception $e) { ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage()); $this->_data->setError($e->getMessage()); $status = false; } // report error if (!$status) { JFactory::getApplication()->enqueuemessage($this->_data->getError()); return 0; } // if success, fetch last insert id and return that $tableDb = $this->_data->getDBO(); $keyName = $this->_data->getKeyName(); $id = empty($post[$keyName]) ? 0 : intval($post[$keyName]); $savedId = empty($id) ? $tableDb->insertid() : $id; return $savedId; }
/** * Create or update a record to * DB from POST data or input array of data * * @param array $dataArray an array holding data to save. If empty, $_POST is used * @return integer id of created or updated record */ public function save($dataArray = null) { // get required tools jimport('joomla.database.table'); $this->_data =& JTable::getInstance($this->_defaultTable, 'Sh404sefTable'); $post = is_null($dataArray) ? JRequest::get('post') : $dataArray; // use table save method $status = $this->_data->save($post); // report error if (!$status) { $app =& JFactory::getApplication(); $app->enqueuemessage($this->_data->getError()); return 0; } // if success, fetch last insert id and return that $tableDb =& $this->_data->getDBO(); $keyName = $this->_data->getKeyName(); $id = empty($post[$keyName]) ? 0 : intval($post[$keyName]); $savedId = empty($id) ? $tableDb->insertid() : $id; return $savedId; }
/** * Move the row up or down in the ordering * * Requires an ordering field to be present in the table * * @param int Amount to move up or down * @return KDatabaseRowAbstract */ public function order($change) { if (!in_array('ordering', $this->_table->getColumns())) { throw new KDatabaseRowException("The table " . $this->_table->getTableName() . " doesn't have a 'ordering' column."); } //force to integer settype($change, 'int'); if ($change !== 0) { $old = $this->ordering; $new = $this->ordering + $change; $new = $new <= 0 ? 1 : $new; $query = 'UPDATE `#__' . $this->_table->getTableName() . '` '; if ($change < 0) { $query .= 'SET ordering = ordering+1 WHERE ' . $new . ' <= ordering AND ordering < ' . $old; } else { $query .= 'SET ordering = ordering-1 WHERE ' . $old . ' < ordering AND ordering <= ' . $new; } $this->_table->getDBO()->execute($query); $this->ordering = $new; $this->save(); $this->_table->reorder(); } return $this; }