FOF30\Model\DataModel::touch PHP Method

touch() public method

Touch a record, updating its modified_on and/or modified_by columns
public touch ( integer $userId = null )
$userId integer Optional user ID of the user touching the record
    public function touch($userId = null)
    {
        if (!$this->getId()) {
            throw new RecordNotLoaded("Can't touch a not loaded DataModel");
        }
        if (!$this->hasField('modified_on') && !$this->hasField('modified_by')) {
            return $this;
        }
        $db = $this->getDbo();
        $date = new \JDate();
        // Update the created_on / modified_on
        if ($this->hasField('modified_on')) {
            $modified_on = $this->getFieldAlias('modified_on');
            $this->{$modified_on} = $date->toSql(false, $db);
        }
        // Update the created_by / modified_by values if necessary
        if ($this->hasField('modified_by')) {
            if (empty($userId)) {
                $userId = $this->container->platform->getUser()->id;
            }
            $modified_by = $this->getFieldAlias('modified_by');
            $this->{$modified_by} = $userId;
        }
        $this->save();
        return $this;
    }