Admin Model

This method is used to adjust the ordering of a row. It returns NULL if the user did not have edit privileges for any of the selected primary keys.

  • integer $pks - The ID of the primary key to move
  • integer $delta - Increment, usually +1 or -1
  • return boolean|null - False on failure or error, true on success, null if the $pk is empty (no items selected)
public function reorder($pks, $delta = 0)
{
$table = $this->getTable();
$pks = (array) $pks;
$result = true;

$allowed = true;

foreach ($pks as $i => $pk)
{
$table->reset();

if ($table->load($pk) && $this->checkout($pk))
{
// Access checks.
if (!$this->canEditState($table))
{
// Prune items that you can't change.
unset($pks[$i]);
$this->checkin($pk);
\JLog::add(\JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), \JLog::WARNING, 'jerror');
$allowed = false;
continue;
}

$where = $this->getReorderConditions($table);

if (!$table->move($delta, $where))
{
$this->setError($table->getError());
unset($pks[$i]);
$result = false;
}

$this->checkin($pk);
}
else
{
$this->setError($table->getError());
unset($pks[$i]);
$result = false;
}
}

if ($allowed === false && empty($pks))
{
$result = null;
}

// Clear the component's cache
if ($result == true)
{
$this->cleanCache();
}

return $result;
}