Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev Autor Línea Nro. Línea
1 efrain 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
70
     * @param int $network_id
71
     * @param int $records_per_page
72
     * @param string $order_field
73
     * @param string $order_direction
74
     * @return Paginator
75
     */
76
    public function fetchAllDataTable($search, $status, $network_id,  $page = 1,  $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
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
 
90
        if($network_id) {
91
            $select->where->equalTo('network_id', $network_id);
92
        }
93
 
94
 
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
    /**
119 efrain 145
     *
146
     * @param int[] $ids
147
     * @param int $network_id
148
     * @return Company[]
149
     */
150
    public function fetchAllByIdsAndNetworkId($ids, $network_id)
151
    {
152
        $ids = empty($ids) ? [0] : $ids;
153
 
154
        $prototype = new Company();
155
        $select = $this->sql->select(self::_TABLE);
156
        $select->where->in('id', $ids);
157
        $select->where->equalTo('network_id', $network_id);
158
        $select->order('name');
159
 
160
        return $this->executeFetchAllObject($select, $prototype);
161
    }
162
 
163
    /**
1 efrain 164
     *
165
     * @param int $id
166
     * @return Company
167
     */
168
    public function fetchOne($id)
169
    {
170
        $prototype = new Company;
171
        $select = $this->sql->select(self::_TABLE);
172
        $select->where->equalTo('id', $id);
173
 
174
        return $this->executeFetchOneObject($select, $prototype);
175
    }
119 efrain 176
 
1 efrain 177
 
178
    /**
179
     *
180
     * @param int $network_id
181
     * @return Company
182
     */
183
    public function fetchDefaultForNetworkByNetworkId($network_id)
184
    {
185
        $prototype = new Company;
186
        $select = $this->sql->select(self::_TABLE);
187
        $select->where->equalTo('default_for_network', Company::DEFAULT_FOR_NETWORK_YES);
188
        $select->where->equalTo('network_id', $network_id);
189
 
190
        return $this->executeFetchOneObject($select, $prototype);
191
    }
192
 
193
 
194
    /**
195
     *
196
     * @param int $id
197
     * @param int $network_id
198
     * @return Company
199
     */
200
    public function fetchOneByIdAndNetworkId($id, $network_id)
201
    {
202
        $prototype = new Company;
203
        $select = $this->sql->select(self::_TABLE);
204
        $select->where->equalTo('id', $id);
205
        $select->where->equalTo('network_id', $network_id);
206
 
207
        return $this->executeFetchOneObject($select, $prototype);
208
    }
209
 
210
    /**
211
     *
212
 
213
     * @return Company
214
     */
215
    public function fetchOneInternal()
216
    {
217
        $prototype = new Company;
218
        $select = $this->sql->select(self::_TABLE);
219
        $select->where->equalTo('internal', Company::INTERNAL_YES);
220
 
221
        return $this->executeFetchOneObject($select, $prototype);
222
    }
223
 
224
    /**
225
     *
226
     * @param int $uuid
227
     * @return Company
228
     */
229
    public function fetchOneByUuid($uuid)
230
    {
231
        $prototype = new Company;
232
        $select = $this->sql->select(self::_TABLE);
233
        $select->where->equalTo('uuid', $uuid);
234
 
235
        return $this->executeFetchOneObject($select, $prototype);
236
    }
237
 
238
    /**
239
     *
240
     * @return Company
241
     */
242
    public function fetchOneDefaultForFollowers()
243
    {
244
        $prototype = new Company;
245
        $select = $this->sql->select(self::_TABLE);
246
        $select->where->equalTo('default_for_followers', Company::DEFAULT_FOR_FOLLOWERS_YES);
247
 
248
        return $this->executeFetchOneObject($select, $prototype);
249
    }
250
 
251
 
252
 
253
    /**
254
     *
255
     * @param string $uuid
256
     * @param int $network_id
257
     * @return Company
258
     */
259
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
260
    {
261
        $prototype = new Company;
262
        $select = $this->sql->select(self::_TABLE);
263
        $select->where->equalTo('uuid', $uuid);
264
        $select->where->equalTo('network_id', $network_id);
265
 
266
        return $this->executeFetchOneObject($select, $prototype);
267
    }
268
 
269
    /**
270
     *
271
     * @param Company $company
272
     * @return boolean
273
     */
274
    public function insert($company)
275
    {
276
        $hydrator = new ObjectPropertyHydrator();
277
        $values = $hydrator->extract($company);
278
        $values = $this->removeEmpty($values);
279
 
280
 
281
        if(empty($values['description']) ) {
282
            $values['description'] = '' ;
283
        }
284
 
285
        $insert = $this->sql->insert(self::_TABLE);
286
        $insert->values($values);
287
 
288
        //echo $insert->getSqlString($this->adapter->platform); exit;
289
 
290
        $result = $this->executeInsert($insert);
291
        if($result) {
292
            $company->id = $this->lastInsertId;
293
        }
294
 
295
        return $result;
296
    }
297
 
298
    /**
299
     *
300
     * @param int $id
301
     * @return boolean
302
     */
303
    public function delete($id)
304
    {
305
 
306
        $update = $this->sql->update(self::_TABLE);
307
        $update->set([
308
            'status' => Company::STATUS_DELETED,
309
        ]);
310
        $update->where->equalTo('id', $id);
311
 
312
        return $this->executeUpdate($update);
313
    }
314
 
315
    /**
316
     *
317
     * @param Company $company
318
     * @return boolean
319
     */
320
    public function updatePremium($company)
321
    {
322
 
323
        $update = $this->sql->update(self::_TABLE);
324
        $update->set([
325
            'status_bigbluebutton' => $company->status_bigbluebutton,
326
            'status_high_performance_groups' => $company->status_high_performance_groups,
327
            'status_microlearning' => $company->status_microlearning,
328
            'status_self_evaluation' => $company->status_self_evaluation,
329
 
330
        ]);
331
        $update->where->equalTo('id', $company->id);
332
 
333
        return $this->executeUpdate($update);
334
    }
335
 
336
    /**
337
     *
338
     * @param Company $company
339
     * @return boolean
340
     */
341
    public function updateExtended($company)
342
    {
343
        $values = [
344
            'description' => $company->description,
345
        ];
346
 
347
        $update = $this->sql->update(self::_TABLE);
348
        $update->set($values);
349
        $update->where->equalTo('id', $company->id);
350
 
351
        return $this->executeUpdate($update);
352
 
353
    }
354
 
355
    /**
356
     *
357
     * @param Company $company
358
     * @return boolean
359
     */
360
    public function updateWebsite($company)
361
    {
362
        $values = [
363
            'website' => $company->website,
364
        ];
365
 
366
        $update = $this->sql->update(self::_TABLE);
367
        $update->set($values);
368
        $update->where->equalTo('id', $company->id);
369
 
370
        return $this->executeUpdate($update);
371
 
372
    }
373
 
374
    /**
375
     *
376
     * @param Company $company
377
     * @return boolean
378
     */
379
    public function updateFoundationYear($company)
380
    {
381
        $values = [
382
            'foundation_year' => $company->foundation_year,
383
        ];
384
 
385
        $update = $this->sql->update(self::_TABLE);
386
        $update->set($values);
387
        $update->where->equalTo('id', $company->id);
388
 
389
        return $this->executeUpdate($update);
390
 
391
    }
392
 
393
    /*
394
    *
395
    * @param Company $company
396
    * @return boolean
397
    */
398
    public function updateImage($company)
399
    {
400
        $values = [
401
            'image' => $company->image,
402
        ];
403
 
404
        $update = $this->sql->update(self::_TABLE);
405
        $update->set($values);
406
        $update->where->equalTo('id', $company->id);
407
 
408
        return $this->executeUpdate($update);
409
 
410
    }
411
 
412
    /**
413
     *
414
     * @param Company $company
415
     * @return boolean
416
     */
417
    public function updateCover($company)
418
    {
419
        $values = [
420
            'cover' => $company->cover,
421
        ];
422
 
423
        $update = $this->sql->update(self::_TABLE);
424
        $update->set($values);
425
        $update->where->equalTo('id', $company->id);
426
 
427
        return $this->executeUpdate($update);
428
 
429
    }
430
 
431
    /**
432
     *
433
     * @param Company $company
434
     * @return boolean
435
     */
436
    public function updateHeader($company)
437
    {
438
        $values = [
439
            'header' => $company->header,
440
        ];
441
 
442
        $update = $this->sql->update(self::_TABLE);
443
        $update->set($values);
444
        $update->where->equalTo('id', $company->id);
445
 
446
        return $this->executeUpdate($update);
447
 
448
    }
449
 
450
    /**
451
     *
452
     * @param Company $company
453
     * @return boolean
454
     */
455
    public function updateFooter($company)
456
    {
457
        $values = [
458
            'footer' => $company->footer,
459
        ];
460
 
461
        $update = $this->sql->update(self::_TABLE);
462
        $update->set($values);
463
        $update->where->equalTo('id', $company->id);
464
 
465
        return $this->executeUpdate($update);
466
 
467
    }
468
 
469
    /**
470
     *
471
     * @param Company $company
472
     * @return boolean
473
     */
474
    public function updateSocialNetwork($company)
475
    {
476
        $values = [
477
            'facebook' => $company->facebook,
478
            'instagram' => $company->instagram,
479
            'twitter' => $company->twitter,
480
        ];
481
 
482
        $update = $this->sql->update(self::_TABLE);
483
        $update->set($values);
484
        $update->where->equalTo('id', $company->id);
485
 
486
        return $this->executeUpdate($update);
487
 
488
    }
489
 
490
 
491
    /**
492
     *
493
     * @param Company $company
494
     * @return boolean
495
     */
496
    public function updateIndustry($company)
497
    {
498
        $values = [
499
            'industry_id' => $company->industry_id,
500
        ];
501
 
502
        $update = $this->sql->update(self::_TABLE);
503
        $update->set($values);
504
        $update->where->equalTo('id', $company->id);
505
 
506
        return $this->executeUpdate($update);
507
 
508
    }
509
 
510
 
511
    /**
512
     *
513
     * @param Company $company
514
     * @return boolean
515
     */
516
    public function updateCompanySize($company)
517
    {
518
        $values = [
519
            'company_size_id' => $company->company_size_id,
520
        ];
521
 
522
        $update = $this->sql->update(self::_TABLE);
523
        $update->set($values);
524
        $update->where->equalTo('id', $company->id);
525
 
526
        return $this->executeUpdate($update);
527
 
528
    }
529
 
530
 
531
    /**
532
     *
533
     * @param Company $company
534
     * @return boolean
535
     */
536
    public function update($company)
537
    {
538
        $hydrator = new ObjectPropertyHydrator();
539
        $values = $hydrator->extract($company);
540
        $values = $this->removeEmpty($values);
541
 
542
 
543
        $update = $this->sql->update(self::_TABLE);
544
        $update->set($values);
545
        $update->where->equalTo('id', $company->id);
546
 
547
        return $this->executeUpdate($update);
548
 
549
    }
550
 
551
}