Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
4689 efrain 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Mapper;
5
 
6
 
7
use LeadersLinked\Mapper\Common\MapperCommon;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Paginator\Paginator;
10
use LeadersLinked\Model\MyCoachCategory;
11
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
12
use Laminas\Db\ResultSet\HydratingResultSet;
13
use Laminas\Paginator\Adapter\DbSelect;
14
 
15
 
16
class MyCoachCategoryMapper extends MapperCommon
17
{
18
    const _TABLE = 'tbl_my_coach_categories';
19
 
20
    /**
21
     *
22
     * @var MyCoachCategoryMapper
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 MyCoachCategoryMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new MyCoachCategoryMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $id
51
     * @return MyCoachCategory
52
     */
53
    public function fetchOne($id)
54
    {
55
 
56
        $select = $this->sql->select(self::_TABLE);
57
        $select->where->equalTo('id', $id);
58
 
59
        $prototype = new MyCoachCategory();
60
        return $this->executeFetchOneObject($select, $prototype);
61
    }
62
 
63
 
64
    /**
65
     *
66
     * @param string $uuid
67
     * @return MyCoachCategory
68
     */
69
    public function fetchOneByUuid($uuid)
70
    {
71
 
72
        $select = $this->sql->select(self::_TABLE);
73
        $select->where->equalTo('uuid', $uuid);
74
 
75
        $prototype = new MyCoachCategory();
76
        return $this->executeFetchOneObject($select, $prototype);
77
    }
78
 
79
 
80
 
81
    /**
82
     *
83
     * @param int $company_id
84
     * @return MyCoachCategory[]
85
     */
86
    public function fetchAllByCompanyId($company_id)
87
    {
88
 
89
        $select = $this->sql->select(self::_TABLE);
90
        $select->where->equalTo('company_id', $company_id);
91
        $select->order('name DESC');
92
 
93
        $prototype = new MyCoachCategory();
94
        return $this->executeFetchAllObject($select, $prototype);
95
    }
96
 
97
    /**
98
     *
6388 efrain 99
     * @param int $network_id
100
     * @return MyCoachCategory[]
101
     */
102
    public function fetchAllByNetworkId($network_id)
103
    {
104
 
105
        $select = $this->sql->select(self::_TABLE);
106
        $select->where->equalTo('network_id', $network_id);
107
        $select->order('name DESC');
108
 
109
        $prototype = new MyCoachCategory();
110
        return $this->executeFetchAllObject($select, $prototype);
111
    }
112
 
113
 
114
    /**
115
     *
116
     * @param int $network_id
117
     * @return MyCoachCategory[]
118
     */
119
    public function fetchAllPublicByNetworkId($network_id)
120
    {
121
 
122
        $select = $this->sql->select(self::_TABLE);
123
        $select->where->equalTo('network_id', $network_id);
124
        $select->where->equalTo('privacy', MyCoachCategory::PRIVACY_PUBLIC);
125
        $select->order('name DESC');
126
 
127
        $prototype = new MyCoachCategory();
128
        return $this->executeFetchAllObject($select, $prototype);
129
    }
130
 
131
    /**
132
     *
133
     * @param array $ids
134
     * @return MyCoachCategory[]
135
     */
136
    public function fetchAllByIds($ids)
137
    {
138
 
139
        $select = $this->sql->select(self::_TABLE);
140
        $select->where->in('id', $ids);
141
        $select->order('name DESC');
142
 
143
        $prototype = new MyCoachCategory();
144
        return $this->executeFetchAllObject($select, $prototype);
145
    }
146
 
147
    /**
148
     *
4689 efrain 149
     * @param int $id
150
     * @return boolean
151
     */
152
    public function delete($id)
153
    {
154
        $delete = $this->sql->delete(self::_TABLE);
155
        $delete->where->equalTo('id', $id);
156
 
157
        return $this->executeDelete($delete);
158
    }
159
 
160
 
161
    /**
162
     *
163
     * @param MyCoachCategory $record
164
     * @return boolean
165
     */
166
    public function insert($record) {
167
        $hydrator = new ObjectPropertyHydrator();
168
        $values = $hydrator->extract($record);
4712 efrain 169
        $values = $this->removeEmpty($values);
4689 efrain 170
 
171
        $insert = $this->sql->insert(self::_TABLE);
172
        $insert->values($values);
173
 
174
 
175
        $result = $this->executeInsert($insert);
176
        if ($result) {
177
            $record->id = $this->lastInsertId;
178
        }
179
 
180
        return $result;
181
    }
182
 
183
    /**
184
     *
185
     * @param MyCoachCategory $record
186
     * @return boolean
187
     */
188
    public function update($record) {
189
        $hydrator = new ObjectPropertyHydrator();
190
        $values = $hydrator->extract($record);
4712 efrain 191
        $values = $this->removeEmpty($values);
4689 efrain 192
 
193
        $update = $this->sql->update(self::_TABLE);
194
        $update->set($values);
195
        $update->where->equalTo('id', $record->id);
196
 
197
        return $this->executeUpdate($update);
198
    }
199
 
200
    /**
201
     *
202
     * @param int $company_id
203
     * @param string $search
204
     * @param int $page
205
     * @param int $records_per_page
206
     * @param string $order_field
207
     * @param string $order_direction
208
     * @return Paginator
209
     */
210
    public function fetchAllDataTable($company_id, $search, $page = 1,   $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
211
    {
212
        $prototype = new MyCoachCategory();
213
        $select = $this->sql->select(self::_TABLE);
214
        $select->where->equalTo('company_id', $company_id);
215
 
216
 
217
        if($search) {
218
            $select->where->like('name', '%' . $search . '%');
219
        }
220
 
221
 
4712 efrain 222
 
4689 efrain 223
        $select->order($order_field . ' ' . $order_direction);
224
 
4712 efrain 225
        //echo $select->getSqlString($this->adapter->platform);
226
 
4689 efrain 227
        $hydrator   = new ObjectPropertyHydrator();
228
        $resultset  = new HydratingResultSet($hydrator, $prototype);
229
 
230
        $adapter = new DbSelect($select, $this->sql, $resultset);
231
        $paginator = new Paginator($adapter);
232
        $paginator->setItemCountPerPage($records_per_page);
233
        $paginator->setCurrentPageNumber($page);
234
 
235
 
236
        return $paginator;
237
    }
238
 
239
}