Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4113 | Rev 7093 | 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
use LeadersLinked\Model\JobDescription;
15
use LeadersLinked\Mapper\Common\MapperCommon;
16
use Laminas\Hydrator\ArraySerializableHydrator;
17
 
540 geraldo 18
class JobDescriptionMapper extends MapperCommon {
192 efrain 19
 
20
    const _TABLE = 'tbl_jobs_description';
21
 
22
    /**
23
     *
24
     * @var JobDescriptionMapper
25
     */
26
    private static $_instance;
540 geraldo 27
 
192 efrain 28
    /**
29
     *
30
     * @param AdapterInterface $adapter
31
     */
540 geraldo 32
    private function __construct($adapter) {
192 efrain 33
        parent::__construct($adapter);
34
    }
540 geraldo 35
 
192 efrain 36
    /**
37
     *
38
     * @param AdapterInterface $adapter
39
     * @return JobDescriptionMapper
40
     */
540 geraldo 41
    public static function getInstance($adapter) {
42
        if (self::$_instance == null) {
192 efrain 43
            self::$_instance = new JobDescriptionMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return JobDescription
52
     */
540 geraldo 53
    public function fetchOne($id) {
192 efrain 54
        $select = $this->sql->select(self::_TABLE);
55
        $select->where->equalTo('id', $id);
56
        $select->limit(1);
540 geraldo 57
 
192 efrain 58
        $prototype = new JobDescription();
59
        return $this->executeFetchOneObject($select, $prototype);
60
    }
539 geraldo 61
 
3454 efrain 62
 
63
 
539 geraldo 64
    /**
65
     *
3454 efrain 66
     * @return JobDescription[]
1246 eleazar 67
     */
3454 efrain 68
    public function fetchAllByDefault() {
1246 eleazar 69
        $select = $this->sql->select(self::_TABLE);
3454 efrain 70
        $select->where->isNull('company_id');
71
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
72
        $select->order('name');
73
 
74
 
1246 eleazar 75
        $prototype = new JobDescription();
76
        return $this->executeFetchAllObject($select, $prototype);
77
    }
78
 
79
    /**
80
     *
539 geraldo 81
     * @return JobDescription[]
82
     */
3454 efrain 83
    public function fetchAllActiveByDefault() {
539 geraldo 84
        $select = $this->sql->select(self::_TABLE);
85
        $select->where->isNull('company_id');
3454 efrain 86
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
87
        $select->order('name');
88
 
89
 
539 geraldo 90
        $prototype = new JobDescription();
91
        return $this->executeFetchAllObject($select, $prototype);
92
    }
3454 efrain 93
 
192 efrain 94
    /**
95
     *
96
     * @param string $uuid
97
     * @return JobDescription
98
     */
540 geraldo 99
    public function fetchOneByUuid($uuid) {
192 efrain 100
        $select = $this->sql->select(self::_TABLE);
101
        $select->where->equalTo('uuid', $uuid);
102
        $select->limit(1);
540 geraldo 103
 
192 efrain 104
        $prototype = new JobDescription();
105
        return $this->executeFetchOneObject($select, $prototype);
106
    }
540 geraldo 107
 
192 efrain 108
    /**
109
     *
110
     * @param int $company_id
111
     * @return JobDescription
112
     */
540 geraldo 113
    public function fetchAllByCompanyId($company_id) {
192 efrain 114
        $select = $this->sql->select(self::_TABLE);
115
        $select->where->equalTo('company_id', $company_id);
116
        $select->order('name');
540 geraldo 117
 
192 efrain 118
        $prototype = new JobDescription();
119
        return $this->executeFetchAllObject($select, $prototype);
120
    }
540 geraldo 121
 
192 efrain 122
    /**
123
     *
124
     * @param int $company_id
125
     * @return JobDescription
126
     */
540 geraldo 127
    public function fetchAllActiveByCompanyId($company_id) {
192 efrain 128
        $select = $this->sql->select(self::_TABLE);
129
        $select->where->equalTo('company_id', $company_id);
130
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
131
        $select->order('name');
3454 efrain 132
 
133
        //echo $select->getSqlString($this->adapter->platform); exit;
540 geraldo 134
 
192 efrain 135
        $prototype = new JobDescription();
136
        return $this->executeFetchAllObject($select, $prototype);
137
    }
538 geraldo 138
 
139
    /**
140
     *
141
     * @param int $company_id
142
     * @param int $job_description_id_default
143
     * @return JobDescription
144
     */
540 geraldo 145
    public function fetchOneByCompanyId($company_id, $job_description_id_default) {
538 geraldo 146
        $select = $this->sql->select(self::_TABLE);
147
        $select->where->equalTo('company_id', $company_id);
148
        $select->where->equalTo('job_description_id_default', $job_description_id_default);
149
        $select->limit(1);
540 geraldo 150
 
538 geraldo 151
        $prototype = new JobDescription();
152
        return $this->executeFetchOneObject($select, $prototype);
153
    }
540 geraldo 154
 
192 efrain 155
    /**
156
     *
157
     * @param int $company_id
158
     * @param int $id
159
     * @return JobDescription
160
     */
540 geraldo 161
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id) {
192 efrain 162
        $select = $this->sql->select(self::_TABLE);
163
        $select->where->equalTo('company_id', $company_id);
164
        $select->where->notEqualTo('id', $id);
165
        $select->order('name');
540 geraldo 166
 
192 efrain 167
        $prototype = new JobDescription();
168
        return $this->executeFetchAllObject($select, $prototype);
169
    }
540 geraldo 170
 
192 efrain 171
    /**
172
     *
173
     * @param int $company_id
174
     * @param int $id
175
     * @return JobDescription
176
     */
540 geraldo 177
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id) {
4113 efrain 178
 
179
 
180
 
181
 
182
 
192 efrain 183
        $select = $this->sql->select(self::_TABLE);
184
        $select->where->equalTo('company_id', $company_id);
185
        $select->where->notEqualTo('id', $id);
186
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
187
        $select->order('name');
540 geraldo 188
 
192 efrain 189
        $prototype = new JobDescription();
190
        return $this->executeFetchAllObject($select, $prototype);
191
    }
4113 efrain 192
 
193
     /**
537 geraldo 194
     *
195
     * @param string $search
196
     * @param int $page
197
     * @param int $records_per_page
198
     * @param string $order_field
199
     * @param string $order_direction
200
     * @return Paginator
201
     */
540 geraldo 202
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
537 geraldo 203
        $prototype = new JobDescription();
204
        $select = $this->sql->select(self::_TABLE);
205
        $select->where->isNull('company_id');
540 geraldo 206
 
207
        if ($search) {
537 geraldo 208
            $select->where->like('name', '%' . $search . '%');
209
        }
210
        $select->order($order_field . ' ' . $order_direction);
540 geraldo 211
 
212
        $hydrator = new ObjectPropertyHydrator();
213
        $resultset = new HydratingResultSet($hydrator, $prototype);
214
 
537 geraldo 215
        $adapter = new DbSelect($select, $this->sql, $resultset);
216
        $paginator = new Paginator($adapter);
217
        $paginator->setItemCountPerPage($records_per_page);
218
        $paginator->setCurrentPageNumber($page);
540 geraldo 219
 
220
 
537 geraldo 221
        return $paginator;
222
    }
223
 
192 efrain 224
    /**
225
     *
226
     * @param int $companyId
227
     * @param string $search
228
     * @param int $page
229
     * @param int $records_per_page
230
     * @param string $order_field
231
     * @param string $order_direction
232
     * @return Paginator
233
     */
540 geraldo 234
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
192 efrain 235
        $prototype = new JobDescription();
236
        $select = $this->sql->select(self::_TABLE);
237
        $select->where->equalTo('company_id', $companyId);
540 geraldo 238
 
239
        if ($search) {
192 efrain 240
            $select->where->like('name', '%' . $search . '%');
241
        }
242
        $select->order($order_field . ' ' . $order_direction);
540 geraldo 243
 
192 efrain 244
        //echo $select->getSqlString($this->adapter->platform); exit;
540 geraldo 245
 
246
        $hydrator = new ObjectPropertyHydrator();
247
        $resultset = new HydratingResultSet($hydrator, $prototype);
248
 
192 efrain 249
        $adapter = new DbSelect($select, $this->sql, $resultset);
250
        $paginator = new Paginator($adapter);
251
        $paginator->setItemCountPerPage($records_per_page);
252
        $paginator->setCurrentPageNumber($page);
540 geraldo 253
 
254
 
192 efrain 255
        return $paginator;
256
    }
6951 efrain 257
 
258
 
259
    /**
260
     *
261
     * @return JobDescription[]
262
     */
263
    public function fetchAllDefaultOrderByPositionName()
264
    {
265
        $select = $this->sql->select(self::_TABLE);
266
        $select->order('job_description_id_boss, position, name');
267
 
268
        $prototype = new JobDescription();
269
        return $this->executeFetchAllObject($select, $prototype);
270
    }
271
 
272
 
273
    /**
274
     *
275
     * @param int $companyId
276
     * @return JobDescription[]
277
     */
278
    public function fetchAllByCompanyIdOrderByPositionName($companyId)
279
    {
280
        $select = $this->sql->select(self::_TABLE);
281
        $select->where->equalTo('company_id', $companyId);
282
        $select->order('job_description_id_boss, position, name');
283
 
284
 
285
        $prototype = new JobDescription();
286
        return $this->executeFetchAllObject($select, $prototype);
287
 
288
    }
289
 
290
 
291
    /**
292
     *
293
     * @param int $job_description_id_boss
294
     * @return JobDescription[]
295
     */
296
    public function fetchAllDefaultAndJobDescriptionIdBoss($job_description_id_boss)
297
    {
298
        $select = $this->sql->select(self::_TABLE);
299
        if($job_description_id_boss) {
300
            $select->where->equalTo('job_description_id_boss', $job_description_id_boss);
301
        } else {
302
            $select->where->isNull('job_description_id_boss');
303
        }
304
        $select->order('position, name');
540 geraldo 305
 
6951 efrain 306
        $prototype = new JobDescription();
307
        return $this->executeFetchAllObject($select, $prototype);
308
    }
309
 
310
 
192 efrain 311
    /**
312
     *
6951 efrain 313
     * @param int $companyId
314
     * @return JobDescription[]
315
     */
316
    public function fetchAllByCompanyIdAndJobDescriptionIdBoss($companyId, $job_description_id_boss)
317
    {
318
        $select = $this->sql->select(self::_TABLE);
319
        $select->where->equalTo('company_id', $companyId);
320
        if($job_description_id_boss) {
321
            $select->where->equalTo('job_description_id_boss', $job_description_id_boss);
322
        } else {
323
            $select->where->isNull('job_description_id_boss');
324
        }
325
        $select->order('position, name');
326
 
327
 
328
        //echo $select->getSqlString($this->adapter->platform); exit;
329
 
330
 
331
        $prototype = new JobDescription();
332
        return $this->executeFetchAllObject($select, $prototype);
333
 
334
    }
335
 
336
    /**
337
     *
192 efrain 338
     * @param JobDescription $jobDescription
339
     * @return boolean
340
     */
540 geraldo 341
    public function insert($jobDescription) {
192 efrain 342
        $hydrator = new ObjectPropertyHydrator();
343
        $values = $hydrator->extract($jobDescription);
344
        $values = $this->removeEmpty($values);
4113 efrain 345
 
192 efrain 346
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
540 geraldo 347
 
348
 
192 efrain 349
        $insert = $this->sql->insert(self::_TABLE);
350
        $insert->values($values);
540 geraldo 351
 
192 efrain 352
        //echo $insert->getSqlString($this->adapter->platform); exit;
540 geraldo 353
 
354
 
192 efrain 355
        $result = $this->executeInsert($insert);
540 geraldo 356
        if ($result) {
192 efrain 357
            $jobDescription->id = $this->getLastInsertId();
358
        }
359
        return $result;
360
    }
540 geraldo 361
 
192 efrain 362
    /**
363
     *
364
     * @param JobDescription $jobDescription
365
     * @return boolean
366
     */
540 geraldo 367
    public function update($jobDescription) {
192 efrain 368
        $hydrator = new ObjectPropertyHydrator();
369
        $values = $hydrator->extract($jobDescription);
370
        $values = $this->removeEmpty($values);
4113 efrain 371
 
192 efrain 372
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
540 geraldo 373
 
192 efrain 374
        $update = $this->sql->update(self::_TABLE);
375
        $update->set($values);
376
        $update->where->equalTo('id', $jobDescription->id);
540 geraldo 377
 
192 efrain 378
        return $this->executeUpdate($update);
379
    }
540 geraldo 380
 
192 efrain 381
    /**
382
     *
383
     * @param JobDescription $jobDescription
384
     * @return boolean
385
     */
540 geraldo 386
    public function delete($jobDescription) {
192 efrain 387
        $delete = $this->sql->delete(self::_TABLE);
388
        $delete->where->equalTo('id', $jobDescription->id);
540 geraldo 389
 
192 efrain 390
        return $this->executeDelete($delete);
391
    }
6951 efrain 392
 
393
 
394
    /**
395
     *
396
     * @param int $job_description_id
397
     * @param int $position
398
     * @return boolean
399
     */
400
    public function removeJobDescriptionIdBossByJobDescriptionId($job_description_id, $position)
401
    {
402
        $values = [
403
            'job_description_id_boss' => null,
404
            'position' => $position,
405
        ];
406
 
407
        $update = $this->sql->update(self::_TABLE);
408
        $update->set($values);
409
        $update->where->equalTo('id', $job_description_id);
410
 
411
        //error_log($update->getSqlString($this->adapter->platform));
412
 
413
        return $this->executeUpdate($update);
414
    }
415
 
416
    /**
417
     *
418
     * @param int $job_description_id_boss
419
     * @return int
420
     */
421
    public function fetchMaxPositionByJobDescriptionIdBoss($job_description_id_boss)
422
    {
423
        $select = $this->sql->select(self::_TABLE);
424
        $select->columns(['max' => new Expression('MAX(position)')]);
425
        $select->where->equalTo('id', $job_description_id_boss);
426
 
427
        $record = $this->executeFetchOneArray($select);
428
 
429
        return intval($record['max'], 10);
430
    }
431
 
432
 
433
    /**
434
     *
435
     * @param int $job_description_id
436
     * @param int $job_description_id_boss
437
     * @param int $position
438
     * @return boolean
439
     */
440
    public function setJobDescriptionIdBossByJobDescripcionId($job_description_id, $job_description_id_boss, $position)
441
    {
192 efrain 442
 
6951 efrain 443
        $values = [
444
            'job_description_id_boss' => $job_description_id_boss,
445
            'position' => $position
446
        ];
447
 
448
        $update = $this->sql->update(self::_TABLE);
449
        $update->set($values);
450
        $update->where->equalTo('id', $job_description_id);
451
 
452
        //error_log($update->getSqlString($this->adapter->platform));
453
 
454
        return $this->executeUpdate($update);
455
    }
550 geraldo 456
 
457
 
6951 efrain 458
    /**
459
     *
460
     * @param JobDescription $jobDescription
461
     * @return boolean
462
     */
463
    public function removeAllJobDescriptionIdBossByJobDescripcionId($job_description_id)
464
    {
465
        $values = [
466
            'job_description_id_boss' => null,
467
        ];
468
 
469
        $update = $this->sql->update(self::_TABLE);
470
        $update->set($values);
471
        $update->where->equalTo('id', $job_description_id);
472
 
473
        //error_log($update->getSqlString($this->adapter->platform));
474
 
475
        return $this->executeUpdate($update);
476
    }
477
 
478
 
540 geraldo 479
}