Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 526 | Rev 528 | 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\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
91
     * @return JobDescriptionCompetency
92
     */
526 geraldo 93
    public function fetchByJobDescription($job_description_id)
525 geraldo 94
    {
95
        $select = $this->sql->select(self::_TABLE);
96
        $select->where->equalTo('job_description_id', $job_description_id);
97
 
527 geraldo 98
        $hydrator   = new ObjectPropertyHydrator();
99
        $resultset  = new HydratingResultSet($hydrator, $prototype);
100
 
101
        $adapter = new DbSelect($select, $this->sql, $resultset);
102
        $paginator = new Paginator($adapter);
103
        $paginator->setItemCountPerPage($records_per_page);
104
        $paginator->setCurrentPageNumber($page);
105
 
106
 
107
        return $paginator;
525 geraldo 108
    }
109
 
110
    /**
111
     *
192 efrain 112
     * @param JobDescriptionCompetency $jobDescriptionCompetency
113
     * @return boolean
114
     */
115
    public function insert($jobDescriptionCompetency)
116
    {
117
        $hydrator = new ObjectPropertyHydrator();
118
        $values = $hydrator->extract($jobDescriptionCompetency);
119
        $values = $this->removeEmpty($values);
120
 
121
        $insert = $this->sql->insert(self::_TABLE);
122
        $insert->values($values);
123
 
124
        //echo $insert->getSqlString($this->adapter->platform); exit;
125
 
126
 
127
        $result = $this->executeInsert($insert);
128
        if($result) {
129
            $jobDescriptionCompetency->id = $this->getLastInsertId();
130
        }
131
        return $result;
132
 
133
    }
134
 
135
    /**
136
     *
137
     * @param JobDescriptionCompetency $jobDescriptionCompetency
138
     * @return boolean
139
     */
140
    public function update($jobDescriptionCompetency)
141
    {
142
        $hydrator = new ObjectPropertyHydrator();
143
        $values = $hydrator->extract($jobDescriptionCompetency);
144
        $values = $this->removeEmpty($values);
145
 
146
        $update = $this->sql->update(self::_TABLE);
147
        $update->set($values);
148
        $update->where->equalTo('id', $jobDescriptionCompetency->id);
149
 
150
        return $this->executeUpdate($update);
151
    }
152
 
153
    /**
154
     *
155
     * @param JobDescriptionCompetency $jobDescriptionCompetency
156
     * @return boolean
157
     */
158
    public function delete($jobDescriptionCompetency)
159
    {
160
        $delete = $this->sql->delete(self::_TABLE);
161
        $delete->where->equalTo('id', $jobDescriptionCompetency->id);
162
 
163
        return $this->executeDelete($delete);
164
 
165
    }
166
 
167
    /**
168
     *
169
     * @param int $job_description_id
170
     * @return boolean
171
     */
172
    public function deleteAllBJobDescriptionId($job_description_id)
173
    {
174
        $delete = $this->sql->delete(self::_TABLE);
175
        $delete->where->equalTo('job_description_id', $job_description_id);
176
 
177
        return $this->executeDelete($delete);
178
 
179
    }
180
 
181
 
182
 
183
 
184
}