Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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