Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 3639 | | Comparar con el anterior | Ultima modificación | Ver Log |

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