public function testCategoryWithOut() { $Category = new Category(); $Category->setName('test')->setRank(1)->setLevel(1)->setDelFlg(Constant::DISABLED)->setCreateDate(new \DateTime())->setUpdateDate(new \DateTime()); $this->app['orm.em']->persist($Category); $this->app['orm.em']->flush(); $this->searchData = array('category_id' => $Category); $this->scenario(); $this->expected = 0; $this->actual = count($this->Results); $this->verify(); }
/** * 親カテゴリ名を含むカテゴリ名を取得する. * @return string */ public function getCategoryFullName() { if (is_null($this->Category)) { return ""; } $fulName = $this->Category->getName(); // 親カテゴリがない場合はカテゴリ名を返す. if (is_null($this->Category->getParent())) { return $fulName; } // 親カテゴリ名を結合する $ParentCategory = $this->Category->getParent(); while (!is_null($ParentCategory)) { $fulName = $ParentCategory->getName() . " > " . $fulName; $ParentCategory = $ParentCategory->getParent(); } return $fulName; }
public function createCategories() { $categories = array(array('name' => '親1', 'level' => 1, 'rank' => 1, 'child' => array(array('name' => '子1', 'level' => 2, 'rank' => 4, 'child' => array(array('name' => '孫1', 'level' => 3, 'rank' => 9))))), array('name' => '親2', 'level' => 1, 'rank' => 2, 'child' => array(array('name' => '子2-0', 'level' => 2, 'rank' => 5, 'child' => array(array('name' => '孫2', 'level' => 3, 'rank' => 10))), array('name' => '子2-1', 'level' => 2, 'rank' => 6), array('name' => '子2-2', 'level' => 2, 'rank' => 7))), array('name' => '親3', 'level' => 1, 'rank' => 3, 'child' => array(array('name' => '子3', 'level' => 2, 'rank' => 8, 'child' => array(array('name' => '孫3', 'level' => 3, 'rank' => 11)))))); foreach ($categories as $category_array) { $Category = new Category(); $Category->setPropertiesFromArray($category_array); $Category->setDelFlg(Constant::DISABLED); $Category->setCreateDate(new \DateTime()); $Category->setUpdateDate(new \DateTime()); $this->app['orm.em']->persist($Category); $this->app['orm.em']->flush(); if (!array_key_exists('child', $category_array)) { continue; } foreach ($category_array['child'] as $child_array) { $Child = new Category(); $Child->setPropertiesFromArray($child_array); $Child->setParent($Category); $Child->setDelFlg(Constant::DISABLED); $Child->setCreateDate(new \DateTime()); $Child->setUpdateDate(new \DateTime()); $this->app['orm.em']->persist($Child); $this->app['orm.em']->flush(); // add child category $Category->addChild($Child); if (!array_key_exists('child', $child_array)) { continue; } foreach ($child_array['child'] as $grandson_array) { $Grandson = new Category(); $Grandson->setPropertiesFromArray($grandson_array); $Grandson->setParent($Child); $Grandson->setDelFlg(Constant::DISABLED); $Grandson->setCreateDate(new \DateTime()); $Grandson->setUpdateDate(new \DateTime()); $this->app['orm.em']->persist($Grandson); $this->app['orm.em']->flush(); // add child category $Child->addChild($Grandson); } } } }
/** * カテゴリを削除する. * * @param \Eccube\Entity\Category $Category 削除対象のカテゴリ * @return boolean 成功した場合 true, 子カテゴリが存在する場合, 商品カテゴリが紐づいている場合は false */ public function delete(\Eccube\Entity\Category $Category) { $em = $this->getEntityManager(); $em->getConnection()->beginTransaction(); try { if ($Category->getChildren()->count() > 0 || $Category->getProductCategories()->count() > 0) { throw new \Exception(); } $rank = $Category->getRank(); $em->createQueryBuilder()->update('Eccube\\Entity\\Category', 'c')->set('c.rank', 'c.rank - 1')->where('c.rank > :rank')->setParameter('rank', $rank)->getQuery()->execute(); $Category->setDelFlg(1); $em->persist($Category); $em->flush(); $em->getConnection()->commit(); } catch (\Exception $e) { $em->getConnection()->rollback(); return false; } return true; }
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; }
public function testSaveWithException() { $faker = $this->getFaker(); $name = $faker->name; $Category = new Category(); $Category->setName($name)->setLevel(null); // level は not null なので例外になる $result = $this->app['eccube.repository.category']->save($Category); $this->assertFalse($result); }