| 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 |
*/
|
|
|
53 |
public function fetchCountContentReactionsByFeedId($feed_id)
|
|
|
54 |
{
|
|
|
55 |
$select = $this->sql->select(self::_TABLE);
|
|
|
56 |
$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
|
|
|
57 |
$select->where->equalTo('feed_id', $feed_id);
|
|
|
58 |
$select->group('reaction');
|
|
|
59 |
|
|
|
60 |
return $this->executeFetchAllArray($select);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
|
| 6056 |
efrain |
64 |
|
| 5765 |
efrain |
65 |
/**
|
|
|
66 |
*
|
| 6056 |
efrain |
67 |
* @param int $knowledge_area_id
|
|
|
68 |
* @return array
|
|
|
69 |
*/
|
|
|
70 |
public function fetchCountContentReactionsByKnowledgeAreaId($knowledge_area_id)
|
|
|
71 |
{
|
|
|
72 |
$select = $this->sql->select(self::_TABLE);
|
|
|
73 |
$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
|
|
|
74 |
$select->where->equalTo('knowledge_area_id', $knowledge_area_id);
|
|
|
75 |
$select->group('reaction');
|
|
|
76 |
|
|
|
77 |
return $this->executeFetchAllArray($select);
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
/**
|
|
|
82 |
*
|
| 5765 |
efrain |
83 |
* @param int $post_id
|
|
|
84 |
* @return array
|
|
|
85 |
*/
|
|
|
86 |
public function fetchCountContentReactionsByPostId($post_id)
|
|
|
87 |
{
|
|
|
88 |
$select = $this->sql->select(self::_TABLE);
|
|
|
89 |
$select->columns(['total' => new Expression('COUNT(*)'), 'reaction']);
|
|
|
90 |
$select->where->equalTo('post_id', $post_id);
|
|
|
91 |
$select->group('reaction');
|
|
|
92 |
|
|
|
93 |
return $this->executeFetchAllArray($select);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
/**
|
|
|
97 |
*
|
|
|
98 |
* @param int $feed_id
|
|
|
99 |
* @param int $user_id
|
|
|
100 |
* @return ContentReaction
|
|
|
101 |
*/
|
|
|
102 |
public function fetchOneByFeedIdAndUserId($feed_id, $user_id)
|
|
|
103 |
{
|
|
|
104 |
$select = $this->sql->select(self::_TABLE);
|
|
|
105 |
$select->where->equalTo('feed_id', $feed_id);
|
|
|
106 |
$select->where->equalTo('user_id', $user_id);
|
|
|
107 |
$select->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
|
|
|
108 |
|
|
|
109 |
$prototype = new ContentReaction();
|
|
|
110 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
/**
|
|
|
115 |
*
|
|
|
116 |
* @param int $post_id
|
|
|
117 |
* @param int $user_id
|
|
|
118 |
* @return ContentReaction
|
|
|
119 |
*/
|
|
|
120 |
public function fetchOneByPostIdAndUserId($post_id, $user_id)
|
|
|
121 |
{
|
|
|
122 |
$select = $this->sql->select(self::_TABLE);
|
|
|
123 |
$select->where->equalTo('post_id', $post_id);
|
|
|
124 |
$select->where->equalTo('user_id', $user_id);
|
|
|
125 |
$select->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
|
|
|
126 |
|
|
|
127 |
$prototype = new ContentReaction();
|
|
|
128 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
/**
|
| 6056 |
efrain |
132 |
*
|
|
|
133 |
* @param int $knowledge_area_id
|
|
|
134 |
* @param int $user_id
|
|
|
135 |
* @return ContentReaction
|
|
|
136 |
*/
|
|
|
137 |
public function fetchOneByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id)
|
|
|
138 |
{
|
|
|
139 |
$select = $this->sql->select(self::_TABLE);
|
|
|
140 |
$select->where->equalTo('knowledge_area_id', $knowledge_area_id);
|
|
|
141 |
$select->where->equalTo('user_id', $user_id);
|
|
|
142 |
$select->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
|
|
|
143 |
|
|
|
144 |
$prototype = new ContentReaction();
|
|
|
145 |
return $this->executeFetchOneObject($select, $prototype);
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/**
|
| 5765 |
efrain |
149 |
*
|
|
|
150 |
* @param int $feed_id
|
|
|
151 |
* @param int $user_id
|
|
|
152 |
* @return boolean
|
|
|
153 |
*/
|
|
|
154 |
public function deleteByFeedIdAndUserId($feed_id, $user_id)
|
|
|
155 |
{
|
|
|
156 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
157 |
$delete->where->equalTo('feed_id', $feed_id);
|
|
|
158 |
$delete->where->equalTo('user_id', $user_id);
|
|
|
159 |
$delete->where->equalTo('relational', ContentReaction::RELATIONAL_FEED);
|
|
|
160 |
|
|
|
161 |
return $this->executeDelete($delete);
|
|
|
162 |
}
|
|
|
163 |
|
| 6056 |
efrain |
164 |
/**
|
|
|
165 |
*
|
|
|
166 |
* @param int $knowledge_area_id
|
|
|
167 |
* @param int $user_id
|
|
|
168 |
* @return boolean
|
|
|
169 |
*/
|
|
|
170 |
public function deleteByKnowledgeAreaIdAndUserId($knowledge_area_id, $user_id)
|
|
|
171 |
{
|
|
|
172 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
173 |
$delete->where->equalTo('knowledge_area_id', $knowledge_area_id);
|
|
|
174 |
$delete->where->equalTo('user_id', $user_id);
|
|
|
175 |
$delete->where->equalTo('relational', ContentReaction::RELATIONAL_KNOWLEDGE_AREA);
|
|
|
176 |
|
|
|
177 |
return $this->executeDelete($delete);
|
|
|
178 |
}
|
| 5765 |
efrain |
179 |
|
| 6056 |
efrain |
180 |
|
| 5765 |
efrain |
181 |
/**
|
|
|
182 |
*
|
|
|
183 |
* @param int $post_id
|
|
|
184 |
* @param int $user_id
|
|
|
185 |
* @return boolean
|
|
|
186 |
*/
|
|
|
187 |
public function deleteByPostIdAndUserId($post_id, $user_id)
|
|
|
188 |
{
|
|
|
189 |
$delete = $this->sql->delete(self::_TABLE);
|
|
|
190 |
$delete->where->equalTo('post_id', $post_id);
|
|
|
191 |
$delete->where->equalTo('user_id', $user_id);
|
|
|
192 |
$delete->where->equalTo('relational', ContentReaction::RELATIONAL_POST);
|
|
|
193 |
|
|
|
194 |
return $this->executeDelete($delete);
|
|
|
195 |
}
|
|
|
196 |
|
|
|
197 |
/**
|
|
|
198 |
*
|
|
|
199 |
* @param ContentReaction $contentReaction
|
|
|
200 |
* @return boolean
|
|
|
201 |
*/
|
|
|
202 |
public function insert($contentReaction)
|
|
|
203 |
{
|
|
|
204 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
205 |
$values = $hydrator->extract($contentReaction);
|
|
|
206 |
|
|
|
207 |
$insert = $this->sql->insert(self::_TABLE);
|
|
|
208 |
$insert->values($values);
|
|
|
209 |
|
|
|
210 |
$response = $this->executeInsert($insert);
|
|
|
211 |
if($response) {
|
|
|
212 |
$contentReaction->id = $this->getLastInsertId();
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
return $response;
|
|
|
216 |
}
|
| 5775 |
efrain |
217 |
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
*
|
|
|
221 |
* @param ContentReaction $contentReaction
|
|
|
222 |
* @return boolean
|
|
|
223 |
*/
|
|
|
224 |
public function update($contentReaction)
|
|
|
225 |
{
|
|
|
226 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
227 |
$values = $hydrator->extract($contentReaction);
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
$update = $this->sql->update(self::_TABLE);
|
|
|
231 |
$update->set($values);
|
|
|
232 |
$update->where->equalTo('id', $contentReaction->id);
|
|
|
233 |
|
|
|
234 |
return $this->executeUpdate($update);
|
|
|
235 |
|
|
|
236 |
}
|
| 5765 |
efrain |
237 |
}
|