Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

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