Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 538 | Rev 540 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

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