Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 537 | Rev 539 | 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
    }
69
 
70
    /**
71
     *
72
     * @param string $uuid
73
     * @return JobDescription
74
     */
75
    public function fetchOneByUuid($uuid)
76
    {
77
        $select = $this->sql->select(self::_TABLE);
78
        $select->where->equalTo('uuid', $uuid);
79
        $select->limit(1);
80
 
81
        $prototype = new JobDescription();
82
        return $this->executeFetchOneObject($select, $prototype);
83
    }
84
 
85
 
86
    /**
87
     *
88
     * @param int $company_id
89
     * @return JobDescription
90
     */
91
    public function fetchAllByCompanyId($company_id)
92
    {
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('company_id', $company_id);
95
        $select->order('name');
96
 
97
        $prototype = new JobDescription();
98
        return $this->executeFetchAllObject($select, $prototype);
99
    }
100
 
101
 
102
    /**
103
     *
104
     * @param int $company_id
105
     * @return JobDescription
106
     */
107
    public function fetchAllActiveByCompanyId($company_id)
108
    {
109
        $select = $this->sql->select(self::_TABLE);
110
        $select->where->equalTo('company_id', $company_id);
111
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
112
        $select->order('name');
113
 
114
        $prototype = new JobDescription();
115
        return $this->executeFetchAllObject($select, $prototype);
116
    }
538 geraldo 117
 
118
 
119
    /**
120
     *
121
     * @param int $company_id
122
     * @param int $job_description_id_default
123
     * @return JobDescription
124
     */
125
    public function fetchOneByCompanyId($company_id, $job_description_id_default)
126
    {
127
        $select = $this->sql->select(self::_TABLE);
128
        $select->where->equalTo('company_id', $company_id);
129
        $select->where->equalTo('job_description_id_default', $job_description_id_default);
130
        $select->limit(1);
131
 
132
        $prototype = new JobDescription();
133
        return $this->executeFetchOneObject($select, $prototype);
134
    }
192 efrain 135
 
136
 
137
    /**
138
     *
139
     * @param int $company_id
140
     * @param int $id
141
     * @return JobDescription
142
     */
143
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id)
144
    {
145
        $select = $this->sql->select(self::_TABLE);
146
        $select->where->equalTo('company_id', $company_id);
147
        $select->where->notEqualTo('id', $id);
148
        $select->order('name');
149
 
150
        $prototype = new JobDescription();
151
        return $this->executeFetchAllObject($select, $prototype);
152
    }
153
 
154
 
155
    /**
156
     *
157
     * @param int $company_id
158
     * @param int $id
159
     * @return JobDescription
160
     */
161
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id)
162
    {
163
        $select = $this->sql->select(self::_TABLE);
164
        $select->where->equalTo('company_id', $company_id);
165
        $select->where->notEqualTo('id', $id);
166
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
167
        $select->order('name');
168
 
169
        $prototype = new JobDescription();
170
        return $this->executeFetchAllObject($select, $prototype);
171
    }
172
 
537 geraldo 173
     /**
174
     *
175
     * @param string $search
176
     * @param int $page
177
     * @param int $records_per_page
178
     * @param string $order_field
179
     * @param string $order_direction
180
     * @return Paginator
181
     */
182
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
183
    {
184
        $prototype = new JobDescription();
185
        $select = $this->sql->select(self::_TABLE);
186
        $select->where->isNull('company_id');
187
 
188
        if($search) {
189
            $select->where->like('name', '%' . $search . '%');
190
        }
191
        $select->order($order_field . ' ' . $order_direction);
192
 
193
        $hydrator   = new ObjectPropertyHydrator();
194
        $resultset  = new HydratingResultSet($hydrator, $prototype);
195
 
196
        $adapter = new DbSelect($select, $this->sql, $resultset);
197
        $paginator = new Paginator($adapter);
198
        $paginator->setItemCountPerPage($records_per_page);
199
        $paginator->setCurrentPageNumber($page);
200
 
201
 
202
        return $paginator;
203
    }
204
 
192 efrain 205
 
206
    /**
207
     *
208
     * @param int $companyId
209
     * @param string $search
210
     * @param int $page
211
     * @param int $records_per_page
212
     * @param string $order_field
213
     * @param string $order_direction
214
     * @return Paginator
215
     */
216
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
217
    {
218
        $prototype = new JobDescription();
219
        $select = $this->sql->select(self::_TABLE);
220
        $select->where->equalTo('company_id', $companyId);
221
 
222
        if($search) {
223
            $select->where->like('name', '%' . $search . '%');
224
        }
225
        $select->order($order_field . ' ' . $order_direction);
226
 
227
        //echo $select->getSqlString($this->adapter->platform); exit;
228
 
229
        $hydrator   = new ObjectPropertyHydrator();
230
        $resultset  = new HydratingResultSet($hydrator, $prototype);
231
 
232
        $adapter = new DbSelect($select, $this->sql, $resultset);
233
        $paginator = new Paginator($adapter);
234
        $paginator->setItemCountPerPage($records_per_page);
235
        $paginator->setCurrentPageNumber($page);
236
 
237
 
238
        return $paginator;
239
    }
240
 
241
 
242
    /**
243
     *
244
     * @param JobDescription $jobDescription
245
     * @return boolean
246
     */
247
    public function insert($jobDescription)
248
    {
249
        $hydrator = new ObjectPropertyHydrator();
250
        $values = $hydrator->extract($jobDescription);
251
        $values = $this->removeEmpty($values);
252
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
253
 
254
 
255
        $insert = $this->sql->insert(self::_TABLE);
256
        $insert->values($values);
257
 
258
        //echo $insert->getSqlString($this->adapter->platform); exit;
259
 
260
 
261
        $result = $this->executeInsert($insert);
262
        if($result) {
263
            $jobDescription->id = $this->getLastInsertId();
264
        }
265
        return $result;
266
 
267
    }
268
 
269
    /**
270
     *
271
     * @param JobDescription $jobDescription
272
     * @return boolean
273
     */
274
    public function update($jobDescription)
275
    {
276
        $hydrator = new ObjectPropertyHydrator();
277
        $values = $hydrator->extract($jobDescription);
278
        $values = $this->removeEmpty($values);
279
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
280
 
281
        $update = $this->sql->update(self::_TABLE);
282
        $update->set($values);
283
        $update->where->equalTo('id', $jobDescription->id);
284
 
285
        return $this->executeUpdate($update);
286
    }
287
 
288
    /**
289
     *
290
     * @param JobDescription $jobDescription
291
     * @return boolean
292
     */
293
    public function delete($jobDescription)
294
    {
295
        $delete = $this->sql->delete(self::_TABLE);
296
        $delete->where->equalTo('id', $jobDescription->id);
297
 
298
        return $this->executeDelete($delete);
299
 
300
    }
301
 
302
 
303
 
304
 
305
 
306
}