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