Back to Content class

Method store

public bool
store
(mixed $updateNulls = true)
Overrides Table::store to set modified data and user id.
Parameters
  • bool $updateNulls True to update fields even if they are null.
Returns
  • bool True on success.
Since
  • 1.6
Class: Content
Project: Joomla

Method store - Source code

/**
 * Overrides Table::store to set modified data and user id.
 *
 * @param   boolean  $updateNulls  True to update fields even if they are null.
 *
 * @return  boolean  True on success.
 *
 * @since   1.6
 */
public function store($updateNulls = true)
{
    $date = Factory::getDate()->toSql();
    $user = Factory::getUser();
    // Set created date if not set.
    if (!(int) $this->created) {
        $this->created = $date;
    }
    if ($this->id) {
        // Existing item
        $this->modified_by = $user->get('id');
        $this->modified = $date;
    } else {
        // Field created_by can be set by the user, so we don't touch it if it's set.
        if (empty($this->created_by)) {
            $this->created_by = $user->get('id');
        }
        // Set modified to created date if not set
        if (!(int) $this->modified) {
            $this->modified = $this->created;
        }
        // Set modified_by to created_by user if not set
        if (empty($this->modified_by)) {
            $this->modified_by = $this->created_by;
        }
    }
    // Verify that the alias is unique
    $table = Table::getInstance('Content', 'JTable', array('dbo' => $this->getDbo()));
    if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) {
        $this->setError(Text::_('JLIB_DATABASE_ERROR_ARTICLE_UNIQUE_ALIAS'));
        return false;
    }
    return parent::store($updateNulls);
}