Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

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