Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 4733 | | 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
     */
6793 efrain 76
    public function fetchAllDataTable($search, $status, $network_id,  $page = 1,  $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
     *
4733 efrain 221
     * @return Company
222
     */
223
    public function fetchOneDefaultForFollowers()
224
    {
225
        $prototype = new Company;
226
        $select = $this->sql->select(self::_TABLE);
227
        $select->where->equalTo('default_for_followers', Company::DEFAULT_FOR_FOLLOWERS_YES);
228
 
229
        return $this->executeFetchOneObject($select, $prototype);
230
    }
231
 
232
 
233
 
234
    /**
235
     *
3639 efrain 236
     * @param string $uuid
237
     * @param int $network_id
238
     * @return Company
239
     */
240
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
241
    {
242
        $prototype = new Company;
243
        $select = $this->sql->select(self::_TABLE);
244
        $select->where->equalTo('uuid', $uuid);
245
        $select->where->equalTo('network_id', $network_id);
246
 
247
        return $this->executeFetchOneObject($select, $prototype);
248
    }
249
 
250
    /**
1 www 251
     *
252
     * @param Company $company
253
     * @return boolean
254
     */
255
    public function insert($company)
256
    {
257
        $hydrator = new ObjectPropertyHydrator();
258
        $values = $hydrator->extract($company);
259
        $values = $this->removeEmpty($values);
260
 
261
 
262
        if(empty($values['description']) ) {
263
            $values['description'] = '' ;
264
        }
265
 
266
        $insert = $this->sql->insert(self::_TABLE);
267
        $insert->values($values);
268
 
269
        //echo $insert->getSqlString($this->adapter->platform); exit;
270
 
271
        $result = $this->executeInsert($insert);
272
        if($result) {
273
            $company->id = $this->lastInsertId;
274
        }
275
 
276
        return $result;
277
    }
278
 
279
    /**
280
     *
281
     * @param int $id
282
     * @return boolean
283
     */
284
    public function delete($id)
285
    {
286
 
287
        $update = $this->sql->update(self::_TABLE);
288
        $update->set([
289
            'status' => Company::STATUS_DELETED,
290
        ]);
291
        $update->where->equalTo('id', $id);
292
 
293
        return $this->executeUpdate($update);
294
    }
295
 
296
    /**
297
     *
298
     * @param Company $company
299
     * @return boolean
300
     */
301
    public function updatePremium($company)
302
    {
303
 
304
        $update = $this->sql->update(self::_TABLE);
305
        $update->set([
306
            'status_bigbluebutton' => $company->status_bigbluebutton,
307
            'status_high_performance_groups' => $company->status_high_performance_groups,
308
            'status_microlearning' => $company->status_microlearning,
309
            'status_self_evaluation' => $company->status_self_evaluation,
310
 
311
        ]);
312
        $update->where->equalTo('id', $company->id);
313
 
314
        return $this->executeUpdate($update);
315
    }
316
 
317
    /**
318
     *
319
     * @param Company $company
320
     * @return boolean
321
     */
322
    public function updateExtended($company)
323
    {
324
        $values = [
325
            'description' => $company->description,
326
        ];
327
 
328
        $update = $this->sql->update(self::_TABLE);
329
        $update->set($values);
330
        $update->where->equalTo('id', $company->id);
331
 
332
        return $this->executeUpdate($update);
333
 
334
    }
335
 
336
    /**
337
     *
338
     * @param Company $company
339
     * @return boolean
340
     */
341
    public function updateWebsite($company)
342
    {
343
        $values = [
344
            'website' => $company->website,
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 updateFoundationYear($company)
361
    {
362
        $values = [
363
            'foundation_year' => $company->foundation_year,
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 updateImage($company)
380
    {
381
        $values = [
382
            'image' => $company->image,
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 updateCover($company)
399
    {
400
        $values = [
401
            'cover' => $company->cover,
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
    }
535 geraldo 411
 
412
    /**
413
     *
414
     * @param Company $company
415
     * @return boolean
416
     */
417
    public function updateHeader($company)
418
    {
419
        $values = [
420
            'header' => $company->header,
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 updateFooter($company)
437
    {
438
        $values = [
439
            'footer' => $company->footer,
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
    }
1 www 449
 
450
    /**
451
     *
452
     * @param Company $company
453
     * @return boolean
454
     */
455
    public function updateSocialNetwork($company)
456
    {
457
        $values = [
458
            'facebook' => $company->facebook,
459
            'instagram' => $company->instagram,
460
            'twitter' => $company->twitter,
461
        ];
462
 
463
        $update = $this->sql->update(self::_TABLE);
464
        $update->set($values);
465
        $update->where->equalTo('id', $company->id);
466
 
467
        return $this->executeUpdate($update);
468
 
469
    }
470
 
471
 
472
    /**
473
     *
474
     * @param Company $company
475
     * @return boolean
476
     */
477
    public function updateIndustry($company)
478
    {
479
        $values = [
480
            'industry_id' => $company->industry_id,
481
        ];
482
 
483
        $update = $this->sql->update(self::_TABLE);
484
        $update->set($values);
485
        $update->where->equalTo('id', $company->id);
486
 
487
        return $this->executeUpdate($update);
488
 
489
    }
490
 
491
 
492
    /**
493
     *
494
     * @param Company $company
495
     * @return boolean
496
     */
497
    public function updateCompanySize($company)
498
    {
499
        $values = [
500
            'company_size_id' => $company->company_size_id,
501
        ];
502
 
503
        $update = $this->sql->update(self::_TABLE);
504
        $update->set($values);
505
        $update->where->equalTo('id', $company->id);
506
 
507
        return $this->executeUpdate($update);
508
 
509
    }
510
 
511
 
512
    /**
513
     *
514
     * @param Company $company
515
     * @return boolean
516
     */
517
    public function update($company)
518
    {
519
        $hydrator = new ObjectPropertyHydrator();
520
        $values = $hydrator->extract($company);
521
        $values = $this->removeEmpty($values);
522
 
523
 
524
        $update = $this->sql->update(self::_TABLE);
525
        $update->set($values);
526
        $update->where->equalTo('id', $company->id);
527
 
528
        return $this->executeUpdate($update);
529
 
530
    }
531
 
532
}