Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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