Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1657 | Rev 1659 | 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
        return $this->executeFetchAllObject($select, $prototype);
107
    }
108
    public function insert($datos)
109
    {
110
        $hydrator = new ObjectPropertyHydrator();
111
        $values = $hydrator->extract($datos);
112
        $values = $this->removeEmpty($values);
113
        $insert = $this->sql->insert(self::_TABLE);
114
        $insert->values($values);
115
 
116
 
117
        $result = $this->executeInsert($insert);
118
        if($result) {
119
            $datos->id = $this->lastInsertId;
120
        }
121
 
122
        return $result;
123
 
124
    }
1620 nelberth 125
    public function fetchOneByGroupIdAndUserId($group_id, $user_id)
126
    {
127
        $prototype = new HighPerformanceTeamsGroupsMembers();
128
 
129
        $select = $this->sql->select(self::_TABLE);
130
        $select->where->equalTo('group_id', $group_id)->and->equalTo('user_id', $user_id);
131
 
132
        return $this->executeFetchOneObject($select, $prototype);
133
    }
1603 nelberth 134
    public function update($form)
135
    {
136
        $hydrator = new ObjectPropertyHydrator();
137
        $values = $hydrator->extract($form);
138
        $values = $this->removeEmpty($values);
139
 
140
        $update = $this->sql->update(self::_TABLE);
141
        $update->set($values);
142
        $update->where->equalTo('id', $form->id);
143
        return $this->executeUpdate($update);
144
    }
145
 
146
    public function delete($form_id)
147
    {
148
        $delete = $this->sql->delete(self::_TABLE);
149
        $delete->where->equalTo('id', $form_id);
150
 
151
        return $this->executeDelete($delete);
152
    }
153
 
154
    public function fetchOneById($id)
155
    {
156
        $prototype = new HighPerformanceTeamsGroupsMembers();
157
        $select = $this->sql->select(self::_TABLE);
158
        $select->where->equalTo('id', $id);
159
 
160
        return $this->executeFetchOneObject($select, $prototype);
161
    }
162
    public function fetchOneByUserId($id)
163
    {
164
        $prototype = new HighPerformanceTeamsGroupsMembers();
165
        $select = $this->sql->select(self::_TABLE);
166
        $select->where->equalTo('user_id', $id);
167
 
168
        return $this->executeFetchOneObject($select, $prototype);
169
    }
170
    public function fetchOneByGroupId($id)
171
    {
172
        $prototype = new HighPerformanceTeamsGroupsMembers();
173
        $select = $this->sql->select(self::_TABLE);
174
        $select->where->equalTo('group_id', $id);
175
 
176
        return $this->executeFetchOneObject($select, $prototype);
177
    }
178
 
179
 
180
}