Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5935 | Rev 6056 | 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
    }
96
 
6001 efrain 97
 
5935 efrain 98
    /**
99
     *
6001 efrain 100
     * @param int $network_id
101
     * @return KnowledgeAreaCategory[]
102
     */
103
    public function fetchAllPublicByNetworkId($network_id)
104
    {
105
 
106
        $select = $this->sql->select(self::_TABLE);
107
        $select->where->equalTo('network_id', $network_id);
108
        $select->order('name DESC');
109
 
110
        $prototype = new KnowledgeAreaCategory();
111
        return $this->executeFetchAllObject($select, $prototype);
112
    }
113
 
114
    /**
115
     *
116
     * @param array $ids
117
     * @return KnowledgeAreaCategory[]
118
     */
119
    public function fetchAllByIds($ids)
120
    {
121
 
122
        $select = $this->sql->select(self::_TABLE);
123
        $select->where->in('id', $ids);
124
        $select->order('name DESC');
125
 
126
        $prototype = new KnowledgeAreaCategory();
127
        return $this->executeFetchAllObject($select, $prototype);
128
    }
129
 
130
    /**
131
     *
5935 efrain 132
     * @param int $id
133
     * @return boolean
134
     */
135
    public function delete($id)
136
    {
137
        $delete = $this->sql->delete(self::_TABLE);
138
        $delete->where->equalTo('id', $id);
139
 
140
        return $this->executeDelete($delete);
141
    }
142
 
143
 
144
    /**
145
     *
146
     * @param KnowledgeAreaCategory $record
147
     * @return boolean
148
     */
149
    public function insert($record) {
150
        $hydrator = new ObjectPropertyHydrator();
151
        $values = $hydrator->extract($record);
152
        $values = $this->removeEmpty($values);
153
 
154
        $insert = $this->sql->insert(self::_TABLE);
155
        $insert->values($values);
156
 
157
 
158
        $result = $this->executeInsert($insert);
159
        if ($result) {
160
            $record->id = $this->lastInsertId;
161
        }
162
 
163
        return $result;
164
    }
165
 
166
    /**
167
     *
168
     * @param KnowledgeAreaCategory $record
169
     * @return boolean
170
     */
171
    public function update($record) {
172
        $hydrator = new ObjectPropertyHydrator();
173
        $values = $hydrator->extract($record);
174
        $values = $this->removeEmpty($values);
175
 
176
        $update = $this->sql->update(self::_TABLE);
177
        $update->set($values);
178
        $update->where->equalTo('id', $record->id);
179
 
180
        return $this->executeUpdate($update);
181
    }
182
 
183
    /**
184
     *
185
     * @param int $company_id
186
     * @param string $search
187
     * @param int $page
188
     * @param int $records_per_page
189
     * @param string $order_field
190
     * @param string $order_direction
191
     * @return Paginator
192
     */
193
    public function fetchAllDataTable($company_id, $search, $page = 1,   $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
194
    {
195
        $prototype = new KnowledgeAreaCategory();
196
        $select = $this->sql->select(self::_TABLE);
197
        $select->where->equalTo('company_id', $company_id);
198
 
199
 
200
        if($search) {
201
            $select->where->like('name', '%' . $search . '%');
202
        }
203
 
204
 
205
 
206
        $select->order($order_field . ' ' . $order_direction);
207
 
208
        //echo $select->getSqlString($this->adapter->platform);
209
 
210
        $hydrator   = new ObjectPropertyHydrator();
211
        $resultset  = new HydratingResultSet($hydrator, $prototype);
212
 
213
        $adapter = new DbSelect($select, $this->sql, $resultset);
214
        $paginator = new Paginator($adapter);
215
        $paginator->setItemCountPerPage($records_per_page);
216
        $paginator->setCurrentPageNumber($page);
217
 
218
 
219
        return $paginator;
220
    }
221
 
222
}