getId() == $entity->getId()) break; $former_order++; } $collection = array_slice($collection,0, count($collection), false); $max_order = count($collection); if($new_order > $max_order) throw new ValidationException(sprintf("max order is %s", $max_order)); unset($collection[$former_order - 1]); $collection = array_merge ( array_slice($collection, 0, $new_order-1 , true) , [$entity] , array_slice($collection, $new_order -1 , count($collection), true) ); $order = 1; foreach($collection as $e){ $e->setOrder($order); $order++; } } /** * @param Selectable $collection * @param IOrderable $element * @param $new_order * @throws ValidationException */ private static function recalculateOrderForSelectable(Selectable $collection, IOrderable $element, $new_order){ $criteria = Criteria::create(); $criteria->orderBy(['order'=> 'ASC']); self::recalculateOrderForCollection( $collection->matching($criteria)->toArray(), $element, $new_order); } }