Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
5765 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Mapper;
6
 
7
use LeadersLinked\Model\ContentReaction;
8
use LeadersLinked\Mapper\Common\MapperCommon;
9
use Laminas\Db\Adapter\AdapterInterface;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\Db\Sql\Expression;
12
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
13
 
14
 
15
class ContentReactionMapper extends MapperCommon
16
{
17
    const _TABLE = 'tbl_content_reactions';
18
 
19
 
20
    /**
21
     *
22
     * @var ContentReactionMapper
23
     */
24
    private static $_instance;
25
 
26
    /**
27
     *
28
     * @param AdapterInterface $adapter
29
     */
30
    private function __construct($adapter)
31
    {
32
        parent::__construct($adapter);
33
    }
34
 
35
    /**
36
     *
37
     * @param AdapterInterface $adapter
38
     * @return \LeadersLinked\Mapper\ContentReactionMapper
39
     */
40
    public static function getInstance($adapter)
41
    {
42
        if(self::$_instance == null) {
43
            self::$_instance = new ContentReactionMapper($adapter);
44
        }
45
        return self::$_instance;
46
    }
47
 
48
    /**
49
     *
50
     * @param int $feed_id
51
     * @return array
52
     */
6521 efrain 53
    public function fetchCountByFeedId($feed_id)
5765 efrain 54
    {
55
        $select = $this->sql->select(self::_TABLE);
56
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
57
        $select->where->equalTo('feed_id', $feed_id);
6521 efrain 58
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
5765 efrain 59
        $select->group('reaction');
60
 
61
        return $this->executeFetchAllArray($select);
62
    }
63
 
6521 efrain 64
    /**
65
     *
66
     * @param int $my_coach_question_id
67
     * @return array
68
     */
69
    public function fetchCountByMyCoachQuestionId($my_coach_question_id)
70
    {
71
        $selectIn = $this->sql->select(MyCoachAnswerMapper::_TABLE);
72
        $selectIn->columns(['id']);
73
        $selectIn->where->equalTo('question_id', $my_coach_question_id);
74
 
75
 
76
        $select = $this->sql->select(self::_TABLE);
77
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
78
        $select->where->in('my_coach_answer_id', $selectIn);
79
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
6547 efrain 80
        //$select->group('reaction');
6521 efrain 81
 
6547 efrain 82
        $record = $this->executeFetchOneArray($select);
83
        return $record['total'];
6521 efrain 84
    }
5765 efrain 85
 
6521 efrain 86
    /**
87
     *
88
     * @param int $my_coach_answer_id
89
     * @return array
90
     */
91
    public function fetchCountByMyCoachAnswerId($my_coach_answer_id)
92
    {
93
        $select = $this->sql->select(self::_TABLE);
94
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
95
        $select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
96
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
6547 efrain 97
 
98
        $record = $this->executeFetchOneArray($select);
99
        return $record['total'];
100
    }
101
 
102
    /*
103
    public function fetchCountByMyCoachAnswerId($my_coach_answer_id)
104
    {
105
        $select = $this->sql->select(self::_TABLE);
106
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
107
        $select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
108
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
6521 efrain 109
        $select->group('reaction');
110
 
111
        return $this->executeFetchAllArray($select);
112
    }
6547 efrain 113
     */
6056 efrain 114
 
6521 efrain 115
 
5765 efrain 116
    /**
117
     *
6056 efrain 118
     * @param int $knowledge_area_id
119
     * @return array
120
     */
6521 efrain 121
    public function fetchCountByKnowledgeAreaId($knowledge_area_id)
6056 efrain 122
    {
123
        $select = $this->sql->select(self::_TABLE);
124
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
125
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
6521 efrain 126
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
6056 efrain 127
        $select->group('reaction');
128
 
129
        return $this->executeFetchAllArray($select);
130
    }
6521 efrain 131
 
6056 efrain 132
 
133
 
6521 efrain 134
 
6056 efrain 135
    /**
136
     *
5765 efrain 137
     * @param int $post_id
138
     * @return array
139
     */
6521 efrain 140
    public function fetchCountByPostId($post_id)
5765 efrain 141
    {
142
        $select = $this->sql->select(self::_TABLE);
143
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
144
        $select->where->equalTo('post_id', $post_id);
6521 efrain 145
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
5765 efrain 146
        $select->group('reaction');
147
 
148
        return $this->executeFetchAllArray($select);
149
    }
150
 
151
    /**
152
     *
153
     * @param int $feed_id
154
     * @param int $user_id
155
     * @return ContentReaction
156
     */
157
    public function fetchOneByFeedIdAndUserId($feed_id, $user_id)
158
    {
159
        $select = $this->sql->select(self::_TABLE);
160
        $select->where->equalTo('feed_id', $feed_id);
161
        $select->where->equalTo('user_id', $user_id);
162
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
163
 
164
        $prototype = new ContentReaction();
165
        return $this->executeFetchOneObject($select, $prototype);
166
    }
167
 
168
 
169
    /**
170
     *
171
     * @param int $post_id
172
     * @param int $user_id
173
     * @return ContentReaction
174
     */
175
    public function fetchOneByPostIdAndUserId($post_id, $user_id)
176
    {
177
        $select = $this->sql->select(self::_TABLE);
178
        $select->where->equalTo('post_id', $post_id);
179
        $select->where->equalTo('user_id', $user_id);
180
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
181
 
182
        $prototype = new ContentReaction();
183
        return $this->executeFetchOneObject($select, $prototype);
184
    }
185
 
186
    /**
6056 efrain 187
     *
6521 efrain 188
     * @param int $my_coach_answer_id
189
     * @param int $user_id
190
     * @return ContentReaction
191
     */
192
    public function fetchOneByMyCoachAnswerIdAndUserId($my_coach_answer_id, $user_id)
193
    {
194
        $select = $this->sql->select(self::_TABLE);
195
        $select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
196
        $select->where->equalTo('user_id', $user_id);
197
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
198
 
199
        $prototype = new ContentReaction();
200
        return $this->executeFetchOneObject($select, $prototype);
201
    }
202
 
203
    /**
204
     *
6056 efrain 205
     * @param int $knowledge_area_id
206
     * @param int $user_id
207
     * @return ContentReaction
208
     */
209
    public function fetchOneByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id)
210
    {
211
        $select = $this->sql->select(self::_TABLE);
212
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
213
        $select->where->equalTo('user_id', $user_id);
214
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
215
 
216
        $prototype = new ContentReaction();
217
        return $this->executeFetchOneObject($select, $prototype);
218
    }
219
 
6521 efrain 220
 
6056 efrain 221
    /**
5765 efrain 222
     *
223
     * @param int $feed_id
224
     * @param int $user_id
225
     * @return boolean
226
     */
227
    public function deleteByFeedIdAndUserId($feed_id, $user_id)
228
    {
229
        $delete = $this->sql->delete(self::_TABLE);
230
        $delete->where->equalTo('feed_id', $feed_id);
231
        $delete->where->equalTo('user_id', $user_id);
232
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
233
 
234
        return $this->executeDelete($delete);
235
    }
236
 
6056 efrain 237
    /**
238
     *
239
     * @param int $knowledge_area_id
240
     * @param int $user_id
241
     * @return boolean
242
     */
243
    public function deleteByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id)
244
    {
245
        $delete = $this->sql->delete(self::_TABLE);
246
        $delete->where->equalTo('knowledge_area_id', $knowledge_area_id);
247
        $delete->where->equalTo('user_id', $user_id);
248
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
249
 
250
        return $this->executeDelete($delete);
251
    }
5765 efrain 252
 
6521 efrain 253
    /**
254
     *
255
     * @param int $my_coach_answer_id
256
     * @param int $user_id
257
     * @return boolean
258
     */
259
    public function deleteByByMyCoachAnswerId($my_coach_answer_id, $user_id)
260
    {
261
        $delete = $this->sql->delete(self::_TABLE);
262
        $delete->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
263
        $delete->where->equalTo('user_id', $user_id);
264
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
265
 
266
        return $this->executeDelete($delete);
267
    }
6056 efrain 268
 
6521 efrain 269
 
270
 
271
 
272
 
5765 efrain 273
    /**
274
     *
275
     * @param int $post_id
276
     * @param int $user_id
277
     * @return boolean
278
     */
279
    public function deleteByPostIdAndUserId($post_id, $user_id)
280
    {
281
        $delete = $this->sql->delete(self::_TABLE);
282
        $delete->where->equalTo('post_id', $post_id);
283
        $delete->where->equalTo('user_id', $user_id);
284
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
285
 
286
        return $this->executeDelete($delete);
287
    }
288
 
289
    /**
290
     *
291
     * @param ContentReaction $contentReaction
292
     * @return boolean
293
     */
294
    public function insert($contentReaction)
295
    {
296
        $hydrator = new ObjectPropertyHydrator();
297
        $values = $hydrator->extract($contentReaction);
6521 efrain 298
        $values = $this->removeEmpty($values);
5765 efrain 299
 
300
        $insert = $this->sql->insert(self::_TABLE);
301
        $insert->values($values);
302
 
303
        $response = $this->executeInsert($insert);
304
        if($response) {
305
            $contentReaction->id = $this->getLastInsertId();
306
        }
307
 
308
        return $response;
309
    }
5775 efrain 310
 
311
 
312
    /**
313
     *
314
     * @param ContentReaction $contentReaction
315
     * @return boolean
316
     */
317
    public function update($contentReaction)
318
    {
319
        $hydrator = new ObjectPropertyHydrator();
320
        $values = $hydrator->extract($contentReaction);
6521 efrain 321
        $values = $this->removeEmpty($values);
5775 efrain 322
 
323
        $update = $this->sql->update(self::_TABLE);
324
        $update->set($values);
325
        $update->where->equalTo('id', $contentReaction->id);
326
 
327
        return  $this->executeUpdate($update);
328
 
329
    }
5765 efrain 330
}