Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1650 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1635 nelberth 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\HighPerformanceTeamsGroupsViewTopic;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
use Laminas\Paginator\Paginator;
14
 
15
 
16
class HighPerformanceTeamsGroupsViewTopicMapper extends MapperCommon{
17
    const _TABLE = 'tbl_high_performance_team_group_topics';
18
 
19
    /**
20
     *
21
     * @var HighPerformanceTeamsGroupsViewTopicMapper
22
     */
23
    private static $_instance;
24
 
25
    /**
26
     *
27
     * @param AdapterInterface $adapter
28
     */
29
    private function __construct($adapter)
30
    {
31
        parent::__construct($adapter);
32
    }
33
 
34
    /**
35
     *
36
     * @param AdapterInterface $adapter
37
     * @return \LeadersLinked\Mapper\HighPerformanceTeamsGroupsViewTopicMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new HighPerformanceTeamsGroupsViewTopicMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
 
48
 
49
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC', $group_id)
50
    {
51
        $prototype = new HighPerformanceTeamsGroupsViewTopic();
52
        $select = $this->sql->select(self::_TABLE);
53
        $select->where->equalTo('group_id', $group_id);
54
        $select->where->notEqualTo('status', HighPerformanceTeamsGroupsViewTopic::STATUS_DELETE);
55
 
56
 
57
        if($search) {
58
            $select->where->like('title', '%' . $search . '%');
59
        }
60
        $select->order($order_field . ' ' . $order_direction);
61
 
62
 
63
 
64
        $hydrator   = new ObjectPropertyHydrator();
65
        $resultset  = new HydratingResultSet($hydrator, $prototype);
66
 
67
        $adapter = new DbSelect($select, $this->sql, $resultset);
68
        $paginator = new Paginator($adapter);
69
        $paginator->setItemCountPerPage($records_per_page);
70
        $paginator->setCurrentPageNumber($page);
71
 
72
 
73
        return $paginator;
74
    }
75
 
76
    public function fetchAll($group_id)
77
    {
78
        $prototype = new HighPerformanceTeamsGroupsViewTopic();
79
        $select = $this->sql->select(self::_TABLE);
80
        $select->where->equalTo('status', 'a');
81
        $select->where->equalTo('group_id', $group_id);
82
        $select->where->notEqualTo('status', HighPerformanceTeamsGroupsViewTopic::STATUS_DELETE);
83
        return $this->executeFetchAllObject($select, $prototype);
84
    }
85
    public function insert($datos)
86
    {
87
        $hydrator = new ObjectPropertyHydrator();
88
        $values = $hydrator->extract($datos);
89
        $values = $this->removeEmpty($values);
90
        $insert = $this->sql->insert(self::_TABLE);
91
        $insert->values($values);
92
 
93
 
94
        $result = $this->executeInsert($insert);
95
        if($result) {
96
            $datos->id = $this->lastInsertId;
97
        }
98
 
99
        return $result;
100
 
101
    }
102
 
103
    public function update($form)
104
    {
105
        $hydrator = new ObjectPropertyHydrator();
106
        $values = $hydrator->extract($form);
107
        $values = $this->removeEmpty($values);
108
 
109
        $update = $this->sql->update(self::_TABLE);
110
        $update->set($values);
111
        $update->where->equalTo('id', $form->id);
112
        return $this->executeUpdate($update);
113
    }
114
 
115
    public function delete($form_id)
116
    {
117
        $delete = $this->sql->delete(self::_TABLE);
118
        $delete->where->equalTo('id', $form_id);
119
 
120
        return $this->executeDelete($delete);
121
    }
122
 
123
    public function fetchOneByUuid($uuid)
124
    {
125
        $prototype = new HighPerformanceTeamsGroupsViewTopic();
126
        $select = $this->sql->select(self::_TABLE);
127
        $select->where->equalTo('uuid', $uuid);
128
 
129
        return $this->executeFetchOneObject($select, $prototype);
130
    }
131
 
132
 
133
 
134
}