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\Board; |
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 BoardGateway extends BaseGateway implements GatewayInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* |
36
|
|
|
* @access private |
37
|
|
|
* @var string $queryAlias |
38
|
|
|
*/ |
39
|
|
|
protected $queryAlias = 'b'; |
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 findBoard(QueryBuilder $qb = null, $parameters = null) |
49
|
|
|
{ |
50
|
|
|
if (null == $qb) { |
51
|
|
|
$qb = $this->createSelectQuery(); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$qb->addOrderBy('b.listOrderPriority', 'ASC'); |
55
|
|
|
|
56
|
|
|
return $this->one($qb, $parameters); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* |
61
|
|
|
* @access public |
62
|
|
|
* @param \Doctrine\ORM\QueryBuilder $qb |
|
|
|
|
63
|
|
|
* @param Array $parameters |
|
|
|
|
64
|
|
|
* @return \Doctrine\Common\Collections\ArrayCollection |
65
|
|
|
*/ |
66
|
|
|
public function findBoards(QueryBuilder $qb = null, $parameters = null) |
67
|
|
|
{ |
68
|
|
|
if (null == $qb) { |
69
|
|
|
$qb = $this->createSelectQuery(); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
$qb->addOrderBy('b.listOrderPriority', 'ASC'); |
73
|
|
|
|
74
|
|
|
return $this->all($qb, $parameters); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* |
79
|
|
|
* @access public |
80
|
|
|
* @param \Doctrine\ORM\QueryBuilder $qb |
|
|
|
|
81
|
|
|
* @param Array $parameters |
|
|
|
|
82
|
|
|
* @return int |
83
|
|
|
*/ |
84
|
|
|
public function countBoards(QueryBuilder $qb = null, $parameters = null) |
85
|
|
|
{ |
86
|
|
|
if (null == $qb) { |
87
|
|
|
$qb = $this->createCountQuery(); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
if (null == $parameters) { |
91
|
|
|
$parameters = array(); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$qb->setParameters($parameters); |
95
|
|
|
|
96
|
|
|
try { |
97
|
|
|
return $qb->getQuery()->getSingleScalarResult(); |
98
|
|
|
} catch (\Doctrine\ORM\NoResultException $e) { |
99
|
|
|
return 0; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* |
105
|
|
|
* @access public |
106
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Board $board |
107
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface |
|
|
|
|
108
|
|
|
*/ |
109
|
|
|
public function saveBoard(Board $board) |
110
|
|
|
{ |
111
|
|
|
$this->persist($board)->flush(); |
112
|
|
|
|
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* |
118
|
|
|
* @access public |
119
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Board $board |
120
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface |
|
|
|
|
121
|
|
|
*/ |
122
|
|
|
public function updateBoard(Board $board) |
123
|
|
|
{ |
124
|
|
|
$this->persist($board)->flush(); |
125
|
|
|
|
126
|
|
|
return $this; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* |
131
|
|
|
* @access public |
132
|
|
|
* @param \CCDNForum\ForumBundle\Entity\Board $board |
133
|
|
|
* @return \CCDNForum\ForumBundle\Model\Component\Gateway\GatewayInterface |
|
|
|
|
134
|
|
|
*/ |
135
|
|
|
public function deleteBoard(Board $board) |
136
|
|
|
{ |
137
|
|
|
$this->remove($board)->flush(); |
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* |
144
|
|
|
* @access public |
145
|
|
|
* @return \CCDNForum\ForumBundle\Entity\Board |
146
|
|
|
*/ |
147
|
|
|
public function createBoard() |
148
|
|
|
{ |
149
|
|
|
return new $this->entityClass(); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|
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.