Back to Table class

Method isCheckedOut

public bool
isCheckedOut
(mixed $with = 0, mixed $against = null)
Method to determine if a row is checked out and therefore uneditable by a user.
Parameters
  • int $with The user ID to preform the match with, if an item is checked out by this user the function will return false.
  • int $against The user ID to perform the match against when the function is used as a static function.
Returns
  • bool True if checked out.
Since
  • 1.7.0
Class: Table
Project: Joomla

Method isCheckedOut - Source code

/**
 * Method to determine if a row is checked out and therefore uneditable by a user.
 *
 * If the row is checked out by the same user, then it is considered not checked out -- as the user can still edit it.
 *
 * @param   integer  $with     The user ID to preform the match with, if an item is checked out by this user the function will return false.
 * @param   integer  $against  The user ID to perform the match against when the function is used as a static function.
 *
 * @return  boolean  True if checked out.
 *
 * @since   1.7.0
 */
public function isCheckedOut($with = 0, $against = null)
{
    // Handle the non-static case.
    if (isset($this) && $this instanceof Table && \is_null($against)) {
        $checkedOutField = $this->getColumnAlias('checked_out');
        $against = $this->get($checkedOutField);
    }
    // The item is not checked out or is checked out by the same user.
    if (!$against || $against == $with) {
        return false;
    }
    // This last check can only be relied on if tracking session metadata
    if (Factory::getApplication()->get('session_metadata', true)) {
        $db = Factory::getDbo();
        $query = $db->getQuery(true)->select('COUNT(userid)')->from($db->quoteName('#__session'))->where($db->quoteName('userid') . ' = ' . (int) $against);
        $db->setQuery($query);
        $checkedOut = (bool) $db->loadResult();
        // If a session exists for the user then it is checked out.
        return $checkedOut;
    }
    // Assume if we got here that there is a value in the checked out column but it doesn't match the given user
    return true;
}