moveTo() public method

Move to another parent CategoryItem
public moveTo ( CategoryItem $item, CategoryItem $parent = null ) : CategoryItem
$item Xpressengine\Category\Models\CategoryItem item object
$parent Xpressengine\Category\Models\CategoryItem new parent item object
return Xpressengine\Category\Models\CategoryItem
コード例 #1
0
 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();
 }
コード例 #2
0
 public function testMoveTo()
 {
     list($repo, $itemRepo) = $this->getMocks();
     $instance = new CategoryHandler($repo, $itemRepo);
     $mockItemEntity = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockParent = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockParent->id = 1;
     $mockOldParent = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockOldParent->id = 2;
     $itemRepo->shouldReceive('fetchAsc')->once()->with($mockItemEntity, 1)->andReturn([$mockOldParent]);
     $itemRepo->shouldReceive('unlinkHierarchy')->once()->with($mockItemEntity, $mockOldParent)->andReturnNull();
     $itemRepo->shouldReceive('linkHierarchy')->once()->with($mockItemEntity, $mockParent)->andReturnNull();
     $instance->moveTo($mockItemEntity, $mockParent);
 }
コード例 #3
0
 public function testMoveToThorwsExceptionWhenGivenParentIsSelf()
 {
     $instance = new CategoryHandler();
     $mockItem = m::mock('Xpressengine\\Category\\Models\\CategoryItem');
     $mockItem->shouldReceive('getKey')->andReturn(1);
     $mockParent = m::mock('Xpressengine\\Category\\Models\\CategoryItem');
     $mockParent->shouldReceive('getKey')->andReturn(1);
     $mockItem->shouldReceive('getParent')->andReturnNull();
     try {
         $instance->moveTo($mockItem, $mockParent);
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertInstanceOf('Xpressengine\\Category\\Exceptions\\UnableMoveToSelfException', $e);
     }
 }