示例#1
0
 public function index(Application $app, Request $request, $parent_id = null, $id = null)
 {
     if ($parent_id) {
         $Parent = $app['eccube.repository.category']->find($parent_id);
         if (!$Parent) {
             throw new NotFoundHttpException('親カテゴリが存在しません');
         }
     } else {
         $Parent = null;
     }
     if ($id) {
         $TargetCategory = $app['eccube.repository.category']->find($id);
         if (!$TargetCategory) {
             throw new NotFoundHttpException('カテゴリが存在しません');
         }
         $Parent = $TargetCategory->getParent();
     } else {
         $TargetCategory = new \Eccube\Entity\Category();
         $TargetCategory->setParent($Parent);
         if ($Parent) {
             $TargetCategory->setLevel($Parent->getLevel() + 1);
         } else {
             $TargetCategory->setLevel(1);
         }
     }
     //
     $builder = $app['form.factory']->createBuilder('admin_category', $TargetCategory);
     $event = new EventArgs(array('builder' => $builder, 'Parent' => $Parent, 'TargetCategory' => $TargetCategory), $request);
     $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_INITIALIZE, $event);
     $form = $builder->getForm();
     //
     if ($request->getMethod() === 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             if ($app['config']['category_nest_level'] < $TargetCategory->getLevel()) {
                 throw new BadRequestHttpException('リクエストが不正です');
             }
             log_info('カテゴリ登録開始', array($id));
             $status = $app['eccube.repository.category']->save($TargetCategory);
             if ($status) {
                 log_info('カテゴリ登録完了', array($id));
                 $event = new EventArgs(array('form' => $form, 'Parent' => $Parent, 'TargetCategory' => $TargetCategory), $request);
                 $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_PRODUCT_CATEGORY_INDEX_COMPLETE, $event);
                 $app->addSuccess('admin.category.save.complete', 'admin');
                 if ($Parent) {
                     return $app->redirect($app->url('admin_product_category_show', array('parent_id' => $Parent->getId())));
                 } else {
                     return $app->redirect($app->url('admin_product_category'));
                 }
             } else {
                 log_info('カテゴリ登録エラー', array($id));
                 $app->addError('admin.category.save.error', 'admin');
             }
         }
     }
     $Categories = $app['eccube.repository.category']->getList($Parent);
     // ツリー表示のため、ルートからのカテゴリを取得
     $TopCategories = $app['eccube.repository.category']->getList(null);
     return $app->render('Product/category.twig', array('form' => $form->createView(), 'Parent' => $Parent, 'Categories' => $Categories, 'TopCategories' => $TopCategories, 'TargetCategory' => $TargetCategory));
 }
 public function index(Application $app, Request $request, $parent_id = null, $id = null)
 {
     if ($parent_id) {
         $Parent = $app['eccube.repository.category']->find($parent_id);
         if (!$Parent) {
             throw new NotFoundHttpException();
         }
     } else {
         $Parent = null;
     }
     if ($id) {
         $TargetCategory = $app['eccube.repository.category']->find($id);
         if (!$TargetCategory) {
             throw new NotFoundHttpException();
         }
         $Parent = $TargetCategory->getParent();
     } else {
         $TargetCategory = new \Eccube\Entity\Category();
         $TargetCategory->setParent($Parent);
         if ($Parent) {
             $TargetCategory->setLevel($Parent->getLevel() + 1);
         } else {
             $TargetCategory->setLevel(1);
         }
     }
     //
     $form = $app['form.factory']->createBuilder('admin_category', $TargetCategory)->getForm();
     //
     if ($request->getMethod() === 'POST') {
         $form->handleRequest($request);
         if ($form->isValid()) {
             if ($app['config']['category_nest_level'] < $TargetCategory->getLevel()) {
                 throw new BadRequestHttpException();
             }
             $status = $app['eccube.repository.category']->save($TargetCategory);
             if ($status) {
                 $app->addSuccess('admin.category.save.complete', 'admin');
                 if ($Parent) {
                     return $app->redirect($app->url('admin_product_category_show', array('parent_id' => $Parent->getId())));
                 } else {
                     return $app->redirect($app->url('admin_product_category'));
                 }
             } else {
                 $app->addError('admin.category.save.error', 'admin');
             }
         }
     }
     $Children = $app['eccube.repository.category']->getList(null);
     $Categories = $app['eccube.repository.category']->getList($Parent);
     $TopCategories = $app['eccube.repository.category']->findBy(array('Parent' => null), array('rank' => 'DESC'));
     $category_count = $app['eccube.repository.category']->getTotalCount();
     return $app->render('Product/category.twig', array('form' => $form->createView(), 'Children' => $Children, 'Parent' => $Parent, 'Categories' => $Categories, 'TopCategories' => $TopCategories, 'TargetCategory' => $TargetCategory, 'category_count' => $category_count));
 }
 public function index(Application $app, Request $request, $category_id = null)
 {
     if ($category_id) {
         // カテゴリが選択されている場合は親になるカテゴリを取得しておく
         $Parent = $app['eccube.repository.category']->find($category_id);
         if (!$Parent) {
             throw new EntityNotFoundException();
         }
     } else {
         $Parent = null;
     }
     $TargetCategory = new \Eccube\Entity\Category();
     $TargetCategory->setParent($Parent);
     if ($Parent) {
         $TargetCategory->setLevel($Parent->getLevel() + 1);
     } else {
         $TargetCategory->setLevel(1);
     }
     $Children = $app['eccube.repository.category']->getList(null);
     $ProductCategorys = $app['eccube.plugin.product_rank.repository.product_rank']->findBySearchData($Parent);
     $TopCategories = $app['eccube.repository.category']->findBy(array('Parent' => null), array('rank' => 'DESC'));
     $category_count = $app['eccube.repository.category']->getTotalCount();
     return $app->render('ProductRank/Resource/template/admin//product_rank.twig', array('Children' => $Children, 'Parent' => $Parent, 'ProductCategorys' => $ProductCategorys, 'TopCategories' => $TopCategories, 'TargetCategory' => $TargetCategory, 'category_count' => $category_count, 'category_id' => $category_id));
 }
 private function newTestCategory($TestCreator, $TestParentCategory = null)
 {
     $TestCategory = new \Eccube\Entity\Category();
     if ($TestParentCategory == null) {
         $TestCategory->setName('テスト家具')->setRank(100)->setLevel(100)->setDelFlg(false)->setParent($TestParentCategory)->setCreator($TestCreator);
     } else {
         $TestCategory->setName($TestParentCategory->getName() . '_c')->setRank($TestParentCategory->getRank() + 1)->setLevel($TestParentCategory->getLevel() + 1)->setDelFlg(false)->setParent($TestParentCategory)->setCreator($TestCreator);
     }
     return $TestCategory;
 }
 /**
  * カテゴリを生成する.
  *
  * 以下のように, ツリー状のカテゴリを生成する
  *
  *  大カテゴリ -- 中カテゴリ -- 小カテゴリ
  *             |             |- 小カテゴリ
  *             |             |- 小カテゴリ
  *             |
  *             |- 中カテゴリ -- 小カテゴリ
  *                            |- 小カテゴリ
  *                            |- 小カテゴリ
  * @return void
  */
 function createCategories()
 {
     $existingMaxRank = 0;
     print "カテゴリを生成しています...\n";
     if (!$this->delete) {
         $q = $this->em->createQuery('SELECT MAX(c.rank) from Eccube\\Entity\\Category c');
         $existingMaxRank = $q->getSingleResult()[1];
     }
     $count = 0;
     // 全カテゴリ共通の値
     $common_val = array();
     $common_val['creator'] = $this->app['eccube.repository.member']->find(2);
     $common_val['del_flg'] = (string) '0';
     // 大カテゴリを生成
     for ($i = 0; $i < TOP_CATEGORIES_VOLUME; $i++) {
         $Category = new \Eccube\Entity\Category();
         $Category->setCreator($common_val['creator'])->setDelFlg($common_val['del_flg'])->setName(sprintf("Category%d00", $i))->setLevel(1)->setRank($this->lfGetTotalCategoryrank($existingMaxRank) - $count);
         $this->saveEntity($Category);
         $this->arrCategory1[] = $Category;
         $count++;
         print ".";
         $top_category = $Category;
         // 中カテゴリを生成
         for ($j = 0; $j < MIDDLE_CATEGORIES_VOLUME; $j++) {
             $Category = new \Eccube\Entity\Category();
             $Category->setCreator($common_val['creator'])->setDelFlg($common_val['del_flg'])->setName(sprintf("Category%d%d0", $i, $j + MIDDLE_CATEGORIES_VOLUME))->setParent($top_category)->setLevel(2)->setRank($this->lfGetTotalCategoryrank($existingMaxRank) - $count);
             $this->saveEntity($Category);
             $this->arrCategory2[] = $Category;
             $count++;
             print ".";
             $middle_category = $Category;
             // 小カテゴリを生成
             for ($k = 0; $k < SMALL_CATEGORIES_VOLUME; $k++) {
                 $Category = new \Eccube\Entity\Category();
                 $Category->setCreator($common_val['creator'])->setDelFlg($common_val['del_flg'])->setName(sprintf("Category%d%d%d", $i, $j, $k + SMALL_CATEGORIES_VOLUME))->setParent($middle_category)->setLevel(3)->setRank($this->lfGetTotalCategoryrank($existingMaxRank) - $count);
                 $this->saveEntity($Category);
                 $this->arrCategory3[] = $Category;
                 $count++;
                 print ".";
             }
         }
     }
     print "\n";
 }