Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 535 | Rev 4733 | 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 LeadersLinked\Model\Company;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\Sql\Expression;
13
use Laminas\Db\ResultSet\HydratingResultSet;
14
use Laminas\Paginator\Adapter\DbSelect;
15
use Laminas\Paginator\Paginator;
16
 
17
 
18
class CompanyMapper extends MapperCommon
19
{
20
    const _TABLE = 'tbl_companies';
21
 
22
 
23
    /**
24
     *
25
     * @var CompanyMapper
26
     */
27
    private static $_instance;
28
 
29
    /**
30
     *
31
     * @param AdapterInterface $adapter
32
     */
33
    private function __construct($adapter)
34
    {
35
        parent::__construct($adapter);
36
    }
37
 
38
    /**
39
     *
40
     * @param AdapterInterface $adapter
41
     * @param LoggerInterface $logger
42
     * @param int $user_id
43
     * @return \LeadersLinked\Mapper\CompanyMapper
44
     */
45
    public static function getInstance($adapter)
46
    {
47
        if(self::$_instance == null) {
48
            self::$_instance = new CompanyMapper($adapter);
49
        }
50
        return self::$_instance;
51
    }
52
 
53
    /**
54
     *
55
     * @return Company[]
56
     */
57
    public function fetchAll()
58
    {
59
        $prototype = new Company;
60
        $select = $this->sql->select(self::_TABLE);
61
 
62
        return $this->executeFetchAllObject($select, $prototype);
63
    }
64
 
65
    /**
66
     *
67
     * @param string $search
68
     * @param int $page
69
     * @param string $status
3639 efrain 70
     * @param int $network_id
1 www 71
     * @param int $records_per_page
72
     * @param string $order_field
73
     * @param string $order_direction
74
     * @return Paginator
75
     */
3639 efrain 76
    public function fetchAllDataTable($search, $page = 1, $status, $network_id,  $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
1 www 77
    {
78
        $prototype = new Company();
79
        $select = $this->sql->select(self::_TABLE);
80
 
81
 
82
        if($search) {
83
            $select->where->like('name', '%' . $search . '%');
84
        }
85
 
86
        if($status) {
87
            $select->where->equalTo('status', $status);
88
        }
89
 
3639 efrain 90
        if($network_id) {
91
            $select->where->equalTo('network_id', $network_id);
92
        }
93
 
94
 
1 www 95
        $select->order($order_field . ' ' . $order_direction);
96
 
97
        $hydrator   = new ObjectPropertyHydrator();
98
        $resultset  = new HydratingResultSet($hydrator, $prototype);
99
 
100
        $adapter = new DbSelect($select, $this->sql, $resultset);
101
        $paginator = new Paginator($adapter);
102
        $paginator->setItemCountPerPage($records_per_page);
103
        $paginator->setCurrentPageNumber($page);
104
 
105
 
106
        return $paginator;
107
    }
108
 
109
 
110
    /**
111
     *
112
     * @param string $status
113
     * @param string $search
114
     * @param int $page
115
     * @param int $records_per_page
116
     * @param string $order_field
117
     * @param string $order_direction
118
     * @return Paginator
119
     */
120
    public function fetchAllDataTableByStatus($status, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
121
    {
122
        $prototype = new Company();
123
        $select = $this->sql->select(self::_TABLE);
124
        $select->where->equalTo('status', $status);
125
 
126
 
127
        if($search) {
128
            $select->where->like('name', '%' . $search . '%');
129
        }
130
        $select->order($order_field . ' ' . $order_direction);
131
 
132
        $hydrator   = new ObjectPropertyHydrator();
133
        $resultset  = new HydratingResultSet($hydrator, $prototype);
134
 
135
        $adapter = new DbSelect($select, $this->sql, $resultset);
136
        $paginator = new Paginator($adapter);
137
        $paginator->setItemCountPerPage($records_per_page);
138
        $paginator->setCurrentPageNumber($page);
139
 
140
 
141
        return $paginator;
142
    }
143
 
144
    /**
145
     *
146
     * @param int $id
147
     * @return Company
148
     */
149
    public function fetchOne($id)
150
    {
151
        $prototype = new Company;
152
        $select = $this->sql->select(self::_TABLE);
153
        $select->where->equalTo('id', $id);
154
 
155
        return $this->executeFetchOneObject($select, $prototype);
156
    }
157
 
3639 efrain 158
 
1 www 159
    /**
160
     *
3639 efrain 161
     * @param int $network_id
162
     * @return Company
163
     */
164
    public function fetchDefaultForNetworkByNetworkId($network_id)
165
    {
166
        $prototype = new Company;
167
        $select = $this->sql->select(self::_TABLE);
168
        $select->where->equalTo('default_for_network', Company::DEFAULT_FOR_NETWORK_YES);
169
        $select->where->equalTo('network_id', $network_id);
170
 
171
        return $this->executeFetchOneObject($select, $prototype);
172
    }
173
 
174
 
175
    /**
176
     *
177
     * @param int $id
178
     * @param int $network_id
179
     * @return Company
180
     */
181
    public function fetchOneByIdAndNetworkId($id, $network_id)
182
    {
183
        $prototype = new Company;
184
        $select = $this->sql->select(self::_TABLE);
185
        $select->where->equalTo('id', $id);
186
        $select->where->equalTo('network_id', $network_id);
187
 
188
        return $this->executeFetchOneObject($select, $prototype);
189
    }
190
 
191
    /**
192
     *
1 www 193
 
194
     * @return Company
195
     */
196
    public function fetchOneInternal()
197
    {
198
        $prototype = new Company;
199
        $select = $this->sql->select(self::_TABLE);
200
        $select->where->equalTo('internal', Company::INTERNAL_YES);
201
 
202
        return $this->executeFetchOneObject($select, $prototype);
203
    }
204
 
205
    /**
206
     *
207
     * @param int $uuid
208
     * @return Company
209
     */
210
    public function fetchOneByUuid($uuid)
211
    {
212
        $prototype = new Company;
213
        $select = $this->sql->select(self::_TABLE);
214
        $select->where->equalTo('uuid', $uuid);
215
 
216
        return $this->executeFetchOneObject($select, $prototype);
217
    }
218
 
219
    /**
3639 efrain 220
     *
221
     * @param string $uuid
222
     * @param int $network_id
223
     * @return Company
224
     */
225
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
226
    {
227
        $prototype = new Company;
228
        $select = $this->sql->select(self::_TABLE);
229
        $select->where->equalTo('uuid', $uuid);
230
        $select->where->equalTo('network_id', $network_id);
231
 
232
        return $this->executeFetchOneObject($select, $prototype);
233
    }
234
 
235
    /**
1 www 236
     *
237
     * @param Company $company
238
     * @return boolean
239
     */
240
    public function insert($company)
241
    {
242
        $hydrator = new ObjectPropertyHydrator();
243
        $values = $hydrator->extract($company);
244
        $values = $this->removeEmpty($values);
245
 
246
 
247
        if(empty($values['description']) ) {
248
            $values['description'] = '' ;
249
        }
250
 
251
        $insert = $this->sql->insert(self::_TABLE);
252
        $insert->values($values);
253
 
254
        //echo $insert->getSqlString($this->adapter->platform); exit;
255
 
256
        $result = $this->executeInsert($insert);
257
        if($result) {
258
            $company->id = $this->lastInsertId;
259
        }
260
 
261
        return $result;
262
    }
263
 
264
    /**
265
     *
266
     * @param int $id
267
     * @return boolean
268
     */
269
    public function delete($id)
270
    {
271
 
272
        $update = $this->sql->update(self::_TABLE);
273
        $update->set([
274
            'status' => Company::STATUS_DELETED,
275
        ]);
276
        $update->where->equalTo('id', $id);
277
 
278
        return $this->executeUpdate($update);
279
    }
280
 
281
    /**
282
     *
283
     * @param Company $company
284
     * @return boolean
285
     */
286
    public function updatePremium($company)
287
    {
288
 
289
        $update = $this->sql->update(self::_TABLE);
290
        $update->set([
291
            'status_bigbluebutton' => $company->status_bigbluebutton,
292
            'status_high_performance_groups' => $company->status_high_performance_groups,
293
            'status_microlearning' => $company->status_microlearning,
294
            'status_self_evaluation' => $company->status_self_evaluation,
295
 
296
        ]);
297
        $update->where->equalTo('id', $company->id);
298
 
299
        return $this->executeUpdate($update);
300
    }
301
 
302
    /**
303
     *
304
     * @param Company $company
305
     * @return boolean
306
     */
307
    public function updateExtended($company)
308
    {
309
        $values = [
310
            'description' => $company->description,
311
        ];
312
 
313
        $update = $this->sql->update(self::_TABLE);
314
        $update->set($values);
315
        $update->where->equalTo('id', $company->id);
316
 
317
        return $this->executeUpdate($update);
318
 
319
    }
320
 
321
    /**
322
     *
323
     * @param Company $company
324
     * @return boolean
325
     */
326
    public function updateWebsite($company)
327
    {
328
        $values = [
329
            'website' => $company->website,
330
        ];
331
 
332
        $update = $this->sql->update(self::_TABLE);
333
        $update->set($values);
334
        $update->where->equalTo('id', $company->id);
335
 
336
        return $this->executeUpdate($update);
337
 
338
    }
339
 
340
    /**
341
     *
342
     * @param Company $company
343
     * @return boolean
344
     */
345
    public function updateFoundationYear($company)
346
    {
347
        $values = [
348
            'foundation_year' => $company->foundation_year,
349
        ];
350
 
351
        $update = $this->sql->update(self::_TABLE);
352
        $update->set($values);
353
        $update->where->equalTo('id', $company->id);
354
 
355
        return $this->executeUpdate($update);
356
 
357
    }
358
 
359
    /*
360
    *
361
    * @param Company $company
362
    * @return boolean
363
    */
364
    public function updateImage($company)
365
    {
366
        $values = [
367
            'image' => $company->image,
368
        ];
369
 
370
        $update = $this->sql->update(self::_TABLE);
371
        $update->set($values);
372
        $update->where->equalTo('id', $company->id);
373
 
374
        return $this->executeUpdate($update);
375
 
376
    }
377
 
378
    /**
379
     *
380
     * @param Company $company
381
     * @return boolean
382
     */
383
    public function updateCover($company)
384
    {
385
        $values = [
386
            'cover' => $company->cover,
387
        ];
388
 
389
        $update = $this->sql->update(self::_TABLE);
390
        $update->set($values);
391
        $update->where->equalTo('id', $company->id);
392
 
393
        return $this->executeUpdate($update);
394
 
395
    }
535 geraldo 396
 
397
    /**
398
     *
399
     * @param Company $company
400
     * @return boolean
401
     */
402
    public function updateHeader($company)
403
    {
404
        $values = [
405
            'header' => $company->header,
406
        ];
407
 
408
        $update = $this->sql->update(self::_TABLE);
409
        $update->set($values);
410
        $update->where->equalTo('id', $company->id);
411
 
412
        return $this->executeUpdate($update);
413
 
414
    }
415
 
416
    /**
417
     *
418
     * @param Company $company
419
     * @return boolean
420
     */
421
    public function updateFooter($company)
422
    {
423
        $values = [
424
            'footer' => $company->footer,
425
        ];
426
 
427
        $update = $this->sql->update(self::_TABLE);
428
        $update->set($values);
429
        $update->where->equalTo('id', $company->id);
430
 
431
        return $this->executeUpdate($update);
432
 
433
    }
1 www 434
 
435
    /**
436
     *
437
     * @param Company $company
438
     * @return boolean
439
     */
440
    public function updateSocialNetwork($company)
441
    {
442
        $values = [
443
            'facebook' => $company->facebook,
444
            'instagram' => $company->instagram,
445
            'twitter' => $company->twitter,
446
        ];
447
 
448
        $update = $this->sql->update(self::_TABLE);
449
        $update->set($values);
450
        $update->where->equalTo('id', $company->id);
451
 
452
        return $this->executeUpdate($update);
453
 
454
    }
455
 
456
 
457
    /**
458
     *
459
     * @param Company $company
460
     * @return boolean
461
     */
462
    public function updateIndustry($company)
463
    {
464
        $values = [
465
            'industry_id' => $company->industry_id,
466
        ];
467
 
468
        $update = $this->sql->update(self::_TABLE);
469
        $update->set($values);
470
        $update->where->equalTo('id', $company->id);
471
 
472
        return $this->executeUpdate($update);
473
 
474
    }
475
 
476
 
477
    /**
478
     *
479
     * @param Company $company
480
     * @return boolean
481
     */
482
    public function updateCompanySize($company)
483
    {
484
        $values = [
485
            'company_size_id' => $company->company_size_id,
486
        ];
487
 
488
        $update = $this->sql->update(self::_TABLE);
489
        $update->set($values);
490
        $update->where->equalTo('id', $company->id);
491
 
492
        return $this->executeUpdate($update);
493
 
494
    }
495
 
496
 
497
    /**
498
     *
499
     * @param Company $company
500
     * @return boolean
501
     */
502
    public function update($company)
503
    {
504
        $hydrator = new ObjectPropertyHydrator();
505
        $values = $hydrator->extract($company);
506
        $values = $this->removeEmpty($values);
507
 
508
 
509
        $update = $this->sql->update(self::_TABLE);
510
        $update->set($values);
511
        $update->where->equalTo('id', $company->id);
512
 
513
        return $this->executeUpdate($update);
514
 
515
    }
516
 
517
}