Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 531 | | 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\JobDescriptionCompetency;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
use Laminas\Hydrator\ArraySerializableHydrator;
18
 
19
 
20
 
21
class JobDescriptionCompetencyMapper extends MapperCommon
22
{
23
    const _TABLE = 'tbl_job_description_competencies';
24
 
25
 
26
    /**
27
     *
28
     * @var JobDescriptionCompetencyMapper
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 JobDescriptionCompetencyMapper
45
     */
46
    public static function getInstance($adapter)
47
    {
48
        if(self::$_instance == null) {
49
            self::$_instance = new JobDescriptionCompetencyMapper($adapter);
50
        }
51
        return self::$_instance;
52
    }
53
 
54
 
55
    /**
56
     *
57
     * @param int $id
58
     * @return JobDescriptionCompetency
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 JobDescriptionCompetency();
67
        return $this->executeFetchOneObject($select, $prototype);
68
    }
69
 
70
 
71
    /**
72
     *
73
     * @param int $job_description_id
74
     * @param int $competency_id
75
     * @return JobDescriptionCompetency
76
     */
77
    public function fetchOneByJobDescriptionIdAndCompetencyId($job_description_id, $competency_id)
78
    {
79
        $select = $this->sql->select(self::_TABLE);
80
        $select->where->equalTo('job_description_id', $job_description_id);
81
        $select->where->equalTo('competency_id', $competency_id);
82
        $select->limit(1);
83
 
84
        $prototype = new JobDescriptionCompetency();
85
        return $this->executeFetchOneObject($select, $prototype);
86
    }
87
 
88
    /**
89
     *
525 geraldo 90
     * @param int $job_description_id
4113 efrain 91
     * @return JobDescriptionCompetency[]
525 geraldo 92
     */
4113 efrain 93
    public function fetchAllByJobDescriptionId($job_description_id)
525 geraldo 94
    {
95
        $select = $this->sql->select(self::_TABLE);
96
        $select->where->equalTo('job_description_id', $job_description_id);
97
 
528 geraldo 98
        $prototype = new JobDescriptionCompetency();
531 geraldo 99
        return $this->executeFetchAllObject($select, $prototype);
525 geraldo 100
    }
101
 
102
    /**
103
     *
192 efrain 104
     * @param JobDescriptionCompetency $jobDescriptionCompetency
105
     * @return boolean
106
     */
107
    public function insert($jobDescriptionCompetency)
108
    {
109
        $hydrator = new ObjectPropertyHydrator();
110
        $values = $hydrator->extract($jobDescriptionCompetency);
111
        $values = $this->removeEmpty($values);
112
 
113
        $insert = $this->sql->insert(self::_TABLE);
114
        $insert->values($values);
115
 
116
        //echo $insert->getSqlString($this->adapter->platform); exit;
117
 
118
 
119
        $result = $this->executeInsert($insert);
120
        if($result) {
121
            $jobDescriptionCompetency->id = $this->getLastInsertId();
122
        }
123
        return $result;
124
 
125
    }
126
 
127
    /**
128
     *
129
     * @param JobDescriptionCompetency $jobDescriptionCompetency
130
     * @return boolean
131
     */
132
    public function update($jobDescriptionCompetency)
133
    {
134
        $hydrator = new ObjectPropertyHydrator();
135
        $values = $hydrator->extract($jobDescriptionCompetency);
136
        $values = $this->removeEmpty($values);
137
 
138
        $update = $this->sql->update(self::_TABLE);
139
        $update->set($values);
140
        $update->where->equalTo('id', $jobDescriptionCompetency->id);
141
 
142
        return $this->executeUpdate($update);
143
    }
144
 
145
    /**
146
     *
147
     * @param JobDescriptionCompetency $jobDescriptionCompetency
148
     * @return boolean
149
     */
150
    public function delete($jobDescriptionCompetency)
151
    {
152
        $delete = $this->sql->delete(self::_TABLE);
153
        $delete->where->equalTo('id', $jobDescriptionCompetency->id);
154
 
155
        return $this->executeDelete($delete);
156
 
157
    }
158
 
159
    /**
160
     *
161
     * @param int $job_description_id
162
     * @return boolean
163
     */
164
    public function deleteAllBJobDescriptionId($job_description_id)
165
    {
166
        $delete = $this->sql->delete(self::_TABLE);
167
        $delete->where->equalTo('job_description_id', $job_description_id);
168
 
169
        return $this->executeDelete($delete);
170
 
171
    }
172
 
173
 
174
 
175
 
176
}