Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6056 | Ir a la última revisión | | 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);
80
        $select->group('reaction');
81
 
82
        return $this->executeFetchAllArray($select);
83
    }
5765 efrain 84
 
6521 efrain 85
    /**
86
     *
87
     * @param int $my_coach_answer_id
88
     * @return array
89
     */
90
    public function fetchCountByMyCoachAnswerId($my_coach_answer_id)
91
    {
92
        $select = $this->sql->select(self::_TABLE);
93
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
94
        $select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
95
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
96
        $select->group('reaction');
97
 
98
        return $this->executeFetchAllArray($select);
99
    }
6056 efrain 100
 
6521 efrain 101
 
5765 efrain 102
    /**
103
     *
6056 efrain 104
     * @param int $knowledge_area_id
105
     * @return array
106
     */
6521 efrain 107
    public function fetchCountByKnowledgeAreaId($knowledge_area_id)
6056 efrain 108
    {
109
        $select = $this->sql->select(self::_TABLE);
110
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
111
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
6521 efrain 112
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
6056 efrain 113
        $select->group('reaction');
114
 
115
        return $this->executeFetchAllArray($select);
116
    }
6521 efrain 117
 
6056 efrain 118
 
119
 
6521 efrain 120
 
6056 efrain 121
    /**
122
     *
5765 efrain 123
     * @param int $post_id
124
     * @return array
125
     */
6521 efrain 126
    public function fetchCountByPostId($post_id)
5765 efrain 127
    {
128
        $select = $this->sql->select(self::_TABLE);
129
        $select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
130
        $select->where->equalTo('post_id', $post_id);
6521 efrain 131
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
5765 efrain 132
        $select->group('reaction');
133
 
134
        return $this->executeFetchAllArray($select);
135
    }
136
 
137
    /**
138
     *
139
     * @param int $feed_id
140
     * @param int $user_id
141
     * @return ContentReaction
142
     */
143
    public function fetchOneByFeedIdAndUserId($feed_id, $user_id)
144
    {
145
        $select = $this->sql->select(self::_TABLE);
146
        $select->where->equalTo('feed_id', $feed_id);
147
        $select->where->equalTo('user_id', $user_id);
148
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
149
 
150
        $prototype = new ContentReaction();
151
        return $this->executeFetchOneObject($select, $prototype);
152
    }
153
 
154
 
155
    /**
156
     *
157
     * @param int $post_id
158
     * @param int $user_id
159
     * @return ContentReaction
160
     */
161
    public function fetchOneByPostIdAndUserId($post_id, $user_id)
162
    {
163
        $select = $this->sql->select(self::_TABLE);
164
        $select->where->equalTo('post_id', $post_id);
165
        $select->where->equalTo('user_id', $user_id);
166
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
167
 
168
        $prototype = new ContentReaction();
169
        return $this->executeFetchOneObject($select, $prototype);
170
    }
171
 
172
    /**
6056 efrain 173
     *
6521 efrain 174
     * @param int $my_coach_answer_id
175
     * @param int $user_id
176
     * @return ContentReaction
177
     */
178
    public function fetchOneByMyCoachAnswerIdAndUserId($my_coach_answer_id, $user_id)
179
    {
180
        $select = $this->sql->select(self::_TABLE);
181
        $select->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
182
        $select->where->equalTo('user_id', $user_id);
183
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
184
 
185
        $prototype = new ContentReaction();
186
        return $this->executeFetchOneObject($select, $prototype);
187
    }
188
 
189
    /**
190
     *
6056 efrain 191
     * @param int $knowledge_area_id
192
     * @param int $user_id
193
     * @return ContentReaction
194
     */
195
    public function fetchOneByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id)
196
    {
197
        $select = $this->sql->select(self::_TABLE);
198
        $select->where->equalTo('knowledge_area_id', $knowledge_area_id);
199
        $select->where->equalTo('user_id', $user_id);
200
        $select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
201
 
202
        $prototype = new ContentReaction();
203
        return $this->executeFetchOneObject($select, $prototype);
204
    }
205
 
6521 efrain 206
 
6056 efrain 207
    /**
5765 efrain 208
     *
209
     * @param int $feed_id
210
     * @param int $user_id
211
     * @return boolean
212
     */
213
    public function deleteByFeedIdAndUserId($feed_id, $user_id)
214
    {
215
        $delete = $this->sql->delete(self::_TABLE);
216
        $delete->where->equalTo('feed_id', $feed_id);
217
        $delete->where->equalTo('user_id', $user_id);
218
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
219
 
220
        return $this->executeDelete($delete);
221
    }
222
 
6056 efrain 223
    /**
224
     *
225
     * @param int $knowledge_area_id
226
     * @param int $user_id
227
     * @return boolean
228
     */
229
    public function deleteByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id)
230
    {
231
        $delete = $this->sql->delete(self::_TABLE);
232
        $delete->where->equalTo('knowledge_area_id', $knowledge_area_id);
233
        $delete->where->equalTo('user_id', $user_id);
234
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
235
 
236
        return $this->executeDelete($delete);
237
    }
5765 efrain 238
 
6521 efrain 239
    /**
240
     *
241
     * @param int $my_coach_answer_id
242
     * @param int $user_id
243
     * @return boolean
244
     */
245
    public function deleteByByMyCoachAnswerId($my_coach_answer_id, $user_id)
246
    {
247
        $delete = $this->sql->delete(self::_TABLE);
248
        $delete->where->equalTo('my_coach_answer_id', $my_coach_answer_id);
249
        $delete->where->equalTo('user_id', $user_id);
250
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_MY_COACH);
251
 
252
        return $this->executeDelete($delete);
253
    }
6056 efrain 254
 
6521 efrain 255
 
256
 
257
 
258
 
5765 efrain 259
    /**
260
     *
261
     * @param int $post_id
262
     * @param int $user_id
263
     * @return boolean
264
     */
265
    public function deleteByPostIdAndUserId($post_id, $user_id)
266
    {
267
        $delete = $this->sql->delete(self::_TABLE);
268
        $delete->where->equalTo('post_id', $post_id);
269
        $delete->where->equalTo('user_id', $user_id);
270
        $delete->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
271
 
272
        return $this->executeDelete($delete);
273
    }
274
 
275
    /**
276
     *
277
     * @param ContentReaction $contentReaction
278
     * @return boolean
279
     */
280
    public function insert($contentReaction)
281
    {
282
        $hydrator = new ObjectPropertyHydrator();
283
        $values = $hydrator->extract($contentReaction);
6521 efrain 284
        $values = $this->removeEmpty($values);
5765 efrain 285
 
286
        $insert = $this->sql->insert(self::_TABLE);
287
        $insert->values($values);
288
 
289
        $response = $this->executeInsert($insert);
290
        if($response) {
291
            $contentReaction->id = $this->getLastInsertId();
292
        }
293
 
294
        return $response;
295
    }
5775 efrain 296
 
297
 
298
    /**
299
     *
300
     * @param ContentReaction $contentReaction
301
     * @return boolean
302
     */
303
    public function update($contentReaction)
304
    {
305
        $hydrator = new ObjectPropertyHydrator();
306
        $values = $hydrator->extract($contentReaction);
6521 efrain 307
        $values = $this->removeEmpty($values);
5775 efrain 308
 
309
        $update = $this->sql->update(self::_TABLE);
310
        $update->set($values);
311
        $update->where->equalTo('id', $contentReaction->id);
312
 
313
        return  $this->executeUpdate($update);
314
 
315
    }
5765 efrain 316
}