| @@ 164-192 (lines=29) @@ | ||
| 161 | * |
|
| 162 | * @return Doctrine\ORM\Query |
|
| 163 | */ |
|
| 164 | public function getExpiringSubscriptionsCount($now, $notify, $days = 7) |
|
| 165 | { |
|
| 166 | $qb = $this->createQueryBuilder('s'); |
|
| 167 | $qb |
|
| 168 | ->select('count(s)') |
|
| 169 | ->where("DATE_SUB(s.expire_at, :days, 'DAY') < :now") |
|
| 170 | ->andWhere('s.active = :status'); |
|
| 171 | ||
| 172 | switch ($notify) { |
|
| 173 | case Emails::NOTIFY_LEVEL_ONE: |
|
| 174 | $qb->andWhere($qb->expr()->isNull('s.notifySentLevelOne')); |
|
| 175 | break; |
|
| 176 | case Emails::NOTIFY_LEVEL_TWO: |
|
| 177 | $qb->andWhere($qb->expr()->isNotNull('s.notifySentLevelOne')); |
|
| 178 | $qb->andWhere($qb->expr()->isNull('s.notifySentLevelTwo')); |
|
| 179 | break; |
|
| 180 | default: |
|
| 181 | break; |
|
| 182 | } |
|
| 183 | ||
| 184 | $qb->setParameters(array( |
|
| 185 | 'status' => 'Y', |
|
| 186 | 'now' => $now, |
|
| 187 | 'days' => $days, |
|
| 188 | )) |
|
| 189 | ->orderBy('s.created_at', 'desc'); |
|
| 190 | ||
| 191 | return $qb->getQuery(); |
|
| 192 | } |
|
| 193 | ||
| 194 | /** |
|
| 195 | * Gets expiration subscriptions query. |
|
| @@ 205-235 (lines=31) @@ | ||
| 202 | * |
|
| 203 | * @return Doctrine\ORM\Query |
|
| 204 | */ |
|
| 205 | public function getExpiringSubscriptions($offset, $batch, $now, $notify, $days = 7) |
|
| 206 | { |
|
| 207 | $qb = $this->createQueryBuilder('s'); |
|
| 208 | $qb |
|
| 209 | ->where("DATE_SUB(s.expire_at, :days, 'DAY') < :now") |
|
| 210 | ->andWhere('s.active = :status'); |
|
| 211 | ||
| 212 | switch ($notify) { |
|
| 213 | case Emails::NOTIFY_LEVEL_ONE: |
|
| 214 | $qb->andWhere($qb->expr()->isNull('s.notifySentLevelOne')); |
|
| 215 | break; |
|
| 216 | case Emails::NOTIFY_LEVEL_TWO: |
|
| 217 | $qb->andWhere($qb->expr()->isNotNull('s.notifySentLevelOne')); |
|
| 218 | $qb->andWhere($qb->expr()->isNull('s.notifySentLevelTwo')); |
|
| 219 | break; |
|
| 220 | default: |
|
| 221 | break; |
|
| 222 | } |
|
| 223 | ||
| 224 | $qb |
|
| 225 | ->setParameters(array( |
|
| 226 | 'status' => 'Y', |
|
| 227 | 'now' => $now, |
|
| 228 | 'days' => $days, |
|
| 229 | )) |
|
| 230 | ->orderBy('s.created_at', 'desc') |
|
| 231 | ->setFirstResult($offset) |
|
| 232 | ->setMaxResults($batch); |
|
| 233 | ||
| 234 | return $qb->getQuery(); |
|
| 235 | } |
|
| 236 | ||
| 237 | public function getValidSubscriptionsBy($userId) |
|
| 238 | { |
|