Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 525 | Ir a la última revisión | | 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
     *
90
     * @param JobDescriptionCompetency $jobDescriptionCompetency
91
     * @return boolean
92
     */
93
    public function insert($jobDescriptionCompetency)
94
    {
95
        $hydrator = new ObjectPropertyHydrator();
96
        $values = $hydrator->extract($jobDescriptionCompetency);
97
        $values = $this->removeEmpty($values);
98
 
99
        $insert = $this->sql->insert(self::_TABLE);
100
        $insert->values($values);
101
 
102
        //echo $insert->getSqlString($this->adapter->platform); exit;
103
 
104
 
105
        $result = $this->executeInsert($insert);
106
        if($result) {
107
            $jobDescriptionCompetency->id = $this->getLastInsertId();
108
        }
109
        return $result;
110
 
111
    }
112
 
113
    /**
114
     *
115
     * @param JobDescriptionCompetency $jobDescriptionCompetency
116
     * @return boolean
117
     */
118
    public function update($jobDescriptionCompetency)
119
    {
120
        $hydrator = new ObjectPropertyHydrator();
121
        $values = $hydrator->extract($jobDescriptionCompetency);
122
        $values = $this->removeEmpty($values);
123
 
124
        $update = $this->sql->update(self::_TABLE);
125
        $update->set($values);
126
        $update->where->equalTo('id', $jobDescriptionCompetency->id);
127
 
128
        return $this->executeUpdate($update);
129
    }
130
 
131
    /**
132
     *
133
     * @param JobDescriptionCompetency $jobDescriptionCompetency
134
     * @return boolean
135
     */
136
    public function delete($jobDescriptionCompetency)
137
    {
138
        $delete = $this->sql->delete(self::_TABLE);
139
        $delete->where->equalTo('id', $jobDescriptionCompetency->id);
140
 
141
        return $this->executeDelete($delete);
142
 
143
    }
144
 
145
    /**
146
     *
147
     * @param int $job_description_id
148
     * @return boolean
149
     */
150
    public function deleteAllBJobDescriptionId($job_description_id)
151
    {
152
        $delete = $this->sql->delete(self::_TABLE);
153
        $delete->where->equalTo('job_description_id', $job_description_id);
154
 
155
        return $this->executeDelete($delete);
156
 
157
    }
158
 
159
 
160
 
161
 
162
}