Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Ir a la última revisión | | 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
     *
83
     * @param Job $job
84
     * @return boolean
85
     */
86
    public function insert($job)
87
    {
88
 
89
        $hydrator = new ObjectPropertyHydrator();
90
        $values = $hydrator->extract($job);
91
        $values = array_filter($values, function($value) {
92
            return !empty($value);
93
        });
94
 
95
        $insert = $this->sql->insert(self::_TABLE);
96
        $insert->values($values);
97
 
98
        // echo $insert->getSqlString($this->adapter->platform); exit;
99
 
100
        $response = $this->executeInsert($insert);
101
        if($response) {
102
            $job->id = $this->lastInsertId;
103
        }
104
 
105
        return $response;
106
 
107
    }
108
 
109
    /**
110
     *
111
     * @param Job $job
112
     * @return boolean
113
     */
114
    public function updateJobCategory($job)
115
    {
116
        $values = [
117
            'job_category_id' => $job->job_category_id
118
        ];
119
 
120
        $update = $this->sql->update(self::_TABLE);
121
        $update->set($values);
122
 
123
 
124
        $update->where->equalTo('id', $job->id);
125
        return $this->executeUpdate($update);
126
    }
127
 
128
    /**
129
     *
130
     * @param Job $job
131
     * @return boolean
132
     */
133
    public function updateVisits($job)
134
    {
135
        $values = [
136
            'visits' => $job->visits
137
        ];
138
 
139
        $update = $this->sql->update(self::_TABLE);
140
        $update->set($values);
141
 
142
 
143
        $update->where->equalTo('id', $job->id);
144
        return $this->executeUpdate($update);
145
    }
146
 
147
 
148
    /**
149
     *
150
     * @param Job $job
151
     * @return boolean
152
     */
153
    public function updateEmploymentType($job)
154
    {
155
        $values = [
156
            'employment_type' => $job->employment_type
157
        ];
158
 
159
        $update = $this->sql->update(self::_TABLE);
160
        $update->set($values);
161
 
162
 
163
        $update->where->equalTo('id', $job->id);
164
        return $this->executeUpdate($update);
165
    }
166
 
167
    /**
168
     *
169
     * @param Job $job
170
     * @return boolean
171
     */
172
    public function updateExtended($job)
173
    {
174
        $values = [
175
            'description' => $job->description
176
        ];
177
 
178
        $update = $this->sql->update(self::_TABLE);
179
        $update->set($values);
180
 
181
 
182
        $update->where->equalTo('id', $job->id);
183
        return $this->executeUpdate($update);
184
    }
185
 
186
    /**
187
     *
188
     * @param Job $job
189
     * @return boolean
190
     */
191
    public function updateStatus($job)
192
    {
193
        $values = [
194
            'status' => $job->status
195
        ];
196
 
197
        $update = $this->sql->update(self::_TABLE);
198
        $update->set($values);
199
 
200
 
201
        $update->where->equalTo('id', $job->id);
202
        return $this->executeUpdate($update);
203
    }
204
 
205
    /**
206
     *
207
     * @param Job $job
208
     * @return boolean
209
     */
210
    public function updateTitle($job)
211
    {
212
        $values = [
213
            'title' => $job->title
214
        ];
215
 
216
        $update = $this->sql->update(self::_TABLE);
217
        $update->set($values);
218
 
219
 
220
        $update->where->equalTo('id', $job->id);
221
        return $this->executeUpdate($update);
222
    }
223
 
224
    /**
225
     *
226
     * @param Job $job
227
     * @return boolean
228
     */
229
    public function updateLastDateOfApplication($job)
230
    {
231
        $values = [
232
            'last_date_of_application' => $job->last_date_of_application
233
        ];
234
 
235
        $update = $this->sql->update(self::_TABLE);
236
        $update->set($values);
237
 
238
 
239
        $update->where->equalTo('id', $job->id);
240
        return $this->executeUpdate($update);
241
    }
242
 
243
    /**
244
     *
245
     * @param Job $job
246
     * @return boolean
247
     */
248
    public function updateHowApply($job)
249
    {
250
        $values = [
251
            'job_apply_email' => $job->apply_email,
252
            'job_apply_url' => $job->apply_url,
253
        ];
254
 
255
        $update = $this->sql->update(self::_TABLE);
256
        $update->set($values);
257
 
258
 
259
        $update->where->equalTo('id', $job->id);
260
        return $this->executeUpdate($update);
261
    }
262
 
263
    /**
264
     *
265
     * @param Job $job
266
     * @return boolean
267
     */
268
    public function updateLocation($job)
269
    {
270
        $values = [
271
            'location_id' => $job->location_id
272
        ];
273
 
274
        $update = $this->sql->update(self::_TABLE);
275
        $update->set($values);
276
 
277
 
278
        $update->where->equalTo('id', $job->id);
279
        return $this->executeUpdate($update);
280
    }
281
 
282
    /**
283
     *
284
     * @param Job $job
285
     * @return boolean
286
     */
287
    public function updateExperience($job)
288
    {
289
        $values = [
290
            'experience_visible'=> $job->experience_visible,
291
            'experience_min' => $job->experience_min,
292
            'experience_max' => $job->experience_max,
293
        ];
294
 
295
        $update = $this->sql->update(self::_TABLE);
296
        $update->set($values);
297
 
298
 
299
        $update->where->equalTo('id', $job->id);
300
        return $this->executeUpdate($update);
301
    }
302
 
303
    /**
304
     *
305
     * @param Job $job
306
     * @return boolean
307
     */
308
    public function updateSalary($job)
309
    {
310
        $values = [
311
            'salary_visible'=> $job->salary_visible,
312
            'salary_min' => $job->salary_min,
313
            'salary_max' => $job->salary_max,
314
            'salary_currency' => $job->salary_currency,
315
        ];
316
 
317
        $update = $this->sql->update(self::_TABLE);
318
        $update->set($values);
319
 
320
 
321
        $update->where->equalTo('id', $job->id);
322
        return $this->executeUpdate($update);
323
    }
324
 
325
    /**
326
     *
327
     * @param Job $job
328
     * @return boolean
329
     */
330
    public function delete($job)
331
    {
332
        $values = [
333
            'status'=> Job::STATUS_DELETED,
334
        ];
335
 
336
        $update = $this->sql->update(self::_TABLE);
337
        $update->set($values);
338
 
339
 
340
        $update->where->equalTo('id', $job->id);
341
        return $this->executeUpdate($update);
342
    }
343
 
344
    /**
345
     *
346
     * @param int $companyId
347
     * @param string $search
348
     * @param int $page
349
     * @param int $records_per_page
350
     * @param string $order_field
351
     * @param string $order_direction
352
     * @return Paginator
353
     */
354
    public function fetchAllDataTableByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
355
    {
356
        $prototype = new Job();
357
        $select = $this->sql->select(self::_TABLE);
358
        $select->where->equalTo('company_id', $companyId);
359
        $select->where->in('status', [
360
            Job::STATUS_ACTIVE,
361
            Job::STATUS_INACTIVE,
362
        ]);
363
 
364
        if($search) {
169 efrain 365
            $select->where->like('title', '%' . $search . '%');
1 www 366
        }
367
        $select->order($order_field . ' ' . $order_direction);
368
 
369
        //echo $select->getSqlString($this->adapter->platform); exit;
370
 
371
        $hydrator   = new ObjectPropertyHydrator();
372
        $resultset  = new HydratingResultSet($hydrator, $prototype);
373
 
374
        $adapter = new DbSelect($select, $this->sql, $resultset);
375
        $paginator = new Paginator($adapter);
376
        $paginator->setItemCountPerPage($records_per_page);
377
        $paginator->setCurrentPageNumber($page);
378
 
379
 
380
        return $paginator;
381
    }
382
}