1 |
www |
1 |
<?php
|
|
|
2 |
declare(strict_types=1);
|
|
|
3 |
|
|
|
4 |
namespace LeadersLinked\Mapper;
|
|
|
5 |
|
|
|
6 |
use LeadersLinked\Mapper\Common\MapperCommon;
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
use LeadersLinked\Model\CompanyMicrolearningCapsule;
|
|
|
9 |
use Laminas\Db\Sql\Expression;
|
|
|
10 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
11 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
12 |
use Laminas\Paginator\Paginator;
|
|
|
13 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
class CompanyMicrolearningCapsuleMapper extends MapperCommon
|
|
|
17 |
{
|
|
|
18 |
const _TABLE = 'tbl_company_microlearning_capsules';
|
|
|
19 |
|
|
|
20 |
/**
|
|
|
21 |
*
|
|
|
22 |
* @var CompanyMicrolearningCapsuleMapper
|
|
|
23 |
*/
|
|
|
24 |
private static $_instance;
|
|
|
25 |
/**
|
|
|
26 |
*
|
|
|
27 |
* @param AdapterInterface $adapter
|
|
|
28 |
*/
|
|
|
29 |
private function __construct($adapter)
|
|
|
30 |
{
|
|
|
31 |
parent::__construct($adapter);
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
*
|
|
|
36 |
* @param AdapterInterface $adapter
|
|
|
37 |
* @return CompanyMicrolearningCapsuleMapper
|
|
|
38 |
*/
|
|
|
39 |
public static function getInstance($adapter)
|
|
|
40 |
{
|
|
|
41 |
if(self::$_instance == null) {
|
|
|
42 |
self::$_instance = new CompanyMicrolearningCapsuleMapper($adapter);
|
|
|
43 |
}
|
|
|
44 |
return self::$_instance;
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
/**
|
|
|
48 |
*
|
|
|
49 |
* @param int $company_id
|
|
|
50 |
* @param int $topic_id
|
|
|
51 |
* @return int
|
|
|
52 |
*/
|
|
|
53 |
public function fetchTotalCountByCompanyIdAndTopicId($company_id, $topic_id)
|
|
|
54 |
{
|
|
|
55 |
$select = $this->sql->select();
|
|
|
56 |
$select->columns(['total' => new Expression('COUNT(*)')]);
|
|
|
57 |
$select->from(self::_TABLE);
|
|
|
58 |
$select->where->equalTo('company_id', $company_id);
|
|
|
59 |
$select->where->equalTo('topic_id', $topic_id);
|
|
|
60 |
|
|
|
61 |
$record = $this->executeFetchOneArray($select);
|
|
|
62 |
return $record['total'];
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
*
|
|
|
67 |
* @param int $company_id
|
|
|
68 |
* @return int
|
|
|
69 |
*/
|
|
|
70 |
public function fetchTotalCountAllActiveByCompanyId($company_id)
|
|
|
71 |
{
|
|
|
72 |
$select = $this->sql->select();
|
|
|
73 |
$select->columns(['total' => new Expression('COUNT(*)')]);
|
|
|
74 |
$select->from(self::_TABLE);
|
|
|
75 |
$select->where->equalTo('company_id', $company_id);
|
|
|
76 |
$select->where->equalTo('status', CompanyMicrolearningCapsule::STATUS_ACTIVE);
|
|
|
77 |
|
|
|
78 |
$record = $this->executeFetchOneArray($select);
|
|
|
79 |
return $record['total'];
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
*
|
|
|
84 |
* @param int $id
|
|
|
85 |
* @return CompanyMicrolearningCapsule
|
|
|
86 |
*/
|
|
|
87 |
public function fetchOne($id)
|
|
|
88 |
{
|
|
|
89 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
90 |
|
|
|
91 |
$select = $this->sql->select(self::_TABLE);
|
|
|
92 |
$select->where->equalTo('id', $id);
|
|
|
93 |
|
|
|
94 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
*
|
|
|
99 |
* @param int $uuid
|
|
|
100 |
* @return CompanyMicrolearningCapsule
|
|
|
101 |
*/
|
|
|
102 |
public function fetchOneByUuid($uuid)
|
|
|
103 |
{
|
|
|
104 |
$prototype = new CompanyMicrolearningCapsule;
|
|
|
105 |
$select = $this->sql->select(self::_TABLE);
|
|
|
106 |
$select->where->equalTo('uuid', $uuid);
|
|
|
107 |
|
|
|
108 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
*
|
|
|
113 |
* @param int $company_id
|
|
|
114 |
* @param int $topic_id
|
|
|
115 |
* @return CompanyMicrolearningCapsule[]
|
|
|
116 |
*/
|
|
|
117 |
public function fetchAllActiveByCompanyIdAndTopicId($company_id, $topic_id)
|
|
|
118 |
{
|
|
|
119 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
120 |
|
|
|
121 |
$select = $this->sql->select(self::_TABLE);
|
|
|
122 |
$select->where->equalTo('company_id', $company_id);
|
|
|
123 |
$select->where->equalTo('topic_id', $topic_id);
|
|
|
124 |
$select->where->equalTo('status', CompanyMicrolearningCapsule::STATUS_ACTIVE);
|
|
|
125 |
$select->order(['order', 'name']);
|
|
|
126 |
|
|
|
127 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
/**
|
|
|
131 |
*
|
|
|
132 |
* @param int $company_id
|
|
|
133 |
* @param int $topic_id
|
|
|
134 |
* @return CompanyMicrolearningCapsule[]
|
|
|
135 |
*/
|
|
|
136 |
public function fetchAllByCompanyIdAndTopicId($company_id, $topic_id)
|
|
|
137 |
{
|
|
|
138 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
139 |
|
|
|
140 |
$select = $this->sql->select(self::_TABLE);
|
|
|
141 |
$select->where->equalTo('company_id', $company_id);
|
|
|
142 |
$select->where->equalTo('topic_id', $topic_id);
|
|
|
143 |
$select->order(['order', 'name']);
|
|
|
144 |
|
|
|
145 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
146 |
|
|
|
147 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
148 |
}
|
|
|
149 |
|
3831 |
efrain |
150 |
/**
|
|
|
151 |
*
|
|
|
152 |
* @param int $company_id
|
|
|
153 |
* @param int $topic_id
|
|
|
154 |
* @return int
|
|
|
155 |
*/
|
|
|
156 |
public function fetchCountByCompanyIdAndTopicId($company_id, $topic_id)
|
|
|
157 |
{
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
$select = $this->sql->select(self::_TABLE);
|
|
|
161 |
$select->columns(['total' => new Expression('COUNT(*)')]);
|
|
|
162 |
$select->where->equalTo('company_id', $company_id);
|
|
|
163 |
$select->where->equalTo('topic_id', $topic_id);
|
|
|
164 |
|
|
|
165 |
$record = $this->executeFetchOneArray($select);
|
|
|
166 |
return $record['total'];
|
|
|
167 |
|
|
|
168 |
}
|
1 |
www |
169 |
|
3831 |
efrain |
170 |
|
|
|
171 |
|
|
|
172 |
|
1 |
www |
173 |
/**
|
|
|
174 |
*
|
|
|
175 |
|
|
|
176 |
* @return CompanyMicrolearningCapsule[]
|
|
|
177 |
*/
|
|
|
178 |
public function fetchAllActiveAndPublic()
|
|
|
179 |
{
|
|
|
180 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
181 |
|
|
|
182 |
$select = $this->sql->select(self::_TABLE);
|
|
|
183 |
|
|
|
184 |
$select->where->equalTo('status', CompanyMicrolearningCapsule::STATUS_ACTIVE);
|
|
|
185 |
$select->where->equalTo('privacy', CompanyMicrolearningCapsule::PRIVACY_PUBLIC);
|
|
|
186 |
$select->where->equalTo('type', CompanyMicrolearningCapsule::TYPE_FREE);
|
|
|
187 |
|
|
|
188 |
$select->order(['order', 'name']);
|
|
|
189 |
|
|
|
190 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
191 |
}
|
|
|
192 |
|
|
|
193 |
|
|
|
194 |
/**
|
|
|
195 |
*
|
112 |
efrain |
196 |
|
|
|
197 |
* @return CompanyMicrolearningCapsule[]
|
|
|
198 |
*/
|
|
|
199 |
public function fetchAllActive()
|
|
|
200 |
{
|
|
|
201 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
202 |
|
|
|
203 |
$select = $this->sql->select(self::_TABLE);
|
|
|
204 |
|
|
|
205 |
$select->where->equalTo('status', CompanyMicrolearningCapsule::STATUS_ACTIVE);
|
|
|
206 |
|
|
|
207 |
$select->order(['order', 'name']);
|
|
|
208 |
|
|
|
209 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
210 |
}
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
/**
|
|
|
214 |
*
|
|
|
215 |
|
|
|
216 |
* @return CompanyMicrolearningCapsule[]
|
|
|
217 |
*/
|
|
|
218 |
public function fetchAll()
|
|
|
219 |
{
|
|
|
220 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
221 |
|
|
|
222 |
$select = $this->sql->select(self::_TABLE);
|
|
|
223 |
$select->order(['order', 'name']);
|
|
|
224 |
|
|
|
225 |
return $this->executeFetchAllObject($select, $prototype);
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
/**
|
|
|
230 |
*
|
1 |
www |
231 |
* @param int $companyId
|
|
|
232 |
* @param int $topicId
|
|
|
233 |
* @param string $search
|
|
|
234 |
* @param int $page
|
|
|
235 |
* @param int $records_per_page
|
|
|
236 |
* @param string $order_field
|
|
|
237 |
* @param string $order_direction
|
|
|
238 |
* @return Paginator
|
|
|
239 |
*/
|
|
|
240 |
public function fetchAllDataTableByCompanyIdAndTopicId($companyId, $topicId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
|
|
|
241 |
{
|
|
|
242 |
$prototype = new CompanyMicrolearningCapsule();
|
|
|
243 |
$select = $this->sql->select(self::_TABLE);
|
|
|
244 |
$select->where->equalTo('company_id', $companyId);
|
|
|
245 |
$select->where->equalTo('topic_id', $topicId);
|
|
|
246 |
|
|
|
247 |
if($search) {
|
|
|
248 |
$select->where->like('name', '%' . $search . '%');
|
|
|
249 |
}
|
|
|
250 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
251 |
|
|
|
252 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
253 |
|
|
|
254 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
255 |
$resultset = new HydratingResultSet($hydrator, $prototype);
|
|
|
256 |
|
|
|
257 |
$adapter = new DbSelect($select, $this->sql, $resultset);
|
|
|
258 |
$paginator = new Paginator($adapter);
|
|
|
259 |
$paginator->setItemCountPerPage($records_per_page);
|
|
|
260 |
$paginator->setCurrentPageNumber($page);
|
|
|
261 |
|
|
|
262 |
|
|
|
263 |
return $paginator;
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
|
|
|
267 |
/**
|
|
|
268 |
*
|
|
|
269 |
* @param CompanyMicrolearningCapsule $capsule
|
|
|
270 |
* @return boolean
|
|
|
271 |
*/
|
|
|
272 |
public function insert($capsule)
|
|
|
273 |
{
|
|
|
274 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
275 |
$values = $hydrator->extract($capsule);
|
|
|
276 |
$values = $this->removeEmpty($values);
|
|
|
277 |
$values['cost'] = isset($values['cost']) ? $values['cost'] : 0;
|
|
|
278 |
|
|
|
279 |
|
|
|
280 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
281 |
$insert->values($values);
|
|
|
282 |
|
|
|
283 |
$result = $this->executeInsert($insert);
|
|
|
284 |
if($result) {
|
|
|
285 |
$capsule->id = $this->lastInsertId;
|
|
|
286 |
}
|
|
|
287 |
return $result;
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
/**
|
|
|
291 |
*
|
|
|
292 |
* @param CompanyMicrolearningCapsule $capsule
|
|
|
293 |
* @return boolean
|
|
|
294 |
*/
|
|
|
295 |
public function update($capsule)
|
|
|
296 |
{
|
|
|
297 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
298 |
$values = $hydrator->extract($capsule);
|
|
|
299 |
$values = $this->removeEmpty($values);
|
|
|
300 |
$values['cost'] = isset($values['cost']) ? $values['cost'] : 0;
|
|
|
301 |
|
|
|
302 |
$update = $this->sql->update(self::_TABLE);
|
|
|
303 |
$update->set($values);
|
|
|
304 |
$update->where->equalTo('id', $capsule->id);
|
|
|
305 |
|
|
|
306 |
return $this->executeUpdate($update);
|
|
|
307 |
}
|
|
|
308 |
|
|
|
309 |
/**
|
|
|
310 |
*
|
|
|
311 |
* @param CompanyMicrolearningCapsule $capsule
|
|
|
312 |
* @return boolean
|
|
|
313 |
*/
|
|
|
314 |
public function delete($capsule)
|
|
|
315 |
{
|
|
|
316 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
317 |
$delete->where->equalTo('id', $capsule->id);
|
|
|
318 |
|
|
|
319 |
return $this->executeDelete($delete);
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
|
324 |
}
|