1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the CCDNForum ForumBundle |
5
|
|
|
* |
6
|
|
|
* (c) CCDN (c) CodeConsortium <http://www.codeconsortium.com/> |
7
|
|
|
* |
8
|
|
|
* Available on github <http://www.github.com/codeconsortium/> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace CCDNForum\ForumBundle\Model\Component\Gateway; |
15
|
|
|
|
16
|
|
|
use Doctrine\ORM\QueryBuilder; |
17
|
|
|
use CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface; |
18
|
|
|
use CCDNForum\ForumBundle\Model\Component\Gateway\BaseGateway; |
19
|
|
|
use CCDNForum\ForumBundle\Entity\Subscription; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* |
23
|
|
|
* @category CCDNForum |
24
|
|
|
* @package ForumBundle |
25
|
|
|
* |
26
|
|
|
* @author Reece Fowell <[email protected]> |
27
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
28
|
|
|
* @version Release: 2.0 |
29
|
|
|
* @link https://github.com/codeconsortium/CCDNForumForumBundle |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
class SubscriptionGateway extends BaseGateway implements GatewayInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @access private |
37
|
|
|
* @var string $queryAlias |
38
|
|
|
*/ |
39
|
|
|
protected $queryAlias = 's'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* |
43
|
|
|
* @access public |
44
|
|
|
* @param \Doctrine\ORM\QueryBuilder $qb |
|
|
|
|
45
|
|
|
* @param Array $parameters |
|
|
|
|
46
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection |
47
|
|
|
*/ |
48
|
|
|
public function findSubscription(QueryBuilder $qb = null, $parameters = null) |
49
|
|
|
{ |
50
|
|
|
if (null == $qb) { |
51
|
|
|
$qb = $this->createSelectQuery(); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->one($qb, $parameters); |
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* |
59
|
|
|
* @access public |
60
|
|
|
* @param \Doctrine\ORM\QueryBuilder $qb |
|
|
|
|
61
|
|
|
* @param Array $parameters |
|
|
|
|
62
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection |
63
|
|
|
*/ |
64
|
|
|
public function findSubscriptions(QueryBuilder $qb = null, $parameters = null) |
65
|
|
|
{ |
66
|
|
|
if (null == $qb) { |
67
|
|
|
$qb = $this->createSelectQuery(); |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return $this->all($qb, $parameters); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* |
75
|
|
|
* @access public |
76
|
|
|
* @param \Doctrine\ORM\QueryBuilder $qb |
|
|
|
|
77
|
|
|
* @param Array $parameters |
|
|
|
|
78
|
|
|
* @return int |
79
|
|
|
*/ |
80
|
|
|
public function countSubscriptions(QueryBuilder $qb = null, $parameters = null) |
81
|
|
|
{ |
82
|
|
|
if (null == $qb) { |
83
|
|
|
$qb = $this->createCountQuery(); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
if (null == $parameters) { |
87
|
|
|
$parameters = array(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
$qb->setParameters($parameters); |
91
|
|
|
|
92
|
|
|
try { |
93
|
|
|
return $qb->getQuery()->getSingleScalarResult(); |
94
|
|
|
} catch (\Doctrine\ORM\NoResultException $e) { |
95
|
|
|
return 0; |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* |
101
|
|
|
* @access public |
102
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Subscription $subscription |
103
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface |
|
|
|
|
104
|
|
|
*/ |
105
|
|
|
public function saveSubscription(Subscription $subscription) |
106
|
|
|
{ |
107
|
|
|
$this->persist($subscription)->flush(); |
108
|
|
|
|
109
|
|
|
return $this; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* |
114
|
|
|
* @access public |
115
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Subscription $subscription |
116
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface |
|
|
|
|
117
|
|
|
*/ |
118
|
|
|
public function updateSubscription(Subscription $subscription) |
119
|
|
|
{ |
120
|
|
|
$this->persist($subscription)->flush(); |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* |
127
|
|
|
* @access public |
128
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Subscription $subscription |
129
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface |
|
|
|
|
130
|
|
|
*/ |
131
|
|
|
public function deleteSubscription(Subscription $subscription) |
132
|
|
|
{ |
133
|
|
|
$this->remove($subscription)->flush(); |
134
|
|
|
|
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* |
140
|
|
|
* @access public |
141
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Subscription |
142
|
|
|
*/ |
143
|
|
|
public function createSubscription() |
144
|
|
|
{ |
145
|
|
|
return new $this->entityClass(); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.