Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1620 | Rev 1658 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1603 nelberth 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
8
use LeadersLinked\Model\HighPerformanceTeamsGroups;
9
use LeadersLinked\Mapper\Common\MapperCommon;
10
use Laminas\Db\Adapter\AdapterInterface;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\ResultSet\HydratingResultSet;
13
use Laminas\Paginator\Adapter\DbSelect;
14
use Laminas\Paginator\Paginator;
15
 
16
 
17
class HighPerformanceTeamsGroupsMembersMapper extends MapperCommon{
18
    const _TABLE = 'tbl_high_performance_team_group_members';
19
 
20
    /**
21
     *
22
     * @var HighPerformanceTeamsGroupsMembersMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return \LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new HighPerformanceTeamsGroupsMembersMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
 
49
 
50
    public function fetchAllDataTable($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC', $idUser)
51
    {
52
        $prototype = new HighPerformanceTeamsGroupsMembers();
53
        $select = $this->sql->select(self::_TABLE);
54
        $select->where->equalTo('user_id', $idUser);
55
        $select->where->notEqualTo('status', HighPerformanceTeamsGroupsMembers::STATUS_DELETE);
56
 
57
 
58
        if($search) {
59
            $select->where->like('title', '%' . $search . '%');
60
        }
61
        $select->order($order_field . ' ' . $order_direction);
62
 
63
        $hydrator   = new ObjectPropertyHydrator();
64
        $resultset  = new HydratingResultSet($hydrator, $prototype);
65
 
66
        $adapter = new DbSelect($select, $this->sql, $resultset);
67
        $paginator = new Paginator($adapter);
68
        $paginator->setItemCountPerPage($records_per_page);
69
        $paginator->setCurrentPageNumber($page);
70
 
71
 
72
        return $paginator;
73
    }
74
    public function fetchAllDataTableInnerJoin($search, $page = 1, $records_per_page = 10, $order_field= 'title', $order_direction = 'ASC', $idUser,$tableJoin)
75
    {
76
        $prototype = new HighPerformanceTeamsGroups();
77
        $select = $this->sql->select();
78
        $select->from(['g' => $tableJoin]);
79
        $select->join(['gm' => self::_TABLE], 'gm.group_id = g.id', []);
80
        $select->where->equalTo('gm.user_id', $idUser);
81
        $select->where->notEqualTo('gm.status', HighPerformanceTeamsGroupsMembers::STATUS_DELETE);
82
 
83
 
84
        if($search) {
85
            $select->where->like('title', '%' . $search . '%');
86
        }
87
        $select->order($order_field . ' ' . $order_direction);
88
 
89
        $hydrator   = new ObjectPropertyHydrator();
90
        $resultset  = new HydratingResultSet($hydrator, $prototype);
91
 
92
        $adapter = new DbSelect($select, $this->sql, $resultset);
93
        $paginator = new Paginator($adapter);
94
        $paginator->setItemCountPerPage($records_per_page);
95
        $paginator->setCurrentPageNumber($page);
96
 
97
 
98
        return $paginator;
99
    }
100
 
1657 nelberth 101
    public function fetchAll($group_id)
1603 nelberth 102
    {
103
        $prototype = new HighPerformanceTeamsGroupsMembers();
104
        $select = $this->sql->select(self::_TABLE);
1657 nelberth 105
        $select->where->equalTo('group_id', $group_id);
1603 nelberth 106
        $select->where->notEqualTo('status', HighPerformanceTeamsGroupsMembers::STATUS_DELETE);
107
        return $this->executeFetchAllObject($select, $prototype);
108
    }
109
    public function insert($datos)
110
    {
111
        $hydrator = new ObjectPropertyHydrator();
112
        $values = $hydrator->extract($datos);
113
        $values = $this->removeEmpty($values);
114
        $insert = $this->sql->insert(self::_TABLE);
115
        $insert->values($values);
116
 
117
 
118
        $result = $this->executeInsert($insert);
119
        if($result) {
120
            $datos->id = $this->lastInsertId;
121
        }
122
 
123
        return $result;
124
 
125
    }
1620 nelberth 126
    public function fetchOneByGroupIdAndUserId($group_id, $user_id)
127
    {
128
        $prototype = new HighPerformanceTeamsGroupsMembers();
129
 
130
        $select = $this->sql->select(self::_TABLE);
131
        $select->where->equalTo('group_id', $group_id)->and->equalTo('user_id', $user_id);
132
 
133
        return $this->executeFetchOneObject($select, $prototype);
134
    }
1603 nelberth 135
    public function update($form)
136
    {
137
        $hydrator = new ObjectPropertyHydrator();
138
        $values = $hydrator->extract($form);
139
        $values = $this->removeEmpty($values);
140
 
141
        $update = $this->sql->update(self::_TABLE);
142
        $update->set($values);
143
        $update->where->equalTo('id', $form->id);
144
        return $this->executeUpdate($update);
145
    }
146
 
147
    public function delete($form_id)
148
    {
149
        $delete = $this->sql->delete(self::_TABLE);
150
        $delete->where->equalTo('id', $form_id);
151
 
152
        return $this->executeDelete($delete);
153
    }
154
 
155
    public function fetchOneById($id)
156
    {
157
        $prototype = new HighPerformanceTeamsGroupsMembers();
158
        $select = $this->sql->select(self::_TABLE);
159
        $select->where->equalTo('id', $id);
160
 
161
        return $this->executeFetchOneObject($select, $prototype);
162
    }
163
    public function fetchOneByUserId($id)
164
    {
165
        $prototype = new HighPerformanceTeamsGroupsMembers();
166
        $select = $this->sql->select(self::_TABLE);
167
        $select->where->equalTo('user_id', $id);
168
 
169
        return $this->executeFetchOneObject($select, $prototype);
170
    }
171
    public function fetchOneByGroupId($id)
172
    {
173
        $prototype = new HighPerformanceTeamsGroupsMembers();
174
        $select = $this->sql->select(self::_TABLE);
175
        $select->where->equalTo('group_id', $id);
176
 
177
        return $this->executeFetchOneObject($select, $prototype);
178
    }
179
 
180
 
181
}