public moveTo ( |
||
$item | item object | |
$parent | new parent item object | |
return |
public function moveTo(CategoryItem $item, CategoryItem $parent = null)
{
$oldParent = $item->getParent();
if ($parent !== null) {
if ($item->getKey() === $parent->getKey()) {
throw new UnableMoveToSelfException();
}
if ($oldParent !== null && $oldParent->getKey() == $parent->getKey()) {
return;
}
}
if ($oldParent !== null) {
$this->unlinkHierarchy($item, $oldParent);
$item->{$item->getParentIdName()} = null;
}
if ($parent !== null) {
$this->linkHierarchy($item, $parent);
$item->{$item->getParentIdName()} = $parent->getKey();
}
$item->save();
// 연관 객체 정보들이 변경 되었으므로 객채를 갱신 함
return $item->newQuery()->find($item->getKey());
}
public function moveItem(CategoryHandler $handler, $categoryId) { $id = Input::get('id'); $parentId = Input::get('parentId'); $ordering = Input::get('ordering'); if ($id === null || !($item = $handler->getItem($id))) { throw new InvalidArgumentHttpException(); } $parent = empty($parentId) === false ? $handler->getItem($parentId) : null; DB::beginTransaction(); try { $handler->moveTo($item, $parent); $handler->setOrder($item, $ordering); } catch (Exception $e) { DB::rollBack(); throw $e; } DB::commit(); }