Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6388 | | 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
     *
6521 efrain 66
     * @param int $id
67
     * @param int $network_id
68
     * @return MyCoachCategory
69
     */
70
    public function fetchOneAndNetworkId($id, $network_id)
71
    {
72
 
73
        $select = $this->sql->select(self::_TABLE);
74
        $select->where->equalTo('id', $id);
75
        $select->where->equalTo('network_id', $network_id);
76
 
77
        $prototype = new MyCoachCategory();
78
        return $this->executeFetchOneObject($select, $prototype);
79
    }
80
 
81
 
82
    /**
83
     *
4689 efrain 84
     * @param string $uuid
85
     * @return MyCoachCategory
86
     */
87
    public function fetchOneByUuid($uuid)
88
    {
89
 
90
        $select = $this->sql->select(self::_TABLE);
91
        $select->where->equalTo('uuid', $uuid);
92
 
93
        $prototype = new MyCoachCategory();
94
        return $this->executeFetchOneObject($select, $prototype);
95
    }
96
 
97
 
6521 efrain 98
    /**
99
     *
100
     * @param string $uuid
101
     * @param int $network_id
102
     * @return MyCoachCategory
103
     */
104
    public function fetchOneByUuidAndNetworkId($uuid, $network_id)
105
    {
106
 
107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('uuid', $uuid);
109
        $select->where->equalTo('network_id', $network_id);
110
 
111
        $prototype = new MyCoachCategory();
112
        return $this->executeFetchOneObject($select, $prototype);
113
    }
4689 efrain 114
 
6521 efrain 115
 
116
 
4689 efrain 117
    /**
118
     *
119
     * @param int $company_id
120
     * @return MyCoachCategory[]
121
     */
122
    public function fetchAllByCompanyId($company_id)
123
    {
124
 
125
        $select = $this->sql->select(self::_TABLE);
126
        $select->where->equalTo('company_id', $company_id);
127
        $select->order('name DESC');
128
 
129
        $prototype = new MyCoachCategory();
130
        return $this->executeFetchAllObject($select, $prototype);
131
    }
132
 
133
    /**
134
     *
6388 efrain 135
     * @param int $network_id
136
     * @return MyCoachCategory[]
137
     */
138
    public function fetchAllByNetworkId($network_id)
139
    {
140
 
141
        $select = $this->sql->select(self::_TABLE);
142
        $select->where->equalTo('network_id', $network_id);
143
        $select->order('name DESC');
144
 
145
        $prototype = new MyCoachCategory();
146
        return $this->executeFetchAllObject($select, $prototype);
147
    }
148
 
149
 
150
    /**
151
     *
152
     * @param int $network_id
153
     * @return MyCoachCategory[]
154
     */
155
    public function fetchAllPublicByNetworkId($network_id)
156
    {
157
 
158
        $select = $this->sql->select(self::_TABLE);
159
        $select->where->equalTo('network_id', $network_id);
160
        $select->where->equalTo('privacy', MyCoachCategory::PRIVACY_PUBLIC);
161
        $select->order('name DESC');
162
 
163
        $prototype = new MyCoachCategory();
164
        return $this->executeFetchAllObject($select, $prototype);
165
    }
166
 
167
    /**
168
     *
169
     * @param array $ids
170
     * @return MyCoachCategory[]
171
     */
172
    public function fetchAllByIds($ids)
173
    {
174
 
175
        $select = $this->sql->select(self::_TABLE);
176
        $select->where->in('id', $ids);
177
        $select->order('name DESC');
178
 
179
        $prototype = new MyCoachCategory();
180
        return $this->executeFetchAllObject($select, $prototype);
181
    }
182
 
183
    /**
184
     *
4689 efrain 185
     * @param int $id
186
     * @return boolean
187
     */
188
    public function delete($id)
189
    {
190
        $delete = $this->sql->delete(self::_TABLE);
191
        $delete->where->equalTo('id', $id);
192
 
193
        return $this->executeDelete($delete);
194
    }
195
 
196
 
197
    /**
198
     *
199
     * @param MyCoachCategory $record
200
     * @return boolean
201
     */
202
    public function insert($record) {
203
        $hydrator = new ObjectPropertyHydrator();
204
        $values = $hydrator->extract($record);
4712 efrain 205
        $values = $this->removeEmpty($values);
4689 efrain 206
 
207
        $insert = $this->sql->insert(self::_TABLE);
208
        $insert->values($values);
209
 
210
 
211
        $result = $this->executeInsert($insert);
212
        if ($result) {
213
            $record->id = $this->lastInsertId;
214
        }
215
 
216
        return $result;
217
    }
218
 
219
    /**
220
     *
221
     * @param MyCoachCategory $record
222
     * @return boolean
223
     */
224
    public function update($record) {
225
        $hydrator = new ObjectPropertyHydrator();
226
        $values = $hydrator->extract($record);
4712 efrain 227
        $values = $this->removeEmpty($values);
4689 efrain 228
 
229
        $update = $this->sql->update(self::_TABLE);
230
        $update->set($values);
231
        $update->where->equalTo('id', $record->id);
232
 
233
        return $this->executeUpdate($update);
234
    }
235
 
236
    /**
237
     *
238
     * @param int $company_id
239
     * @param string $search
240
     * @param int $page
241
     * @param int $records_per_page
242
     * @param string $order_field
243
     * @param string $order_direction
244
     * @return Paginator
245
     */
246
    public function fetchAllDataTable($company_id, $search, $page = 1,   $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
247
    {
248
        $prototype = new MyCoachCategory();
249
        $select = $this->sql->select(self::_TABLE);
250
        $select->where->equalTo('company_id', $company_id);
251
 
252
 
253
        if($search) {
254
            $select->where->like('name', '%' . $search . '%');
255
        }
256
 
257
 
4712 efrain 258
 
4689 efrain 259
        $select->order($order_field . ' ' . $order_direction);
260
 
4712 efrain 261
        //echo $select->getSqlString($this->adapter->platform);
262
 
4689 efrain 263
        $hydrator   = new ObjectPropertyHydrator();
264
        $resultset  = new HydratingResultSet($hydrator, $prototype);
265
 
266
        $adapter = new DbSelect($select, $this->sql, $resultset);
267
        $paginator = new Paginator($adapter);
268
        $paginator->setItemCountPerPage($records_per_page);
269
        $paginator->setCurrentPageNumber($page);
270
 
271
 
272
        return $paginator;
273
    }
274
 
275
}