public function moveItem(Model $model, $direct = null, $id = null, $delta = 1) {
		$direct = mb_strtolower($direct);
		$delta = (int)$delta;
		if (in_array($direct, ['up', 'down']) && ($delta < 0)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid delta for moving record'));
		}

		if (!in_array($direct, ['top', 'up', 'down', 'bottom'])) {
			throw new InternalErrorException(__d('view_extension', 'Invalid direction for moving record'));
		}

		switch ($direct) {
			case 'top':
				$delta = true;
				// no break
			case 'up':
				$method = 'moveUp';
				break;
			case 'bottom':
				$delta = true;
				// no break
			case 'down':
				$method = 'moveDown';
				break;
		}

		$newParentId = null;
		$optionsEvent = compact('id', 'newParentId', 'method', 'delta');
		$event = new CakeEvent('Model.beforeUpdateTree', $model, [$optionsEvent]);
		$model->getEventManager()->dispatch($event);
		if ($event->isStopped()) {
			return false;
		}

		$result = $model->$method($id, $delta);
		if ($result) {
			$event = new CakeEvent('Model.afterUpdateTree', $model);
			$model->getEventManager()->dispatch($event);
		}

		return $result;
	}
public function moveItem(Model $model, $direct = null, $id = null, $delta = 1) {
		$direct = mb_strtolower($direct);
		$delta = (int)$delta;
		if (in_array($direct, ['up', 'down']) && ($delta < 0)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid delta for moving record'));
		}

		if (!in_array($direct, ['top', 'up', 'down', 'bottom'])) {
			throw new InternalErrorException(__d('view_extension', 'Invalid direction for moving record'));
		}

		switch ($direct) {
			case 'top':
				$delta = true;
				// no break
			case 'up':
				$method = 'moveUp';
				break;
			case 'bottom':
				$delta = true;
				// no break
			case 'down':
				$method = 'moveDown';
				break;
		}

		$newParentId = null;
		$optionsEvent = compact('id', 'newParentId', 'method', 'delta');
		$event = new CakeEvent('Model.beforeUpdateTree', $model, [$optionsEvent]);
		$model->getEventManager()->dispatch($event);
		if ($event->isStopped()) {
			return false;
		}

		$result = $model->$method($id, $delta);
		if ($result) {
			$event = new CakeEvent('Model.afterUpdateTree', $model);
			$model->getEventManager()->dispatch($event);
		}

		return $result;
	}
public function moveItem ( Model $ model , $ direct = null , $ id = null , $ delta = 1 ) { $ direct = mb_strtolower ( $ direct ) ; $ delta = ( int ) $ delta ; if ( in_array ( $ direct , [ 'up' , 'down' ] ) && ( $ delta < 0 ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid delta for moving record' ) ) ; } if ( ! in_array ( $ direct , [ 'top' , 'up' , 'down' , 'bottom' ] ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid direction for moving record' ) ) ; } switch ( $ direct ) { case 'top' : $ delta = true ; // no break case 'up' : $ method = 'moveUp' ; break ; case 'bottom' : $ delta = true ; // no break case 'down' : $ method = 'moveDown' ; break ; } $ newParentId = null ; $ optionsEvent = compact ( 'id' , 'newParentId' , 'method' , 'delta' ) ; $ event = new CakeEvent ( 'Model.beforeUpdateTree' , $ model , [ $ optionsEvent ] ) ; $ model -> getEventManager ( ) -> dispatch ( $ event ) ; if ( $ event -> isStopped ( ) ) { return false ; } $ result = $ model -> $ method ( $ id , $ delta ) ; if ( $ result ) { $ event = new CakeEvent ( 'Model.afterUpdateTree' , $ model ) ; $ model -> getEventManager ( ) -> dispatch ( $ event ) ; } return $ result ; }
Move item to new position of tree

@param Model $model Model using this behavior.
@param string $direct Direction for moving: `up`, `down`, `top`, `bottom`
@param int $id ID of record for moving
@param int $delta Delta for moving
@throws InternalErrorException if delta for moving < 0
@throws InternalErrorException if direction for moving not is: `up`, `down`, `top` or `bottom`
@triggers Model.beforeUpdateTree $model array($options)
@triggers Model.afterUpdateTree $model
@return bool Success
Move item to new position of tree