FOF30\Model\DataModel::lock PHP 메소드

lock() 공개 메소드

Lock a record by setting its locked_on and/or locked_by columns
public lock ( integer $userId = null )
$userId integer
    public function lock($userId = null)
    {
        if (!$this->getId()) {
            throw new CannotLockNotLoadedRecord();
        }
        if (!$this->hasField('locked_on') && !$this->hasField('locked_by')) {
            return $this;
        }
        $this->triggerEvent('onBeforeLock', array());
        $db = $this->getDbo();
        if ($this->hasField('locked_on')) {
            $date = new \JDate();
            $locked_on = $this->getFieldAlias('locked_on');
            $this->{$locked_on} = $date->toSql(false, $db);
        }
        if ($this->hasField('locked_by')) {
            if (empty($userId)) {
                $userId = $this->container->platform->getUser()->id;
            }
            $locked_by = $this->getFieldAlias('locked_by');
            $this->{$locked_by} = $userId;
        }
        $this->save();
        $this->triggerEvent('onAfterLock');
        return $this;
    }