src/Repository/CarriersSubscriptionsRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\CarriersSubscriptions;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\ORM\Exception\ORMException;
  6. use Doctrine\ORM\OptimisticLockException;
  7. use Doctrine\Persistence\ManagerRegistry;
  8. /**
  9.  * @extends ServiceEntityRepository<CarriersSubscriptions>
  10.  *
  11.  * @method CarriersSubscriptions|null find($id, $lockMode = null, $lockVersion = null)
  12.  * @method CarriersSubscriptions|null findOneBy(array $criteria, array $orderBy = null)
  13.  * @method CarriersSubscriptions[]    findAll()
  14.  * @method CarriersSubscriptions[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  15.  */
  16. class CarriersSubscriptionsRepository extends ServiceEntityRepository
  17. {
  18.     public function __construct(ManagerRegistry $registry)
  19.     {
  20.         parent::__construct($registry, CarriersSubscriptions::class);
  21.     }
  22.     /**
  23.      * @throws ORMException
  24.      * @throws OptimisticLockException
  25.      */
  26.     public function add(CarriersSubscriptions $entity, bool $flush = false): void
  27.     {
  28.         $this->_em->persist($entity);
  29.         if ($flush) {
  30.             $this->_em->flush();
  31.         }
  32.     }
  33.     /**
  34.      * @throws ORMException
  35.      * @throws OptimisticLockException
  36.      */
  37.     public function remove(CarriersSubscriptions $entity, bool $flush = false): void
  38.     {
  39.         $this->_em->remove($entity);
  40.         if ($flush) {
  41.             $this->_em->flush();
  42.         }
  43.     }
  44. //    /**
  45. //     * @return CarriersSubscriptions[] Returns an array of CarriersSubscriptions objects
  46. //     */
  47. //    public function findByExampleField($value): array
  48. //    {
  49. //        return $this->createQueryBuilder('c')
  50. //            ->andWhere('c.exampleField = :val')
  51. //            ->setParameter('val', $value)
  52. //            ->orderBy('c.id', 'ASC')
  53. //            ->setMaxResults(10)
  54. //            ->getQuery()
  55. //            ->getResult()
  56. //        ;
  57. //    }
  58. //    public function findOneBySomeField($value): ?CarriersSubscriptions
  59. //    {
  60. //        return $this->createQueryBuilder('c')
  61. //            ->andWhere('c.exampleField = :val')
  62. //            ->setParameter('val', $value)
  63. //            ->getQuery()
  64. //            ->getOneOrNullResult()
  65. //        ;
  66. //    }
  67.     public function findCarrierSubscriptionsByCarrier($carrier_id){
  68.         return $this->createQueryBuilder('c')
  69.             ->select('c.id, c.unsubscribed_at, c.nbDesiredVehicles, c.subscribed_at, c.start_at, c.trial_end_date, p.trial_duration_days')
  70.             ->leftJoin('c.carriers', 'ca')
  71.             ->leftJoin('c.package', 'p')
  72.             ->where('ca.id = :carrier_id')
  73.             ->setParameter('carrier_id', $carrier_id)
  74.             ->getQuery()
  75.             ->getResult();
  76.     }
  77.     public function findCarrierSubscriptionsEndsBefore2Months(){
  78.         return $this->createQueryBuilder('c')
  79.             ->select('ca.id AS carrier_id, c.id, c.unsubscribed_at,c.end_at')
  80.             ->leftJoin('c.carriers', 'ca')
  81.             ->getQuery()
  82.             ->getResult();
  83.     }
  84.     public function getExpirationAccountDate($carrier_id){
  85.         return $this->createQueryBuilder('cs')
  86.             ->select('cs.subscribed_at, p.nbr_month_of_validity')
  87.             ->leftJoin('cs.package', 'p')
  88.             ->leftJoin('cs.carriers', 'ca')
  89.             ->where('ca.id = :carrier_id')
  90.             ->setParameter('carrier_id', $carrier_id)
  91.             ->getQuery()
  92.             ->getResult();
  93.     }
  94.     public function getLastSubscription($carrier_id,$status){
  95.         return $this->createQueryBuilder('cs')
  96.             ->select('cs.id, cs.subscribed_at,cs.start_at,cs.end_at,cs.nbDesiredVehicles,pa.trial_duration_days')
  97.             ->leftJoin('cs.carriers', 'ca')
  98.             ->leftJoin('cs.payment', 'p')
  99.             ->leftJoin('cs.package', 'pa')
  100.             ->where('ca.id = :carrier_id')
  101.             ->setParameter('carrier_id', $carrier_id)
  102.             ->andWhere('p.status = :status')
  103.             ->setParameter('status', $status)
  104.             ->orderBy('cs.id', 'DESC')
  105.             ->setMaxResults(1)
  106.             ->getQuery()
  107.             ->getResult();
  108.     }
  109. }