Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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