public function checkout($userId = null)
	{
		if (!$this->isNew())
		{
			$columns = $this->getStructure()->getTableColumns($this->getTableName());

			$data = [];

			if (isset($columns['checked_out_time']))
			{
				$now = new Date('now');
				$data['checked_out_time'] = $now->toSql();
			}

			if (isset($columns['checked_out']))
			{
				$userId = $userId ?: \User::get('id');
				$data['checked_out'] = $userId;
			}

			if (empty($data))
			{
				// There is no 'checked_out_time' or 'checked_out' column
				return true;
			}

			$this->set($data);

			// We build a simple update query as calling save()
			// can have unintended consequences when all we want
			// is to update two columns
			$query = $this->getQuery()
				->update($this->getTableName())
				->set($data)
				->whereEquals($this->getPrimaryKey(), $this->get($this->getPrimaryKey()));

			// @FIXME: Maybe unnecessary? Database may throw an exception on error
			//         so this might be pointless.
			if (!$query->execute())
			{
				$this->addError(__CLASS__ . '::' . __METHOD__ . '() failed');
				return false;
			}
		}

		return true;
	}
public function checkout($userId = null)
	{
		if (!$this->isNew())
		{
			$columns = $this->getStructure()->getTableColumns($this->getTableName());

			$data = [];

			if (isset($columns['checked_out_time']))
			{
				$now = new Date('now');
				$data['checked_out_time'] = $now->toSql();
			}

			if (isset($columns['checked_out']))
			{
				$userId = $userId ?: \User::get('id');
				$data['checked_out'] = $userId;
			}

			if (empty($data))
			{
				// There is no 'checked_out_time' or 'checked_out' column
				return true;
			}

			$this->set($data);

			// We build a simple update query as calling save()
			// can have unintended consequences when all we want
			// is to update two columns
			$query = $this->getQuery()
				->update($this->getTableName())
				->set($data)
				->whereEquals($this->getPrimaryKey(), $this->get($this->getPrimaryKey()));

			// @FIXME: Maybe unnecessary? Database may throw an exception on error
			//         so this might be pointless.
			if (!$query->execute())
			{
				$this->addError(__CLASS__ . '::' . __METHOD__ . '() failed');
				return false;
			}
		}

		return true;
	}
public function checkout ( $ userId = null ) { if ( ! $ this -> isNew ( ) ) { $ columns = $ this -> getStructure ( ) -> getTableColumns ( $ this -> getTableName ( ) ) ; $ data = [ ] ; if ( isset ( $ columns [ 'checked_out_time' ] ) ) { $ now = new Date ( 'now' ) ; $ data [ 'checked_out_time' ] = $ now -> toSql ( ) ; } if ( isset ( $ columns [ 'checked_out' ] ) ) { $ userId = $ userId ? : \ User :: get ( 'id' ) ; $ data [ 'checked_out' ] = $ userId ; } if ( empty ( $ data ) ) { // There is no 'checked_out_time' or 'checked_out' column return true ; } $ this -> set ( $ data ) ; // We build a simple update query as calling save() // can have unintended consequences when all we want // is to update two columns $ query = $ this -> getQuery ( ) -> update ( $ this -> getTableName ( ) ) -> set ( $ data ) -> whereEquals ( $ this -> getPrimaryKey ( ) , $ this -> get ( $ this -> getPrimaryKey ( ) ) ) ; // @FIXME: Maybe unnecessary? Database may throw an exception on error //         so this might be pointless. if ( ! $ query -> execute ( ) ) { $ this -> addError ( __CLASS__ . '::' . __METHOD__ . '() failed' ) ; return false ; } } return true ; }
Checks out the current model to the provided user

@param   integer  $userId  Optional userId for whom the row should be checked out
@return  boolean
@since   2.0.0
Checks out the current model to the provided user