Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 169 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 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\Paginator\Adapter\DbSelect;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\Hydrator\ArraySerializableHydrator;
13
 
14
 
15
use LeadersLinked\Model\Job;
16
use LeadersLinked\Mapper\Common\MapperCommon;
17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
18
 
19
class JobMapper extends MapperCommon
20
{
21
    const _TABLE = 'tbl_jobs';
22
 
23
 
24
    /**
25
     *
26
     * @var JobMapper
27
     */
28
    private static $_instance;
29
 
30
    /**
31
     *
32
     * @param AdapterInterface $adapter
33
     */
34
    private function __construct($adapter)
35
    {
36
        parent::__construct($adapter);
37
    }
38
 
39
    /**
40
     *
41
     * @param AdapterInterface $adapter
42
     * @return JobMapper
43
     */
44
    public static function getInstance($adapter)
45
    {
46
        if(self::$_instance == null) {
47
            self::$_instance = new JobMapper($adapter);
48
        }
49
        return self::$_instance;
50
    }
51
 
52
 
53
    /**
54
     *
55
     * @param int $id
56
     * @return Job
57
     */
58
    public function fetchOne($id)
59
    {
60
        $select = $this->sql->select(self::_TABLE);
61
        $select->where->equalTo('id', $id);
62
 
63
        $prototype = new Job();
64
        return $this->executeFetchOneObject($select, $prototype);
65
    }
66
 
67
    /**
68
     *
69
     * @param int $uuid
70
     * @return Job
71
     */
72
    public function fetchOneByUuid($uuid)
73
    {
74
        $select = $this->sql->select(self::_TABLE);
75
        $select->where->equalTo('uuid', $uuid);
76
 
77
        $prototype = new Job();
78
        return $this->executeFetchOneObject($select, $prototype);
79
    }
80
 
81
    /**
82
     *
3639 efrain 83
     * @param int $uuid
84
     * @param int $network_id
85
     * @return Job
86
     */
87
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
88
    {
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('uuid', $uuid);
91
        $select->where->equalTo('network_id', $network_id);
92
 
93
        $prototype = new Job();
94
        return $this->executeFetchOneObject($select, $prototype);
95
    }
96
 
97
    /**
98
     *
1 www 99
     * @param Job $job
100
     * @return boolean
101
     */
102
    public function insert($job)
103
    {
104
 
105
        $hydrator = new ObjectPropertyHydrator();
106
        $values = $hydrator->extract($job);
107
        $values = array_filter($values, function($value) {
108
            return !empty($value);
109
        });
110
 
111
        $insert = $this->sql->insert(self::_TABLE);
112
        $insert->values($values);
113
 
114
        // echo $insert->getSqlString($this->adapter->platform); exit;
115
 
116
        $response = $this->executeInsert($insert);
117
        if($response) {
118
            $job->id = $this->lastInsertId;
119
        }
120
 
121
        return $response;
122
 
123
    }
124
 
125
    /**
126
     *
127
     * @param Job $job
128
     * @return boolean
129
     */
130
    public function updateJobCategory($job)
131
    {
132
        $values = [
133
            'job_category_id' => $job->job_category_id
134
        ];
135
 
136
        $update = $this->sql->update(self::_TABLE);
137
        $update->set($values);
138
 
139
 
140
        $update->where->equalTo('id', $job->id);
141
        return $this->executeUpdate($update);
142
    }
143
 
144
    /**
145
     *
146
     * @param Job $job
147
     * @return boolean
148
     */
149
    public function updateVisits($job)
150
    {
151
        $values = [
152
            'visits' => $job->visits
153
        ];
154
 
155
        $update = $this->sql->update(self::_TABLE);
156
        $update->set($values);
157
 
158
 
159
        $update->where->equalTo('id', $job->id);
160
        return $this->executeUpdate($update);
161
    }
162
 
163
 
164
    /**
165
     *
166
     * @param Job $job
167
     * @return boolean
168
     */
169
    public function updateEmploymentType($job)
170
    {
171
        $values = [
172
            'employment_type' => $job->employment_type
173
        ];
174
 
175
        $update = $this->sql->update(self::_TABLE);
176
        $update->set($values);
177
 
178
 
179
        $update->where->equalTo('id', $job->id);
180
        return $this->executeUpdate($update);
181
    }
182
 
183
    /**
184
     *
185
     * @param Job $job
186
     * @return boolean
187
     */
188
    public function updateExtended($job)
189
    {
190
        $values = [
191
            'description' => $job->description
192
        ];
193
 
194
        $update = $this->sql->update(self::_TABLE);
195
        $update->set($values);
196
 
197
 
198
        $update->where->equalTo('id', $job->id);
199
        return $this->executeUpdate($update);
200
    }
201
 
202
    /**
203
     *
204
     * @param Job $job
205
     * @return boolean
206
     */
207
    public function updateStatus($job)
208
    {
209
        $values = [
210
            'status' => $job->status
211
        ];
212
 
213
        $update = $this->sql->update(self::_TABLE);
214
        $update->set($values);
215
 
216
 
217
        $update->where->equalTo('id', $job->id);
218
        return $this->executeUpdate($update);
219
    }
220
 
221
    /**
222
     *
223
     * @param Job $job
224
     * @return boolean
225
     */
226
    public function updateTitle($job)
227
    {
228
        $values = [
229
            'title' => $job->title
230
        ];
231
 
232
        $update = $this->sql->update(self::_TABLE);
233
        $update->set($values);
234
 
235
 
236
        $update->where->equalTo('id', $job->id);
237
        return $this->executeUpdate($update);
238
    }
239
 
240
    /**
241
     *
242
     * @param Job $job
243
     * @return boolean
244
     */
245
    public function updateLastDateOfApplication($job)
246
    {
247
        $values = [
248
            'last_date_of_application' => $job->last_date_of_application
249
        ];
250
 
251
        $update = $this->sql->update(self::_TABLE);
252
        $update->set($values);
253
 
254
 
255
        $update->where->equalTo('id', $job->id);
256
        return $this->executeUpdate($update);
257
    }
258
 
259
    /**
260
     *
261
     * @param Job $job
262
     * @return boolean
263
     */
264
    public function updateHowApply($job)
265
    {
266
        $values = [
267
            'job_apply_email' => $job->apply_email,
268
            'job_apply_url' => $job->apply_url,
269
        ];
270
 
271
        $update = $this->sql->update(self::_TABLE);
272
        $update->set($values);
273
 
274
 
275
        $update->where->equalTo('id', $job->id);
276
        return $this->executeUpdate($update);
277
    }
278
 
279
    /**
280
     *
281
     * @param Job $job
282
     * @return boolean
283
     */
284
    public function updateLocation($job)
285
    {
286
        $values = [
287
            'location_id' => $job->location_id
288
        ];
289
 
290
        $update = $this->sql->update(self::_TABLE);
291
        $update->set($values);
292
 
293
 
294
        $update->where->equalTo('id', $job->id);
295
        return $this->executeUpdate($update);
296
    }
297
 
298
    /**
299
     *
300
     * @param Job $job
301
     * @return boolean
302
     */
303
    public function updateExperience($job)
304
    {
305
        $values = [
306
            'experience_visible'=> $job->experience_visible,
307
            'experience_min' => $job->experience_min,
308
            'experience_max' => $job->experience_max,
309
        ];
310
 
311
        $update = $this->sql->update(self::_TABLE);
312
        $update->set($values);
313
 
314
 
315
        $update->where->equalTo('id', $job->id);
316
        return $this->executeUpdate($update);
317
    }
318
 
319
    /**
320
     *
321
     * @param Job $job
322
     * @return boolean
323
     */
324
    public function updateSalary($job)
325
    {
326
        $values = [
327
            'salary_visible'=> $job->salary_visible,
328
            'salary_min' => $job->salary_min,
329
            'salary_max' => $job->salary_max,
330
            'salary_currency' => $job->salary_currency,
331
        ];
332
 
333
        $update = $this->sql->update(self::_TABLE);
334
        $update->set($values);
335
 
336
 
337
        $update->where->equalTo('id', $job->id);
338
        return $this->executeUpdate($update);
339
    }
340
 
341
    /**
342
     *
343
     * @param Job $job
344
     * @return boolean
345
     */
346
    public function delete($job)
347
    {
348
        $values = [
349
            'status'=> Job::STATUS_DELETED,
350
        ];
351
 
352
        $update = $this->sql->update(self::_TABLE);
353
        $update->set($values);
354
 
355
 
356
        $update->where->equalTo('id', $job->id);
357
        return $this->executeUpdate($update);
358
    }
359
 
360
    /**
361
     *
362
     * @param int $companyId
363
     * @param string $search
364
     * @param int $page
365
     * @param int $records_per_page
366
     * @param string $order_field
367
     * @param string $order_direction
368
     * @return Paginator
369
     */
370
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
371
    {
372
        $prototype = new Job();
373
        $select = $this->sql->select(self::_TABLE);
374
        $select->where->equalTo('company_id', $companyId);
375
        $select->where->in('status', [
376
            Job::STATUS_ACTIVE,
377
            Job::STATUS_INACTIVE,
378
        ]);
379
 
380
        if($search) {
169 efrain 381
            $select->where->like('title', '%' . $search . '%');
1 www 382
        }
383
        $select->order($order_field . ' ' . $order_direction);
384
 
385
        //echo $select->getSqlString($this->adapter->platform); exit;
386
 
387
        $hydrator   = new ObjectPropertyHydrator();
388
        $resultset  = new HydratingResultSet($hydrator, $prototype);
389
 
390
        $adapter = new DbSelect($select, $this->sql, $resultset);
391
        $paginator = new Paginator($adapter);
392
        $paginator->setItemCountPerPage($records_per_page);
393
        $paginator->setCurrentPageNumber($page);
394
 
395
 
396
        return $paginator;
397
    }
398
}