Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 192 | Rev 538 | 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\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
 
537 geraldo 155
     /**
156
     *
157
     * @param string $search
158
     * @param int $page
159
     * @param int $records_per_page
160
     * @param string $order_field
161
     * @param string $order_direction
162
     * @return Paginator
163
     */
164
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
165
    {
166
        $prototype = new JobDescription();
167
        $select = $this->sql->select(self::_TABLE);
168
        $select->where->isNull('company_id');
169
 
170
        if($search) {
171
            $select->where->like('name', '%' . $search . '%');
172
        }
173
        $select->order($order_field . ' ' . $order_direction);
174
 
175
        $hydrator   = new ObjectPropertyHydrator();
176
        $resultset  = new HydratingResultSet($hydrator, $prototype);
177
 
178
        $adapter = new DbSelect($select, $this->sql, $resultset);
179
        $paginator = new Paginator($adapter);
180
        $paginator->setItemCountPerPage($records_per_page);
181
        $paginator->setCurrentPageNumber($page);
182
 
183
 
184
        return $paginator;
185
    }
186
 
192 efrain 187
 
188
    /**
189
     *
190
     * @param int $companyId
191
     * @param string $search
192
     * @param int $page
193
     * @param int $records_per_page
194
     * @param string $order_field
195
     * @param string $order_direction
196
     * @return Paginator
197
     */
198
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
199
    {
200
        $prototype = new JobDescription();
201
        $select = $this->sql->select(self::_TABLE);
202
        $select->where->equalTo('company_id', $companyId);
203
 
204
        if($search) {
205
            $select->where->like('name', '%' . $search . '%');
206
        }
207
        $select->order($order_field . ' ' . $order_direction);
208
 
209
        //echo $select->getSqlString($this->adapter->platform); exit;
210
 
211
        $hydrator   = new ObjectPropertyHydrator();
212
        $resultset  = new HydratingResultSet($hydrator, $prototype);
213
 
214
        $adapter = new DbSelect($select, $this->sql, $resultset);
215
        $paginator = new Paginator($adapter);
216
        $paginator->setItemCountPerPage($records_per_page);
217
        $paginator->setCurrentPageNumber($page);
218
 
219
 
220
        return $paginator;
221
    }
222
 
223
 
224
    /**
225
     *
226
     * @param JobDescription $jobDescription
227
     * @return boolean
228
     */
229
    public function insert($jobDescription)
230
    {
231
        $hydrator = new ObjectPropertyHydrator();
232
        $values = $hydrator->extract($jobDescription);
233
        $values = $this->removeEmpty($values);
234
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
235
 
236
 
237
        $insert = $this->sql->insert(self::_TABLE);
238
        $insert->values($values);
239
 
240
        //echo $insert->getSqlString($this->adapter->platform); exit;
241
 
242
 
243
        $result = $this->executeInsert($insert);
244
        if($result) {
245
            $jobDescription->id = $this->getLastInsertId();
246
        }
247
        return $result;
248
 
249
    }
250
 
251
    /**
252
     *
253
     * @param JobDescription $jobDescription
254
     * @return boolean
255
     */
256
    public function update($jobDescription)
257
    {
258
        $hydrator = new ObjectPropertyHydrator();
259
        $values = $hydrator->extract($jobDescription);
260
        $values = $this->removeEmpty($values);
261
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
262
 
263
        $update = $this->sql->update(self::_TABLE);
264
        $update->set($values);
265
        $update->where->equalTo('id', $jobDescription->id);
266
 
267
        return $this->executeUpdate($update);
268
    }
269
 
270
    /**
271
     *
272
     * @param JobDescription $jobDescription
273
     * @return boolean
274
     */
275
    public function delete($jobDescription)
276
    {
277
        $delete = $this->sql->delete(self::_TABLE);
278
        $delete->where->equalTo('id', $jobDescription->id);
279
 
280
        return $this->executeDelete($delete);
281
 
282
    }
283
 
284
 
285
 
286
 
287
 
288
}