Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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