Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 550 | Rev 3454 | 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
use LeadersLinked\Model\JobDescription;
15
use LeadersLinked\Mapper\Common\MapperCommon;
16
use Laminas\Hydrator\ArraySerializableHydrator;
17
 
540 geraldo 18
class JobDescriptionMapper extends MapperCommon {
192 efrain 19
 
20
    const _TABLE = 'tbl_jobs_description';
21
 
22
    /**
23
     *
24
     * @var JobDescriptionMapper
25
     */
26
    private static $_instance;
540 geraldo 27
 
192 efrain 28
    /**
29
     *
30
     * @param AdapterInterface $adapter
31
     */
540 geraldo 32
    private function __construct($adapter) {
192 efrain 33
        parent::__construct($adapter);
34
    }
540 geraldo 35
 
192 efrain 36
    /**
37
     *
38
     * @param AdapterInterface $adapter
39
     * @return JobDescriptionMapper
40
     */
540 geraldo 41
    public static function getInstance($adapter) {
42
        if (self::$_instance == null) {
192 efrain 43
            self::$_instance = new JobDescriptionMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return JobDescription
52
     */
540 geraldo 53
    public function fetchOne($id) {
192 efrain 54
        $select = $this->sql->select(self::_TABLE);
55
        $select->where->equalTo('id', $id);
56
        $select->limit(1);
540 geraldo 57
 
192 efrain 58
        $prototype = new JobDescription();
59
        return $this->executeFetchOneObject($select, $prototype);
60
    }
539 geraldo 61
 
62
    /**
63
     *
1246 eleazar 64
     * @param int $id
65
     * @return JobDescription
66
     */
67
    public function fetchAll($id) {
68
        $select = $this->sql->select(self::_TABLE);
69
        $select->where->equalTo('id', $id);
70
        $select->limit(1);
71
 
72
        $prototype = new JobDescription();
73
        return $this->executeFetchAllObject($select, $prototype);
74
    }
75
 
76
    /**
77
     *
539 geraldo 78
     * @return JobDescription[]
79
     */
540 geraldo 80
    public function fetchAllByDefault() {
539 geraldo 81
        $select = $this->sql->select(self::_TABLE);
82
        $select->where->isNull('company_id');
83
        $prototype = new JobDescription();
84
        return $this->executeFetchAllObject($select, $prototype);
85
    }
540 geraldo 86
 
192 efrain 87
    /**
88
     *
89
     * @param string $uuid
90
     * @return JobDescription
91
     */
540 geraldo 92
    public function fetchOneByUuid($uuid) {
192 efrain 93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('uuid', $uuid);
95
        $select->limit(1);
540 geraldo 96
 
192 efrain 97
        $prototype = new JobDescription();
98
        return $this->executeFetchOneObject($select, $prototype);
99
    }
540 geraldo 100
 
192 efrain 101
    /**
102
     *
103
     * @param int $company_id
104
     * @return JobDescription
105
     */
540 geraldo 106
    public function fetchAllByCompanyId($company_id) {
192 efrain 107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('company_id', $company_id);
109
        $select->order('name');
540 geraldo 110
 
192 efrain 111
        $prototype = new JobDescription();
112
        return $this->executeFetchAllObject($select, $prototype);
113
    }
540 geraldo 114
 
192 efrain 115
    /**
116
     *
117
     * @param int $company_id
118
     * @return JobDescription
119
     */
540 geraldo 120
    public function fetchAllActiveByCompanyId($company_id) {
192 efrain 121
        $select = $this->sql->select(self::_TABLE);
122
        $select->where->equalTo('company_id', $company_id);
123
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
124
        $select->order('name');
540 geraldo 125
 
192 efrain 126
        $prototype = new JobDescription();
127
        return $this->executeFetchAllObject($select, $prototype);
128
    }
538 geraldo 129
 
130
    /**
131
     *
132
     * @param int $company_id
133
     * @param int $job_description_id_default
134
     * @return JobDescription
135
     */
540 geraldo 136
    public function fetchOneByCompanyId($company_id, $job_description_id_default) {
538 geraldo 137
        $select = $this->sql->select(self::_TABLE);
138
        $select->where->equalTo('company_id', $company_id);
139
        $select->where->equalTo('job_description_id_default', $job_description_id_default);
140
        $select->limit(1);
540 geraldo 141
 
538 geraldo 142
        $prototype = new JobDescription();
143
        return $this->executeFetchOneObject($select, $prototype);
144
    }
540 geraldo 145
 
192 efrain 146
    /**
147
     *
148
     * @param int $company_id
149
     * @param int $id
150
     * @return JobDescription
151
     */
540 geraldo 152
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id) {
192 efrain 153
        $select = $this->sql->select(self::_TABLE);
154
        $select->where->equalTo('company_id', $company_id);
155
        $select->where->notEqualTo('id', $id);
156
        $select->order('name');
540 geraldo 157
 
192 efrain 158
        $prototype = new JobDescription();
159
        return $this->executeFetchAllObject($select, $prototype);
160
    }
540 geraldo 161
 
192 efrain 162
    /**
163
     *
164
     * @param int $company_id
165
     * @param int $id
166
     * @return JobDescription
167
     */
540 geraldo 168
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id) {
192 efrain 169
        $select = $this->sql->select(self::_TABLE);
170
        $select->where->equalTo('company_id', $company_id);
171
        $select->where->notEqualTo('id', $id);
172
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
173
        $select->order('name');
540 geraldo 174
 
192 efrain 175
        $prototype = new JobDescription();
176
        return $this->executeFetchAllObject($select, $prototype);
177
    }
178
 
540 geraldo 179
    /**
537 geraldo 180
     *
181
     * @param string $search
182
     * @param int $page
183
     * @param int $records_per_page
184
     * @param string $order_field
185
     * @param string $order_direction
186
     * @return Paginator
187
     */
540 geraldo 188
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
537 geraldo 189
        $prototype = new JobDescription();
190
        $select = $this->sql->select(self::_TABLE);
191
        $select->where->isNull('company_id');
540 geraldo 192
 
193
        if ($search) {
537 geraldo 194
            $select->where->like('name', '%' . $search . '%');
195
        }
196
        $select->order($order_field . ' ' . $order_direction);
540 geraldo 197
 
198
        $hydrator = new ObjectPropertyHydrator();
199
        $resultset = new HydratingResultSet($hydrator, $prototype);
200
 
537 geraldo 201
        $adapter = new DbSelect($select, $this->sql, $resultset);
202
        $paginator = new Paginator($adapter);
203
        $paginator->setItemCountPerPage($records_per_page);
204
        $paginator->setCurrentPageNumber($page);
540 geraldo 205
 
206
 
537 geraldo 207
        return $paginator;
208
    }
209
 
192 efrain 210
    /**
211
     *
212
     * @param int $companyId
213
     * @param string $search
214
     * @param int $page
215
     * @param int $records_per_page
216
     * @param string $order_field
217
     * @param string $order_direction
218
     * @return Paginator
219
     */
540 geraldo 220
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
192 efrain 221
        $prototype = new JobDescription();
222
        $select = $this->sql->select(self::_TABLE);
223
        $select->where->equalTo('company_id', $companyId);
540 geraldo 224
 
225
        if ($search) {
192 efrain 226
            $select->where->like('name', '%' . $search . '%');
227
        }
228
        $select->order($order_field . ' ' . $order_direction);
540 geraldo 229
 
192 efrain 230
        //echo $select->getSqlString($this->adapter->platform); exit;
540 geraldo 231
 
232
        $hydrator = new ObjectPropertyHydrator();
233
        $resultset = new HydratingResultSet($hydrator, $prototype);
234
 
192 efrain 235
        $adapter = new DbSelect($select, $this->sql, $resultset);
236
        $paginator = new Paginator($adapter);
237
        $paginator->setItemCountPerPage($records_per_page);
238
        $paginator->setCurrentPageNumber($page);
540 geraldo 239
 
240
 
192 efrain 241
        return $paginator;
242
    }
540 geraldo 243
 
192 efrain 244
    /**
245
     *
246
     * @param JobDescription $jobDescription
247
     * @return boolean
248
     */
540 geraldo 249
    public function insert($jobDescription) {
192 efrain 250
        $hydrator = new ObjectPropertyHydrator();
251
        $values = $hydrator->extract($jobDescription);
252
        $values = $this->removeEmpty($values);
253
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
540 geraldo 254
 
255
 
192 efrain 256
        $insert = $this->sql->insert(self::_TABLE);
257
        $insert->values($values);
540 geraldo 258
 
192 efrain 259
        //echo $insert->getSqlString($this->adapter->platform); exit;
540 geraldo 260
 
261
 
192 efrain 262
        $result = $this->executeInsert($insert);
540 geraldo 263
        if ($result) {
192 efrain 264
            $jobDescription->id = $this->getLastInsertId();
265
        }
266
        return $result;
267
    }
540 geraldo 268
 
192 efrain 269
    /**
270
     *
271
     * @param JobDescription $jobDescription
272
     * @return boolean
273
     */
540 geraldo 274
    public function update($jobDescription) {
192 efrain 275
        $hydrator = new ObjectPropertyHydrator();
276
        $values = $hydrator->extract($jobDescription);
277
        $values = $this->removeEmpty($values);
278
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
540 geraldo 279
 
192 efrain 280
        $update = $this->sql->update(self::_TABLE);
281
        $update->set($values);
282
        $update->where->equalTo('id', $jobDescription->id);
540 geraldo 283
 
192 efrain 284
        return $this->executeUpdate($update);
285
    }
540 geraldo 286
 
192 efrain 287
    /**
288
     *
289
     * @param JobDescription $jobDescription
290
     * @return boolean
291
     */
540 geraldo 292
    public function delete($jobDescription) {
192 efrain 293
        $delete = $this->sql->delete(self::_TABLE);
294
        $delete->where->equalTo('id', $jobDescription->id);
540 geraldo 295
 
192 efrain 296
        return $this->executeDelete($delete);
297
    }
298
 
550 geraldo 299
    /**
300
     *
301
     * @return JobDescription[]
302
     */
303
    public function fetchAllActivesByCompanyId($company_id) {
304
        $prototype = new JobDescription();
305
        $select = $this->sql->select(self::_TABLE);
306
        $select->where->equalTo('company_id', $company_id);
307
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
308
        $select->order('name ASC');
309
 
310
        return $this->executeFetchAllObject($select, $prototype);
311
    }
312
 
540 geraldo 313
}