| @@ 110-152 (lines=43) @@ | ||
| 107 | * |
|
| 108 | * @deprecated since 3.0.0, to be removed in 3.1 |
|
| 109 | */ |
|
| 110 | public function up(\Eccube\Entity\Category $Category) |
|
| 111 | { |
|
| 112 | $em = $this->getEntityManager(); |
|
| 113 | $em->getConnection()->beginTransaction(); |
|
| 114 | try { |
|
| 115 | $rank = $Category->getRank(); |
|
| 116 | $Parent = $Category->getParent(); |
|
| 117 | ||
| 118 | if ($Parent) { |
|
| 119 | $CategoryUp = $this->createQueryBuilder('c') |
|
| 120 | ->where('c.rank > :rank AND c.Parent = :Parent') |
|
| 121 | ->setParameter('rank', $rank) |
|
| 122 | ->setParameter('Parent', $Parent) |
|
| 123 | ->orderBy('c.rank', 'ASC') |
|
| 124 | ->setMaxResults(1) |
|
| 125 | ->getQuery() |
|
| 126 | ->getSingleResult(); |
|
| 127 | } else { |
|
| 128 | $CategoryUp = $this->createQueryBuilder('c') |
|
| 129 | ->where('c.rank > :rank AND c.Parent IS NULL') |
|
| 130 | ->setParameter('rank', $rank) |
|
| 131 | ->orderBy('c.rank', 'ASC') |
|
| 132 | ->setMaxResults(1) |
|
| 133 | ->getQuery() |
|
| 134 | ->getSingleResult(); |
|
| 135 | } |
|
| 136 | ||
| 137 | $this_count = $Category->countBranches(); |
|
| 138 | $up_count = $CategoryUp->countBranches(); |
|
| 139 | ||
| 140 | $Category->calcChildrenRank($em, $up_count); |
|
| 141 | $CategoryUp->calcChildrenRank($em, $this_count * -1); |
|
| 142 | $em->flush(); |
|
| 143 | ||
| 144 | $em->getConnection()->commit(); |
|
| 145 | } catch (\Exception $e) { |
|
| 146 | $em->getConnection()->rollback(); |
|
| 147 | ||
| 148 | return false; |
|
| 149 | } |
|
| 150 | ||
| 151 | return true; |
|
| 152 | } |
|
| 153 | ||
| 154 | /** |
|
| 155 | * カテゴリの順位を1下げる. |
|
| @@ 162-204 (lines=43) @@ | ||
| 159 | * |
|
| 160 | * @deprecated since 3.0.0, to be removed in 3.1 |
|
| 161 | */ |
|
| 162 | public function down(\Eccube\Entity\Category $Category) |
|
| 163 | { |
|
| 164 | $em = $this->getEntityManager(); |
|
| 165 | $em->getConnection()->beginTransaction(); |
|
| 166 | try { |
|
| 167 | $rank = $Category->getRank(); |
|
| 168 | $Parent = $Category->getParent(); |
|
| 169 | ||
| 170 | if ($Parent) { |
|
| 171 | $CategoryDown = $this->createQueryBuilder('c') |
|
| 172 | ->where('c.rank < :rank AND c.Parent = :Parent') |
|
| 173 | ->setParameter('rank', $rank) |
|
| 174 | ->setParameter('Parent', $Parent) |
|
| 175 | ->orderBy('c.rank', 'DESC') |
|
| 176 | ->setMaxResults(1) |
|
| 177 | ->getQuery() |
|
| 178 | ->getSingleResult(); |
|
| 179 | } else { |
|
| 180 | $CategoryDown = $this->createQueryBuilder('c') |
|
| 181 | ->where('c.rank < :rank AND c.Parent IS NULL') |
|
| 182 | ->setParameter('rank', $rank) |
|
| 183 | ->orderBy('c.rank', 'DESC') |
|
| 184 | ->setMaxResults(1) |
|
| 185 | ->getQuery() |
|
| 186 | ->getSingleResult(); |
|
| 187 | } |
|
| 188 | ||
| 189 | $this_count = $Category->countBranches(); |
|
| 190 | $down_count = $CategoryDown->countBranches(); |
|
| 191 | ||
| 192 | $Category->calcChildrenRank($em, $down_count * -1); |
|
| 193 | $CategoryDown->calcChildrenRank($em, $this_count); |
|
| 194 | $em->flush(); |
|
| 195 | ||
| 196 | $em->getConnection()->commit(); |
|
| 197 | } catch (\Exception $e) { |
|
| 198 | $em->getConnection()->rollback(); |
|
| 199 | ||
| 200 | return false; |
|
| 201 | } |
|
| 202 | ||
| 203 | return true; |
|
| 204 | } |
|
| 205 | ||
| 206 | /** |
|
| 207 | * カテゴリを保存する. |
|