Back to AdminModel class

Method reorder

public bool|null
reorder
(mixed $pks, mixed $delta = 0)
Method to adjust the ordering of a row.
Parameters
  • int $pks The ID of the primary key to move.
  • int $delta Increment, usually +1 or -1
Returns
  • bool|null False on failure or error, true on success, null if the $pk is empty (no items selected).
Since
  • 1.6
Class: AdminModel
Project: Joomla

Method reorder - Source code

/**
 * Method to adjust the ordering of a row.
 *
 * Returns NULL if the user did not have edit
 * privileges for any of the selected primary keys.
 *
 * @param   integer  $pks    The ID of the primary key to move.
 * @param   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).
 *
 * @since   1.6
 */
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);
                Log::add(Text::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), Log::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;
}