calcChildrenRank() public method

public calcChildrenRank ( EntityManager $em, integer $rank ) : Category
$em Doctrine\ORM\EntityManager
$rank integer
return Category
Example #1
0
 /**
  * カテゴリの順位を1下げる.
  *
  * @param  \Eccube\Entity\Category $Category カテゴリ
  * @return boolean 成功した場合 true
  */
 public function down(\Eccube\Entity\Category $Category)
 {
     $em = $this->getEntityManager();
     $em->getConnection()->beginTransaction();
     try {
         $rank = $Category->getRank();
         $Parent = $Category->getParent();
         if ($Parent) {
             $CategoryDown = $this->createQueryBuilder('c')->where('c.rank < :rank AND c.Parent = :Parent')->setParameter('rank', $rank)->setParameter('Parent', $Parent)->orderBy('c.rank', 'DESC')->setMaxResults(1)->getQuery()->getSingleResult();
         } else {
             $CategoryDown = $this->createQueryBuilder('c')->where('c.rank < :rank AND c.Parent IS NULL')->setParameter('rank', $rank)->orderBy('c.rank', 'DESC')->setMaxResults(1)->getQuery()->getSingleResult();
         }
         $this_count = $Category->countBranches();
         $down_count = $CategoryDown->countBranches();
         $Category->calcChildrenRank($em, $down_count * -1);
         $CategoryDown->calcChildrenRank($em, $this_count);
         $em->flush();
         $em->getConnection()->commit();
     } catch (\Exception $e) {
         $em->getConnection()->rollback();
         return false;
     }
     return true;
 }