Proyectos de Subversion LeadersLinked - Services

Rev

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

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