Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 543 | Rev 1246 | 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
     *
64
     * @return JobDescription[]
65
     */
540 geraldo 66
    public function fetchAllByDefault() {
539 geraldo 67
        $select = $this->sql->select(self::_TABLE);
68
        $select->where->isNull('company_id');
69
        $prototype = new JobDescription();
70
        return $this->executeFetchAllObject($select, $prototype);
71
    }
540 geraldo 72
 
192 efrain 73
    /**
74
     *
75
     * @param string $uuid
76
     * @return JobDescription
77
     */
540 geraldo 78
    public function fetchOneByUuid($uuid) {
192 efrain 79
        $select = $this->sql->select(self::_TABLE);
80
        $select->where->equalTo('uuid', $uuid);
81
        $select->limit(1);
540 geraldo 82
 
192 efrain 83
        $prototype = new JobDescription();
84
        return $this->executeFetchOneObject($select, $prototype);
85
    }
540 geraldo 86
 
192 efrain 87
    /**
88
     *
89
     * @param int $company_id
90
     * @return JobDescription
91
     */
540 geraldo 92
    public function fetchAllByCompanyId($company_id) {
192 efrain 93
        $select = $this->sql->select(self::_TABLE);
94
        $select->where->equalTo('company_id', $company_id);
95
        $select->order('name');
540 geraldo 96
 
192 efrain 97
        $prototype = new JobDescription();
98
        return $this->executeFetchAllObject($select, $prototype);
99
    }
540 geraldo 100
 
192 efrain 101
    /**
102
     *
103
     * @param int $company_id
104
     * @return JobDescription
105
     */
540 geraldo 106
    public function fetchAllActiveByCompanyId($company_id) {
192 efrain 107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('company_id', $company_id);
109
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
110
        $select->order('name');
540 geraldo 111
 
192 efrain 112
        $prototype = new JobDescription();
113
        return $this->executeFetchAllObject($select, $prototype);
114
    }
538 geraldo 115
 
116
    /**
117
     *
118
     * @param int $company_id
119
     * @param int $job_description_id_default
120
     * @return JobDescription
121
     */
540 geraldo 122
    public function fetchOneByCompanyId($company_id, $job_description_id_default) {
538 geraldo 123
        $select = $this->sql->select(self::_TABLE);
124
        $select->where->equalTo('company_id', $company_id);
125
        $select->where->equalTo('job_description_id_default', $job_description_id_default);
126
        $select->limit(1);
540 geraldo 127
 
538 geraldo 128
        $prototype = new JobDescription();
129
        return $this->executeFetchOneObject($select, $prototype);
130
    }
540 geraldo 131
 
192 efrain 132
    /**
133
     *
134
     * @param int $company_id
135
     * @param int $id
136
     * @return JobDescription
137
     */
540 geraldo 138
    public function fetchAllByCompanyIdWhereIdNotEqual($company_id, $id) {
192 efrain 139
        $select = $this->sql->select(self::_TABLE);
140
        $select->where->equalTo('company_id', $company_id);
141
        $select->where->notEqualTo('id', $id);
142
        $select->order('name');
540 geraldo 143
 
192 efrain 144
        $prototype = new JobDescription();
145
        return $this->executeFetchAllObject($select, $prototype);
146
    }
540 geraldo 147
 
192 efrain 148
    /**
149
     *
150
     * @param int $company_id
151
     * @param int $id
152
     * @return JobDescription
153
     */
540 geraldo 154
    public function fetchAllActiveByCompanyIdWhereIdNotEqual($company_id, $id) {
192 efrain 155
        $select = $this->sql->select(self::_TABLE);
156
        $select->where->equalTo('company_id', $company_id);
157
        $select->where->notEqualTo('id', $id);
158
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
159
        $select->order('name');
540 geraldo 160
 
192 efrain 161
        $prototype = new JobDescription();
162
        return $this->executeFetchAllObject($select, $prototype);
163
    }
164
 
540 geraldo 165
    /**
537 geraldo 166
     *
167
     * @param string $search
168
     * @param int $page
169
     * @param int $records_per_page
170
     * @param string $order_field
171
     * @param string $order_direction
172
     * @return Paginator
173
     */
540 geraldo 174
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
537 geraldo 175
        $prototype = new JobDescription();
176
        $select = $this->sql->select(self::_TABLE);
177
        $select->where->isNull('company_id');
540 geraldo 178
 
179
        if ($search) {
537 geraldo 180
            $select->where->like('name', '%' . $search . '%');
181
        }
182
        $select->order($order_field . ' ' . $order_direction);
540 geraldo 183
 
184
        $hydrator = new ObjectPropertyHydrator();
185
        $resultset = new HydratingResultSet($hydrator, $prototype);
186
 
537 geraldo 187
        $adapter = new DbSelect($select, $this->sql, $resultset);
188
        $paginator = new Paginator($adapter);
189
        $paginator->setItemCountPerPage($records_per_page);
190
        $paginator->setCurrentPageNumber($page);
540 geraldo 191
 
192
 
537 geraldo 193
        return $paginator;
194
    }
195
 
192 efrain 196
    /**
197
     *
198
     * @param int $companyId
199
     * @param string $search
200
     * @param int $page
201
     * @param int $records_per_page
202
     * @param string $order_field
203
     * @param string $order_direction
204
     * @return Paginator
205
     */
540 geraldo 206
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field = 'name', $order_direction = 'ASC') {
192 efrain 207
        $prototype = new JobDescription();
208
        $select = $this->sql->select(self::_TABLE);
209
        $select->where->equalTo('company_id', $companyId);
540 geraldo 210
 
211
        if ($search) {
192 efrain 212
            $select->where->like('name', '%' . $search . '%');
213
        }
214
        $select->order($order_field . ' ' . $order_direction);
540 geraldo 215
 
192 efrain 216
        //echo $select->getSqlString($this->adapter->platform); exit;
540 geraldo 217
 
218
        $hydrator = new ObjectPropertyHydrator();
219
        $resultset = new HydratingResultSet($hydrator, $prototype);
220
 
192 efrain 221
        $adapter = new DbSelect($select, $this->sql, $resultset);
222
        $paginator = new Paginator($adapter);
223
        $paginator->setItemCountPerPage($records_per_page);
224
        $paginator->setCurrentPageNumber($page);
540 geraldo 225
 
226
 
192 efrain 227
        return $paginator;
228
    }
540 geraldo 229
 
192 efrain 230
    /**
231
     *
232
     * @param JobDescription $jobDescription
233
     * @return boolean
234
     */
540 geraldo 235
    public function insert($jobDescription) {
192 efrain 236
        $hydrator = new ObjectPropertyHydrator();
237
        $values = $hydrator->extract($jobDescription);
238
        $values = $this->removeEmpty($values);
239
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
540 geraldo 240
 
241
 
192 efrain 242
        $insert = $this->sql->insert(self::_TABLE);
243
        $insert->values($values);
540 geraldo 244
 
192 efrain 245
        //echo $insert->getSqlString($this->adapter->platform); exit;
540 geraldo 246
 
247
 
192 efrain 248
        $result = $this->executeInsert($insert);
540 geraldo 249
        if ($result) {
192 efrain 250
            $jobDescription->id = $this->getLastInsertId();
251
        }
252
        return $result;
253
    }
540 geraldo 254
 
192 efrain 255
    /**
256
     *
257
     * @param JobDescription $jobDescription
258
     * @return boolean
259
     */
540 geraldo 260
    public function update($jobDescription) {
192 efrain 261
        $hydrator = new ObjectPropertyHydrator();
262
        $values = $hydrator->extract($jobDescription);
263
        $values = $this->removeEmpty($values);
264
        $values['job_description_id_boss'] = !empty($values['job_description_id_boss']) ? $values['job_description_id_boss'] : null;
540 geraldo 265
 
192 efrain 266
        $update = $this->sql->update(self::_TABLE);
267
        $update->set($values);
268
        $update->where->equalTo('id', $jobDescription->id);
540 geraldo 269
 
192 efrain 270
        return $this->executeUpdate($update);
271
    }
540 geraldo 272
 
192 efrain 273
    /**
274
     *
275
     * @param JobDescription $jobDescription
276
     * @return boolean
277
     */
540 geraldo 278
    public function delete($jobDescription) {
192 efrain 279
        $delete = $this->sql->delete(self::_TABLE);
280
        $delete->where->equalTo('id', $jobDescription->id);
540 geraldo 281
 
192 efrain 282
        return $this->executeDelete($delete);
283
    }
284
 
550 geraldo 285
    /**
286
     *
287
     * @return JobDescription[]
288
     */
289
    public function fetchAllActivesByCompanyId($company_id) {
290
        $prototype = new JobDescription();
291
        $select = $this->sql->select(self::_TABLE);
292
        $select->where->equalTo('company_id', $company_id);
293
        $select->where->equalTo('status', JobDescription::STATUS_ACTIVE);
294
        $select->order('name ASC');
295
 
296
        return $this->executeFetchAllObject($select, $prototype);
297
    }
298
 
540 geraldo 299
}