### app binding : xe.category 로 바인딩 되어 있음 Category Facade 로 접근 가능 ### 카테고리 생성 php 신규 카테고리 그룹 생성 $category = Category::create(); 카테고리 그룹에 아이템 추가 $item = Category::createItem($category, ['word' => '단어', 'description' => '설명']); 특정 단어의 하위 노드로 등록하고자 할땐 3번째 인자로 부모에 해당하는 아이템을 넘겨주면 됩니다. $child = Category::createItem($category, ['word' => '자식'], $item); ### 카테고리 사용 php 최상위 레벨 아이템 목록 $items = Category::progenitors($category); 특정 아이템의 하위 노드 아이템 목록 $item = array_shift($items); $_1depthItems = Category::children($item); 전체를 tree collection 으로 반환 받을수도 있습니다. php $category = Category::get($id); $tree = Category::getTree($category); ### 특정 대상과 카테고리 아이템의 연결 카테고리 패키지는 대상이 어떤 단어를 사용하는지에 대한 정보를 가지고 관리합니다. php 연결 Category::used($docId, $categoryItem); 해제 Category::unused($docId, $categoryItem);
Author: XE Team (developers) (developers@xpressengine.com)
コード例 #1
0
 public function children(CategoryHandler $handler, $categoryId)
 {
     $parentId = Input::get('id');
     if ($parentId === null) {
         $category = $handler->get($categoryId);
         $children = $handler->progenitors($category);
     } else {
         if (!($parent = $handler->getItem($parentId))) {
             throw new InvalidArgumentHttpException();
         }
         $children = $handler->children($parent);
     }
     return Presenter::makeApi($children);
 }
コード例 #2
0
 public function testGetTargetIds()
 {
     list($repo, $itemRepo) = $this->getMocks();
     $instance = new CategoryHandler($repo, $itemRepo);
     $mockItemEntity1 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity1->id = 1;
     $mockItemEntity2 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity2->id = 2;
     $mockItemEntity3 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity3->id = 3;
     $itemRepo->shouldReceive('fetchDesc')->once()->with($mockItemEntity1, 0, false)->andReturn([$mockItemEntity1, $mockItemEntity2, $mockItemEntity3]);
     $itemRepo->shouldReceive('fetchTargetIdsByIds')->once()->with([1, 2, 3])->andReturn(['xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxa', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxb', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxc', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxe', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxf']);
     $targetIds = $instance->getTargetIds($mockItemEntity1);
     $this->assertEquals(['xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxa', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxb', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxc', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxd', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxe', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxf'], $targetIds);
 }
コード例 #3
0
 public function testCountByCategory()
 {
     list($repo, $itemRepo) = $this->getMocks();
     $instance = new CategoryHandler($repo, $itemRepo);
     $mockEntity = m::mock('Xpressengine\\Category\\CategoryEntity');
     $mockEntity->id = 1;
     $mockItemEntity1 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity1->ordering = 0;
     $mockItemEntity2 = m::mock('Xpressengine\\Category\\CategoryItemEntity');
     $mockItemEntity1->ordering = 1;
     $itemRepo->shouldReceive('fetchProgenitor')->once()->with(1)->andReturn([$mockItemEntity1, $mockItemEntity2]);
     $itemRepo->shouldReceive('count')->once()->with($mockItemEntity1, 1)->andReturn(2);
     $itemRepo->shouldReceive('count')->once()->with($mockItemEntity2, 1)->andReturn(3);
     $count = $instance->countByCategory($mockEntity, 2);
     $this->assertEquals(7, $count);
 }
コード例 #4
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);
     }
 }
コード例 #5
0
 public function storeCategory(CategoryHandler $categoryHandler, Request $request)
 {
     $boardId = $request->get('boardId');
     $input = ['name' => $boardId . '-' . BoardModule::getId()];
     $category = $categoryHandler->create($input);
     if ($boardId == '') {
         // global config
         $config = $this->configHandler->getDefault();
         $config->set('categoryId', $category->id);
         $this->configHandler->putDefault($config->getPureAll());
     } else {
         $config = $this->configHandler->get($boardId);
         $config->set('categoryId', $category->id);
         $this->instanceManager->updateConfig($config->getPureAll());
     }
     return XePresenter::makeApi($category->getAttributes());
 }
コード例 #6
0
 public function storeCategory(Request $request, CategoryHandler $categoryHandler)
 {
     $input = ['name' => $request->get('categoryName')];
     $category = $categoryHandler->create($input);
     return XePresenter::makeApi($category->getAttributes());
 }