Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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