src/Repository/ConversationRepository.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Conversation;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Conversation|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Conversation|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Conversation[]    findAll()
  10.  * @method Conversation[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class ConversationRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryConversation::class);
  17.     }
  18.     public function findAdminUnseenConversations($user)
  19.     {
  20.         return $this->createQueryBuilder('c')
  21.             ->andWhere('c.user_two = :user')
  22.             ->andWhere('c.user_two_status = 0')
  23.             ->setParameter('user'$user)
  24.             ->getQuery()
  25.             ->getResult();
  26.     }
  27.     public function findProfessionalUnseenMessages($user)
  28.     {
  29.         return $this->createQueryBuilder('c')
  30.             ->andWhere('c.user_one = :user')
  31.             ->andWhere('c.user_one_status = 0')
  32.             ->setParameter('user'$user)
  33.             ->getQuery()
  34.             ->getResult();
  35.     }
  36.     public function findConversation($user)
  37.     {
  38.         return $this->createQueryBuilder('c')
  39.             ->andWhere('c.user_one = :user_one AND c.user_two = :user_two')
  40.             ->orWhere('c.user_one = :user_two AND c.user_two = :user_one')
  41.             ->setParameter('user_one'$user)
  42.             ->setParameter('user_two'$user->getOwner())
  43.             ->orderBy('c.id''ASC')
  44.             ->setMaxResults(1)
  45.             ->getQuery()
  46.             ->getResult()
  47.         ;
  48.     }
  49.     public function findAdminConversation($user)
  50.     {
  51.         return $this->createQueryBuilder('c')
  52.             ->innerJoin('c.conversationReplies''r')
  53.             ->andWhere('c.user_one = :user')
  54.             ->orWhere('c.user_two = :user')
  55.             ->setParameter('user'$user
  56.             ->orderBy('r.created_at''ASC')
  57.             ->getQuery()
  58.             ->getResult()
  59.         ;
  60.     }
  61.     // /**
  62.     //  * @return Conversation[] Returns an array of Conversation objects
  63.     //  */
  64.     /*
  65.     public function findByExampleField($value)
  66.     {
  67.         return $this->createQueryBuilder('c')
  68.             ->andWhere('c.exampleField = :val')
  69.             ->setParameter('val', $value)
  70.             ->orderBy('c.id', 'ASC')
  71.             ->setMaxResults(10)
  72.             ->getQuery()
  73.             ->getResult()
  74.         ;
  75.     }
  76.     */
  77.     /*
  78.     public function findOneBySomeField($value): ?Conversation
  79.     {
  80.         return $this->createQueryBuilder('c')
  81.             ->andWhere('c.exampleField = :val')
  82.             ->setParameter('val', $value)
  83.             ->getQuery()
  84.             ->getOneOrNullResult()
  85.         ;
  86.     }
  87.     */
  88. }