Form Model

This method is used to checkin a row.

  • integer $pk - The numeric id of the primary key
  • return boolean - False on failure or error, true otherwise
public function checkin($pk = null)
{
// Only attempt to check the row in if it exists.
if ($pk)
{
$user = \JFactory::getUser();

// Get an instance of the row to checkin.
$table = $this->getTable();

if (!$table->load($pk))
{
$this->setError($table->getError());

return false;
}

$checkedOutField = $table->getColumnAlias('checked_out');
$checkedOutTimeField = $table->getColumnAlias('checked_out_time');

// If there is no checked_out or checked_out_time field, just return true.
if (!property_exists($table, $checkedOutField) || !property_exists($table, $checkedOutTimeField))
{
return true;
}

// Check if this is the user having previously checked out the row.
if ($table->{$checkedOutField} > 0 && $table->{$checkedOutField} != $user->get('id') && !$user->authorise('core.admin', 'com_checkin'))
{
$this->setError(\JText::_('JLIB_APPLICATION_ERROR_CHECKIN_USER_MISMATCH'));

return false;
}

// Attempt to check the row in.
if (!$table->checkIn($pk))
{
$this->setError($table->getError());

return false;
}
}

return true;
}