Blame view

app/Queries/Subscription/SubscriptionQueryHandler.php 1.16 KB
e77200db5   nologostudio.ru   Initial commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  <?php
  
  namespace FootyRoom\Queries\Subscription;
  
  use Illuminate\Database\Connection;
  
  class SubscriptionQueryHandler
  {
      /**
       * @var \Illuminate\Database\Connection
       */
      protected $mysql;
  
      /**
       * Constructor.
       *
       * @param \Illuminate\Database\Connection $mysql
       */
      public function __construct(Connection $mysql)
      {
          $this->mysql = $mysql;
      }
  
      /**
       * Find subscription.
       *
       * @param \FootyRoom\Queries\Subscription\OneSubscriptionQuery $query
       *
       * @return object
       */
      public function findOne(OneSubscriptionQuery $query)
      {
          $builder = $this->mysql
  
          ->table('subscriptions');
  
          if ($query->getUserId()) {
              $builder->where('user_id', '=', $query->getUserId());
          }
  
          if ($query->getSubjectType()) {
              $builder->where('subject_type', '=', $query->getSubjectType());
          }
  
          if ($query->getSubjectId()) {
              $builder->where('subject_id', '=', $query->getSubjectId());
          }
  
          $subscription = $builder->first();
  
          if (!$subscription) {
              return null;
          }
  
          return $subscription;
      }
  }