Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 537 | 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\JobDescription;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
use Laminas\Hydrator\ArraySerializableHydrator;
18
 
19
 
20
 
21
class JobDescriptionMapper extends MapperCommon
22
{
23
    const _TABLE = 'tbl_jobs_description';
24
 
25
 
26
    /**
27
     *
28
     * @var JobDescriptionMapper
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 JobDescriptionMapper
45
     */
46
    public static function getInstance($adapter)
47
    {
48
        if(self::$_instance == null) {
49
            self::$_instance = new JobDescriptionMapper($adapter);
50
        }
51
        return self::$_instance;
52
    }
53
 
54
 
55
    /**
56
     *
57
     * @param int $id
58
     * @return JobDescription
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 JobDescription();
67
        return $this->executeFetchOneObject($select, $prototype);
68
    }
69
 
70
    /**
71
     *
72
     * @param string $uuid
73
     * @return JobDescription
74
     */
75
    public function fetchOneByUuid($uuid)
76
    {
77
        $select = $this->sql->select(self::_TABLE);
78
        $select->where->equalTo('uuid', $uuid);
79
        $select->limit(1);
80
 
81
        $prototype = new JobDescription();
82
        return $this->executeFetchOneObject($select, $prototype);
83
    }
84
 
85
 
86
    /**
87
     *
88
     * @param int $company_id
89
     * @return JobDescription
90
     */
91
    public function fetchAllByCompanyId($company_id)
92
    {
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('company_id', $company_id);
95
        $select->order('name');
96
 
97
        $prototype = new JobDescription();
98
        return $this->executeFetchAllObject($select, $prototype);
99
    }
100
 
101
 
102
    /**
103
     *
104
     * @param int $company_id
105
     * @return JobDescription
106
     */
107
    public function fetchAllActiveByCompanyId($company_id)
108
    {
109
        $select = $this->sql->select(self::_TABLE);
110
        $select->where->equalTo('company_id', $company_id);
111
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
112
        $select->order('name');
113
 
114
        $prototype = new JobDescription();
115
        return $this->executeFetchAllObject($select, $prototype);
116
    }
117
 
118
 
119
    /**
120
     *
121
     * @param int $company_id
122
     * @param int $id
123
     * @return JobDescription
124
     */
125
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id)
126
    {
127
        $select = $this->sql->select(self::_TABLE);
128
        $select->where->equalTo('company_id', $company_id);
129
        $select->where->notEqualTo('id', $id);
130
        $select->order('name');
131
 
132
        $prototype = new JobDescription();
133
        return $this->executeFetchAllObject($select, $prototype);
134
    }
135
 
136
 
137
    /**
138
     *
139
     * @param int $company_id
140
     * @param int $id
141
     * @return JobDescription
142
     */
143
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id)
144
    {
145
        $select = $this->sql->select(self::_TABLE);
146
        $select->where->equalTo('company_id', $company_id);
147
        $select->where->notEqualTo('id', $id);
148
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
149
        $select->order('name');
150
 
151
        $prototype = new JobDescription();
152
        return $this->executeFetchAllObject($select, $prototype);
153
    }
154
 
155
 
156
    /**
157
     *
158
     * @param int $companyId
159
     * @param string $search
160
     * @param int $page
161
     * @param int $records_per_page
162
     * @param string $order_field
163
     * @param string $order_direction
164
     * @return Paginator
165
     */
166
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
167
    {
168
        $prototype = new JobDescription();
169
        $select = $this->sql->select(self::_TABLE);
170
        $select->where->equalTo('company_id', $companyId);
171
 
172
        if($search) {
173
            $select->where->like('name', '%' . $search . '%');
174
        }
175
        $select->order($order_field . ' ' . $order_direction);
176
 
177
        //echo $select->getSqlString($this->adapter->platform); exit;
178
 
179
        $hydrator   = new ObjectPropertyHydrator();
180
        $resultset  = new HydratingResultSet($hydrator, $prototype);
181
 
182
        $adapter = new DbSelect($select, $this->sql, $resultset);
183
        $paginator = new Paginator($adapter);
184
        $paginator->setItemCountPerPage($records_per_page);
185
        $paginator->setCurrentPageNumber($page);
186
 
187
 
188
        return $paginator;
189
    }
190
 
191
 
192
    /**
193
     *
194
     * @param JobDescription $jobDescription
195
     * @return boolean
196
     */
197
    public function insert($jobDescription)
198
    {
199
        $hydrator = new ObjectPropertyHydrator();
200
        $values = $hydrator->extract($jobDescription);
201
        $values = $this->removeEmpty($values);
202
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
203
 
204
 
205
        $insert = $this->sql->insert(self::_TABLE);
206
        $insert->values($values);
207
 
208
        //echo $insert->getSqlString($this->adapter->platform); exit;
209
 
210
 
211
        $result = $this->executeInsert($insert);
212
        if($result) {
213
            $jobDescription->id = $this->getLastInsertId();
214
        }
215
        return $result;
216
 
217
    }
218
 
219
    /**
220
     *
221
     * @param JobDescription $jobDescription
222
     * @return boolean
223
     */
224
    public function update($jobDescription)
225
    {
226
        $hydrator = new ObjectPropertyHydrator();
227
        $values = $hydrator->extract($jobDescription);
228
        $values = $this->removeEmpty($values);
229
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
230
 
231
        $update = $this->sql->update(self::_TABLE);
232
        $update->set($values);
233
        $update->where->equalTo('id', $jobDescription->id);
234
 
235
        return $this->executeUpdate($update);
236
    }
237
 
238
    /**
239
     *
240
     * @param JobDescription $jobDescription
241
     * @return boolean
242
     */
243
    public function delete($jobDescription)
244
    {
245
        $delete = $this->sql->delete(self::_TABLE);
246
        $delete->where->equalTo('id', $jobDescription->id);
247
 
248
        return $this->executeDelete($delete);
249
 
250
    }
251
 
252
 
253
 
254
 
255
 
256
}