Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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