Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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