Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1308 eleazar 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\SurveyForm;
9
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10
use Laminas\Paginator\Paginator;
11
use Laminas\Db\ResultSet\HydratingResultSet;
12
use Laminas\Paginator\Adapter\DbSelect;
13
 
14
 
15
class SurveyFormMapper extends MapperCommon
16
{
7300 efrain 17
    const _TABLE = 'tbl_survey_forms';
1308 eleazar 18
 
19
    /**
20
     *
21
     * @var SurveyFormMapper
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 SurveyFormMapper
38
     */
39
    public static function getInstance($adapter)
40
    {
41
        if(self::$_instance == null) {
42
            self::$_instance = new SurveyFormMapper($adapter);
43
        }
44
        return self::$_instance;
45
    }
46
 
47
    /**
48
     *
49
     * @param int $id
50
     * @return SurveyForm
51
     */
52
    public function fetchOne($id)
53
    {
54
        $prototype = new SurveyForm();
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
     *
65
     * @param int $uuid
66
     * @return SurveyForm
67
     */
68
    public function fetchOneByUuid($uuid)
69
    {
70
        $prototype = new SurveyForm();
71
        $select = $this->sql->select(self::_TABLE);
72
        $select->where->equalTo('uuid', $uuid);
73
 
74
        return $this->executeFetchOneObject($select, $prototype);
75
    }
7300 efrain 76
 
77
 
78
    /**
79
     *
80
     * @param int $company_id
81
     * @return SurveyForm
82
     */
83
    public function fetchAllActiveNormalByCompanyId($company_id)
84
    {
85
        $prototype = new SurveyForm();
86
 
87
        $select = $this->sql->select(self::_TABLE);
88
        $select->where->equalTo('company_id', $company_id);
89
        $select->where->equalTo('type', SurveyForm::TYPE_NORMAL);
7328 efrain 90
        $select->where->equalTo('status', SurveyForm::STATUS_ACTIVE);
7300 efrain 91
        $select->order('name');
92
 
93
        return $this->executeFetchAllObject($select, $prototype);
94
    }
95
 
96
 
97
 
98
    /**
99
     *
100
     * @param int $company_id
101
     * @return SurveyForm
102
     */
103
    public function fetchAllActiveOrganizationalClimateByCompanyId($company_id)
104
    {
105
        $prototype = new SurveyForm();
106
 
107
        $select = $this->sql->select(self::_TABLE);
108
        $select->where->equalTo('company_id', $company_id);
109
        $select->where->equalTo('type', SurveyForm::TYPE_ORGANIZATIONAL_CLIMATE);
7328 efrain 110
        $select->where->equalTo('status', SurveyForm::STATUS_ACTIVE);
7300 efrain 111
        $select->order('name');
112
 
113
        return $this->executeFetchAllObject($select, $prototype);
114
    }
1308 eleazar 115
 
116
 
117
    /**
118
     *
119
     * @param int $company_id
120
     * @return SurveyForm
121
     */
122
    public function fetchAllByCompanyId($company_id)
123
    {
124
        $prototype = new SurveyForm();
125
 
126
        $select = $this->sql->select(self::_TABLE);
127
        $select->where->equalTo('company_id', $company_id);
128
        $select->order('name');
129
 
130
        return $this->executeFetchAllObject($select, $prototype);
131
    }
132
 
133
 
134
    /**
135
     *
3471 efrain 136
     * @param SurveyForm $form
1308 eleazar 137
     * @return boolean
138
     */
139
    public function insert($form)
140
    {
141
        $hydrator = new ObjectPropertyHydrator();
142
        $values = $hydrator->extract($form);
143
        $values = $this->removeEmpty($values);
144
 
145
        $insert = $this->sql->insert(self::_TABLE);
146
        $insert->values($values);
147
 
1370 eleazar 148
        //echo $insert->getSqlString($this->adapter->platform); exit;
1317 eleazar 149
 
1308 eleazar 150
        $result = $this->executeInsert($insert);
151
        if($result) {
152
            $form->id = $this->lastInsertId;
153
        }
154
        return $result;
155
    }
156
 
157
    /**
158
     *
3471 efrain 159
     * @param SurveyForm $form
1308 eleazar 160
     * @return boolean
161
     */
162
    public function update($form)
163
    {
164
        $hydrator = new ObjectPropertyHydrator();
165
        $values = $hydrator->extract($form);
166
        $values = $this->removeEmpty($values);
167
 
168
        $update = $this->sql->update(self::_TABLE);
169
        $update->set($values);
170
        $update->where->equalTo('id', $form->id);
171
 
172
        return $this->executeUpdate($update);
173
    }
174
 
175
    /**
176
     *
177
     * @param int $form_id
178
     * @return boolean
179
     */
180
    public function delete($form_id)
181
    {
182
        $delete = $this->sql->delete(self::_TABLE);
183
        $delete->where->equalTo('id', $form_id);
184
 
185
        return $this->executeDelete($delete);
186
    }
187
 
188
 
189
    /**
190
     *
191
     * @param int $companyId
192
     * @param string $search
193
     * @param int $page
194
     * @param int $records_per_page
195
     * @param string $order_field
196
     * @param string $order_direction
197
     * @return Paginator
198
     */
7300 efrain 199
    public function fetchAllDataTableNormalByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
1308 eleazar 200
    {
201
        $prototype = new SurveyForm();
202
        $select = $this->sql->select(self::_TABLE);
203
        $select->where->equalTo('company_id', $companyId);
7300 efrain 204
        $select->where->equalTo('type', SurveyForm::TYPE_NORMAL);
1308 eleazar 205
 
206
        if($search) {
207
            $select->where->like('name', '%' . $search . '%');
208
        }
209
        $select->order($order_field . ' ' . $order_direction);
210
 
211
        //echo $select->getSqlString($this->adapter->platform); exit;
212
 
213
        $hydrator   = new ObjectPropertyHydrator();
214
        $resultset  = new HydratingResultSet($hydrator, $prototype);
215
 
216
        $adapter = new DbSelect($select, $this->sql, $resultset);
217
        $paginator = new Paginator($adapter);
218
        $paginator->setItemCountPerPage($records_per_page);
219
        $paginator->setCurrentPageNumber($page);
220
 
221
 
222
        return $paginator;
223
    }
7300 efrain 224
 
225
 
226
    /**
227
     *
228
     * @param int $companyId
229
     * @param string $search
230
     * @param int $page
231
     * @param int $records_per_page
232
     * @param string $order_field
233
     * @param string $order_direction
234
     * @return Paginator
235
     */
236
    public function fetchAllDataTableOrganizationClimateByCompanyId($companyId, $search, $page = 1, $records_per_page = 10, $order_field= 'name', $order_direction = 'ASC')
237
    {
238
        $prototype = new SurveyForm();
239
        $select = $this->sql->select(self::_TABLE);
240
        $select->where->equalTo('company_id', $companyId);
241
        $select->where->equalTo('type', SurveyForm::TYPE_ORGANIZATIONAL_CLIMATE);
242
 
243
        if($search) {
244
            $select->where->like('name', '%' . $search . '%');
245
        }
246
        $select->order($order_field . ' ' . $order_direction);
247
 
248
        //echo $select->getSqlString($this->adapter->platform); exit;
249
 
250
        $hydrator   = new ObjectPropertyHydrator();
251
        $resultset  = new HydratingResultSet($hydrator, $prototype);
252
 
253
        $adapter = new DbSelect($select, $this->sql, $resultset);
254
        $paginator = new Paginator($adapter);
255
        $paginator->setItemCountPerPage($records_per_page);
256
        $paginator->setCurrentPageNumber($page);
257
 
258
 
259
        return $paginator;
260
    }
1308 eleazar 261
 
262
 
263
}