| 1 |
www |
1 |
<?php
|
| 16322 |
anderson |
2 |
|
|
|
3 |
|
| 1 |
www |
4 |
declare(strict_types=1);
|
|
|
5 |
|
|
|
6 |
namespace LeadersLinked\Controller;
|
|
|
7 |
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
| 16768 |
efrain |
9 |
|
| 1 |
www |
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Log\LoggerInterface;
|
|
|
12 |
use Laminas\View\Model\ViewModel;
|
|
|
13 |
use Laminas\View\Model\JsonModel;
|
|
|
14 |
|
|
|
15 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
16 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
| 17008 |
efrain |
17 |
use LeadersLinked\Form\Feed\CreateFeedForm;
|
|
|
18 |
use LeadersLinked\Form\Feed\CommentForm;
|
|
|
19 |
use LeadersLinked\Form\Feed\CommentAnswerForm;
|
| 1 |
www |
20 |
use LeadersLinked\Model\Comment;
|
|
|
21 |
use LeadersLinked\Mapper\CommentMapper;
|
|
|
22 |
use LeadersLinked\Mapper\FeedMapper;
|
|
|
23 |
use LeadersLinked\Model\Feed;
|
|
|
24 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
25 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
26 |
use LeadersLinked\Library\Image;
|
|
|
27 |
use LeadersLinked\Model\VideoConvert;
|
|
|
28 |
use LeadersLinked\Mapper\VideoConvertMapper;
|
|
|
29 |
|
| 16701 |
efrain |
30 |
use LeadersLinked\Mapper\FastSurveyMapper;
|
|
|
31 |
use LeadersLinked\Model\FastSurvey;
|
|
|
32 |
use LeadersLinked\Form\FastSurvey\FastSurveyForm;
|
| 17002 |
efrain |
33 |
use LeadersLinked\Library\Storage;
|
| 17008 |
efrain |
34 |
use LeadersLinked\Library\Functions;
|
| 7381 |
nelberth |
35 |
|
| 1 |
www |
36 |
class FeedController extends AbstractActionController
|
|
|
37 |
{
|
|
|
38 |
/**
|
|
|
39 |
*
|
| 16769 |
efrain |
40 |
* @var \Laminas\Db\Adapter\AdapterInterface
|
| 1 |
www |
41 |
*/
|
|
|
42 |
private $adapter;
|
| 16768 |
efrain |
43 |
|
| 1 |
www |
44 |
/**
|
|
|
45 |
*
|
| 16769 |
efrain |
46 |
* @var \LeadersLinked\Cache\CacheInterface
|
| 1 |
www |
47 |
*/
|
| 16769 |
efrain |
48 |
private $cache;
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
*
|
|
|
53 |
* @var \Laminas\Log\LoggerInterface
|
|
|
54 |
*/
|
| 1 |
www |
55 |
private $logger;
|
| 16768 |
efrain |
56 |
|
| 1 |
www |
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
* @var array
|
|
|
60 |
*/
|
|
|
61 |
private $config;
|
| 16768 |
efrain |
62 |
|
| 16769 |
efrain |
63 |
|
| 1 |
www |
64 |
/**
|
|
|
65 |
*
|
| 16769 |
efrain |
66 |
* @var \Laminas\Mvc\I18n\Translator
|
|
|
67 |
*/
|
|
|
68 |
private $translator;
|
|
|
69 |
|
|
|
70 |
|
|
|
71 |
/**
|
|
|
72 |
*
|
|
|
73 |
* @param \Laminas\Db\Adapter\AdapterInterface $adapter
|
|
|
74 |
* @param \LeadersLinked\Cache\CacheInterface $cache
|
|
|
75 |
* @param \Laminas\Log\LoggerInterface LoggerInterface $logger
|
| 1 |
www |
76 |
* @param array $config
|
| 16769 |
efrain |
77 |
* @param \Laminas\Mvc\I18n\Translator $translator
|
| 1 |
www |
78 |
*/
|
| 16769 |
efrain |
79 |
public function __construct($adapter, $cache, $logger, $config, $translator)
|
| 1 |
www |
80 |
{
|
| 16769 |
efrain |
81 |
$this->adapter = $adapter;
|
|
|
82 |
$this->cache = $cache;
|
|
|
83 |
$this->logger = $logger;
|
|
|
84 |
$this->config = $config;
|
|
|
85 |
$this->translator = $translator;
|
| 16322 |
anderson |
86 |
}
|
| 1 |
www |
87 |
|
|
|
88 |
/**
|
|
|
89 |
*
|
|
|
90 |
* Generación del listado de perfiles
|
|
|
91 |
* {@inheritDoc}
|
|
|
92 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
93 |
*/
|
|
|
94 |
public function indexAction()
|
|
|
95 |
{
|
|
|
96 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
97 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
98 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
99 |
|
| 16322 |
anderson |
100 |
|
|
|
101 |
|
| 1 |
www |
102 |
$request = $this->getRequest();
|
| 16322 |
anderson |
103 |
if ($request->isGet()) {
|
| 1 |
www |
104 |
$headers = $request->getHeaders();
|
| 16322 |
anderson |
105 |
|
| 1 |
www |
106 |
$isJson = false;
|
| 16322 |
anderson |
107 |
if ($headers->has('Accept')) {
|
| 1 |
www |
108 |
$accept = $headers->get('Accept');
|
| 16322 |
anderson |
109 |
|
| 1 |
www |
110 |
$prioritized = $accept->getPrioritized();
|
| 16322 |
anderson |
111 |
|
|
|
112 |
foreach ($prioritized as $key => $value) {
|
| 1 |
www |
113 |
$raw = trim($value->getRaw());
|
| 16322 |
anderson |
114 |
|
|
|
115 |
if (!$isJson) {
|
| 1 |
www |
116 |
$isJson = strpos($raw, 'json');
|
|
|
117 |
}
|
|
|
118 |
}
|
|
|
119 |
}
|
| 16322 |
anderson |
120 |
|
| 7645 |
nelberth |
121 |
$formFeed = new CreateFeedForm($this->adapter);
|
| 16322 |
anderson |
122 |
|
| 1 |
www |
123 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
124 |
$viewModel = new ViewModel();
|
|
|
125 |
$viewModel->setTemplate('leaders-linked/feeds/index.phtml');
|
|
|
126 |
$viewModel->setVariables([
|
|
|
127 |
'formFeed' => $formFeed,
|
|
|
128 |
]);
|
| 16322 |
anderson |
129 |
return $viewModel;
|
| 1 |
www |
130 |
} else {
|
|
|
131 |
return new JsonModel([
|
|
|
132 |
'success' => false,
|
|
|
133 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
134 |
]);
|
|
|
135 |
}
|
|
|
136 |
}
|
| 16322 |
anderson |
137 |
|
|
|
138 |
|
| 1 |
www |
139 |
public function commentAction()
|
|
|
140 |
{
|
| 8394 |
nelberth |
141 |
|
| 16322 |
anderson |
142 |
|
| 1 |
www |
143 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
144 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
145 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 16322 |
anderson |
146 |
|
|
|
147 |
|
| 1 |
www |
148 |
$id = $this->params()->fromRoute('id');
|
| 16322 |
anderson |
149 |
|
| 1 |
www |
150 |
$request = $this->getRequest();
|
| 16322 |
anderson |
151 |
if ($request->isPost()) {
|
| 1 |
www |
152 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 15364 |
efrain |
153 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
| 16322 |
anderson |
154 |
if (!$feed) {
|
| 1 |
www |
155 |
$response = [
|
|
|
156 |
'success' => false,
|
|
|
157 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
158 |
];
|
|
|
159 |
return new JsonModel($response);
|
|
|
160 |
}
|
| 16322 |
anderson |
161 |
|
|
|
162 |
if ($feed->company_id != $currentCompany->id) {
|
| 1 |
www |
163 |
$response = [
|
|
|
164 |
'success' => false,
|
|
|
165 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
166 |
];
|
|
|
167 |
return new JsonModel($response);
|
|
|
168 |
}
|
| 16322 |
anderson |
169 |
|
| 1 |
www |
170 |
$dataPost = $request->getPost()->toArray();
|
|
|
171 |
$form = new CommentForm();
|
|
|
172 |
$form->setData($dataPost);
|
| 16322 |
anderson |
173 |
|
|
|
174 |
if ($form->isValid()) {
|
| 16701 |
efrain |
175 |
$now = $feedMapper->getDatebaseNow();
|
| 16322 |
anderson |
176 |
|
| 1 |
www |
177 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
178 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
| 16322 |
anderson |
179 |
|
| 1 |
www |
180 |
$dataPost = (array) $form->getData();
|
|
|
181 |
$comment = new Comment();
|
|
|
182 |
$comment->comment = $dataPost['comment'];
|
|
|
183 |
$comment->feed_id = $feed->id;
|
| 15364 |
efrain |
184 |
$comment->network_id = $currentUser->network_id;
|
| 16322 |
anderson |
185 |
|
|
|
186 |
if ($feed->type == 'hptg') {
|
| 8232 |
nelberth |
187 |
$comment->user_id = $currentUser->id;
|
| 16322 |
anderson |
188 |
} else if ($feed->type == 'mytq') {
|
| 11420 |
eleazar |
189 |
$comment->user_id = $currentCompany->id;
|
| 16322 |
anderson |
190 |
} else {
|
| 8232 |
nelberth |
191 |
$comment->user_id = $owner->user_id;
|
|
|
192 |
}
|
| 16322 |
anderson |
193 |
|
| 1 |
www |
194 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
| 16322 |
anderson |
195 |
if ($commentMapper->insert($comment)) {
|
|
|
196 |
|
| 1 |
www |
197 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
| 16322 |
anderson |
198 |
|
| 1 |
www |
199 |
$feed->total_comments = $total_comments;
|
|
|
200 |
$feedMapper->update($feed);
|
| 16322 |
anderson |
201 |
|
| 1 |
www |
202 |
$response = [
|
|
|
203 |
'success' => true,
|
| 14740 |
efrain |
204 |
'data' => $this->renderComment($comment->id, $now),
|
| 1 |
www |
205 |
'total_comments' => $total_comments
|
|
|
206 |
];
|
| 16322 |
anderson |
207 |
|
| 1 |
www |
208 |
return new JsonModel($response);
|
|
|
209 |
} else {
|
| 16322 |
anderson |
210 |
|
| 1 |
www |
211 |
$response = [
|
|
|
212 |
'success' => false,
|
|
|
213 |
'data' => $commentMapper->getError()
|
|
|
214 |
];
|
| 16322 |
anderson |
215 |
|
| 1 |
www |
216 |
return new JsonModel($response);
|
|
|
217 |
}
|
|
|
218 |
} else {
|
|
|
219 |
$message = '';;
|
|
|
220 |
$form_messages = (array) $form->getMessages();
|
| 16322 |
anderson |
221 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
222 |
foreach ($field_messages as $key => $value) {
|
| 1 |
www |
223 |
$message = $value;
|
|
|
224 |
}
|
|
|
225 |
}
|
| 16322 |
anderson |
226 |
|
| 1 |
www |
227 |
$response = [
|
|
|
228 |
'success' => false,
|
|
|
229 |
'data' => $message
|
|
|
230 |
];
|
| 16322 |
anderson |
231 |
|
| 1 |
www |
232 |
return new JsonModel($response);
|
|
|
233 |
}
|
|
|
234 |
} else {
|
|
|
235 |
$response = [
|
|
|
236 |
'success' => false,
|
|
|
237 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
238 |
];
|
| 16322 |
anderson |
239 |
|
| 1 |
www |
240 |
return new JsonModel($response);
|
|
|
241 |
}
|
|
|
242 |
}
|
| 8390 |
nelberth |
243 |
|
| 8402 |
nelberth |
244 |
public function answerAction()
|
|
|
245 |
{
|
| 16322 |
anderson |
246 |
|
|
|
247 |
|
| 8402 |
nelberth |
248 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
249 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
250 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 16322 |
anderson |
251 |
|
|
|
252 |
|
| 8402 |
nelberth |
253 |
$id = $this->params()->fromRoute('id');
|
|
|
254 |
$comment_uuid = $this->params()->fromRoute('comment');
|
| 16322 |
anderson |
255 |
|
| 8402 |
nelberth |
256 |
$request = $this->getRequest();
|
| 16322 |
anderson |
257 |
if ($request->isPost()) {
|
| 8402 |
nelberth |
258 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
259 |
$feed = $feedMapper->fetchOneByUuid($id);
|
| 16322 |
anderson |
260 |
if (!$feed) {
|
| 8402 |
nelberth |
261 |
$response = [
|
|
|
262 |
'success' => false,
|
|
|
263 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
264 |
];
|
|
|
265 |
return new JsonModel($response);
|
|
|
266 |
}
|
| 16322 |
anderson |
267 |
|
|
|
268 |
if ($feed->company_id != $currentCompany->id) {
|
| 8402 |
nelberth |
269 |
$response = [
|
|
|
270 |
'success' => false,
|
|
|
271 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
272 |
];
|
|
|
273 |
return new JsonModel($response);
|
|
|
274 |
}
|
| 16322 |
anderson |
275 |
|
| 8402 |
nelberth |
276 |
$dataPost = $request->getPost()->toArray();
|
|
|
277 |
$form = new CommentAnswerForm();
|
|
|
278 |
$form->setData($dataPost);
|
| 16322 |
anderson |
279 |
|
|
|
280 |
if ($form->isValid()) {
|
| 16701 |
efrain |
281 |
$now = $feedMapper->getDatebaseNow();
|
| 16322 |
anderson |
282 |
|
| 8402 |
nelberth |
283 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
284 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
| 16322 |
anderson |
285 |
|
| 8402 |
nelberth |
286 |
$dataPost = (array) $form->getData();
|
| 8408 |
nelberth |
287 |
$answer = new Comment();
|
|
|
288 |
$answer->comment = $dataPost['answer'];
|
|
|
289 |
$answer->feed_id = $feed->id;
|
| 16322 |
anderson |
290 |
|
|
|
291 |
if ($feed->type == 'hptg') {
|
| 8408 |
nelberth |
292 |
$answer->user_id = $currentUser->id;
|
| 16322 |
anderson |
293 |
} else {
|
| 8408 |
nelberth |
294 |
$answer->user_id = $owner->user_id;
|
| 8402 |
nelberth |
295 |
}
|
| 8408 |
nelberth |
296 |
|
|
|
297 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
| 16322 |
anderson |
298 |
$comment = $commentMapper->fetchOneByUuid($comment_uuid);
|
| 8408 |
nelberth |
299 |
$answer->parent_id = $comment->id;
|
| 16322 |
anderson |
300 |
|
|
|
301 |
if ($commentMapper->insert($answer)) {
|
|
|
302 |
|
| 8402 |
nelberth |
303 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
| 16322 |
anderson |
304 |
|
| 8402 |
nelberth |
305 |
$feed->total_comments = $total_comments;
|
|
|
306 |
$feedMapper->update($feed);
|
| 16322 |
anderson |
307 |
|
| 8402 |
nelberth |
308 |
$response = [
|
|
|
309 |
'success' => true,
|
| 14740 |
efrain |
310 |
'data' => $this->renderComment($answer->id, $now),
|
| 8402 |
nelberth |
311 |
'total_comments' => $total_comments
|
|
|
312 |
];
|
| 16322 |
anderson |
313 |
|
| 8402 |
nelberth |
314 |
return new JsonModel($response);
|
|
|
315 |
} else {
|
| 16322 |
anderson |
316 |
|
| 8402 |
nelberth |
317 |
$response = [
|
|
|
318 |
'success' => false,
|
|
|
319 |
'data' => $commentMapper->getError()
|
|
|
320 |
];
|
| 16322 |
anderson |
321 |
|
| 8402 |
nelberth |
322 |
return new JsonModel($response);
|
|
|
323 |
}
|
|
|
324 |
} else {
|
|
|
325 |
$message = '';;
|
|
|
326 |
$form_messages = (array) $form->getMessages();
|
| 16322 |
anderson |
327 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
328 |
foreach ($field_messages as $key => $value) {
|
| 8402 |
nelberth |
329 |
$message = $value;
|
|
|
330 |
}
|
|
|
331 |
}
|
| 16322 |
anderson |
332 |
|
| 8402 |
nelberth |
333 |
$response = [
|
|
|
334 |
'success' => false,
|
|
|
335 |
'data' => $message
|
|
|
336 |
];
|
| 16322 |
anderson |
337 |
|
| 8402 |
nelberth |
338 |
return new JsonModel($response);
|
|
|
339 |
}
|
|
|
340 |
} else {
|
|
|
341 |
$response = [
|
|
|
342 |
'success' => false,
|
|
|
343 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
344 |
];
|
| 16322 |
anderson |
345 |
|
| 8402 |
nelberth |
346 |
return new JsonModel($response);
|
|
|
347 |
}
|
|
|
348 |
}
|
|
|
349 |
|
| 16322 |
anderson |
350 |
|
|
|
351 |
|
| 1 |
www |
352 |
public function commentDeleteAction()
|
|
|
353 |
{
|
|
|
354 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
355 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
356 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 16322 |
anderson |
357 |
|
| 1 |
www |
358 |
$request = $this->getRequest();
|
| 16322 |
anderson |
359 |
if ($request->isPost()) {
|
| 1 |
www |
360 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
361 |
$currentUser = $currentUserPlugin->getUser();
|
| 16322 |
anderson |
362 |
|
| 1 |
www |
363 |
$id = $this->params()->fromRoute('id');
|
|
|
364 |
$comment = $this->params()->fromRoute('comment');
|
| 16322 |
anderson |
365 |
|
| 1 |
www |
366 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 15364 |
efrain |
367 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
| 16322 |
anderson |
368 |
if (!$feed) {
|
| 1 |
www |
369 |
$response = [
|
|
|
370 |
'success' => false,
|
|
|
371 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
372 |
];
|
|
|
373 |
return new JsonModel($response);
|
|
|
374 |
}
|
| 16322 |
anderson |
375 |
|
|
|
376 |
if ($feed->company_id != $currentCompany->id) {
|
| 1 |
www |
377 |
$response = [
|
|
|
378 |
'success' => false,
|
|
|
379 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
380 |
];
|
|
|
381 |
return new JsonModel($response);
|
|
|
382 |
}
|
| 16322 |
anderson |
383 |
|
| 1 |
www |
384 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
385 |
$comment = $commentMapper->fetchOneByUuid($comment);
|
| 16322 |
anderson |
386 |
|
|
|
387 |
if ($comment && $comment->feed_id == $feed->id) {
|
| 1 |
www |
388 |
$comment->status = Comment::STATUS_DELETED;
|
| 16322 |
anderson |
389 |
if ($commentMapper->update($comment)) {
|
| 1 |
www |
390 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
| 16322 |
anderson |
391 |
|
| 1 |
www |
392 |
$feed = $feedMapper->fetchOne($comment->feed_id);
|
|
|
393 |
$feed->total_comments = $total_comments;
|
|
|
394 |
$feedMapper->update($feed);
|
| 16322 |
anderson |
395 |
|
|
|
396 |
|
|
|
397 |
|
|
|
398 |
|
|
|
399 |
|
| 1 |
www |
400 |
$response = [
|
|
|
401 |
'success' => true,
|
| 16322 |
anderson |
402 |
'data' => [
|
| 1 |
www |
403 |
'message' => 'LABEL_COMMENT_WAS_DELETED',
|
|
|
404 |
'total_comments' => $total_comments
|
| 16322 |
anderson |
405 |
]
|
|
|
406 |
];
|
| 1 |
www |
407 |
} else {
|
|
|
408 |
$response = [
|
|
|
409 |
'success' => false,
|
|
|
410 |
'data' => $commentMapper->getError()
|
|
|
411 |
];
|
|
|
412 |
}
|
|
|
413 |
} else {
|
|
|
414 |
$response = [
|
|
|
415 |
'success' => false,
|
|
|
416 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
417 |
];
|
|
|
418 |
}
|
|
|
419 |
} else {
|
|
|
420 |
$response = [
|
|
|
421 |
'success' => false,
|
|
|
422 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
423 |
];
|
|
|
424 |
}
|
| 16322 |
anderson |
425 |
|
| 1 |
www |
426 |
return new JsonModel($response);
|
|
|
427 |
}
|
| 16322 |
anderson |
428 |
|
| 1 |
www |
429 |
public function deleteAction()
|
|
|
430 |
{
|
|
|
431 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
432 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
433 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 16322 |
anderson |
434 |
|
| 1 |
www |
435 |
$request = $this->getRequest();
|
| 16322 |
anderson |
436 |
if ($request->isPost()) {
|
| 1 |
www |
437 |
|
| 16322 |
anderson |
438 |
|
| 1 |
www |
439 |
$id = $this->params()->fromRoute('id');
|
| 16322 |
anderson |
440 |
|
| 1 |
www |
441 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 15364 |
efrain |
442 |
$feed = $feedMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
|
| 16322 |
anderson |
443 |
if (!$feed) {
|
| 1 |
www |
444 |
$response = [
|
|
|
445 |
'success' => false,
|
|
|
446 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
447 |
];
|
|
|
448 |
return new JsonModel($response);
|
|
|
449 |
}
|
| 16322 |
anderson |
450 |
|
|
|
451 |
if ($feed->company_id != $currentCompany->id) {
|
| 1 |
www |
452 |
$response = [
|
|
|
453 |
'success' => false,
|
|
|
454 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
455 |
];
|
|
|
456 |
return new JsonModel($response);
|
|
|
457 |
}
|
| 16322 |
anderson |
458 |
|
| 1 |
www |
459 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
460 |
$feed->status = Feed::STATUS_DELETED;
|
| 16322 |
anderson |
461 |
if ($feedMapper->update($feed)) {
|
| 1 |
www |
462 |
$response = [
|
|
|
463 |
'success' => true,
|
|
|
464 |
'data' => 'LABEL_FEED_WAS_DELETED'
|
|
|
465 |
];
|
|
|
466 |
} else {
|
|
|
467 |
$response = [
|
|
|
468 |
'success' => false,
|
|
|
469 |
'data' => $feedMapper->getError()
|
|
|
470 |
];
|
|
|
471 |
}
|
|
|
472 |
|
| 16322 |
anderson |
473 |
|
| 1 |
www |
474 |
return new JsonModel($response);
|
|
|
475 |
} else {
|
|
|
476 |
$response = [
|
|
|
477 |
'success' => false,
|
|
|
478 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
479 |
];
|
|
|
480 |
}
|
| 16322 |
anderson |
481 |
|
| 1 |
www |
482 |
return new JsonModel($response);
|
|
|
483 |
}
|
| 16322 |
anderson |
484 |
|
| 1 |
www |
485 |
public function addAction()
|
|
|
486 |
{
|
| 16701 |
efrain |
487 |
|
| 16322 |
anderson |
488 |
|
| 1 |
www |
489 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
490 |
$currentUser = $currentUserPlugin->getUser();
|
| 16701 |
efrain |
491 |
|
|
|
492 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
493 |
$currentNetwork = $currentNetworkPlugin->getNetwork();
|
|
|
494 |
|
|
|
495 |
|
| 1 |
www |
496 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 10970 |
eleazar |
497 |
$myt_id = $this->params()->fromRoute('myt_id');
|
| 7403 |
nelberth |
498 |
|
|
|
499 |
$request = $this->getRequest();
|
| 16322 |
anderson |
500 |
if ($request->isPost()) {
|
| 7653 |
nelberth |
501 |
|
| 16322 |
anderson |
502 |
|
| 7653 |
nelberth |
503 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
| 16701 |
efrain |
504 |
$feed_content_type = empty($dataPost['feed_content_type']) ? '' : $dataPost['feed_content_type'];
|
|
|
505 |
|
|
|
506 |
|
|
|
507 |
if( $feed_content_type == Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
508 |
|
|
|
509 |
$form = new FastSurveyForm();
|
|
|
510 |
$form->setData($dataPost);
|
|
|
511 |
|
|
|
512 |
if ($form->isValid()) {
|
|
|
513 |
|
|
|
514 |
$dataPost = (array) $form->getData();
|
|
|
515 |
|
|
|
516 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
517 |
$companyUser = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
518 |
$now = $companyUserMapper->getDatebaseNow();
|
|
|
519 |
|
|
|
520 |
|
|
|
521 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
522 |
$fastSurvey = new FastSurvey();
|
|
|
523 |
$hydrator->hydrate($dataPost, $fastSurvey);
|
|
|
524 |
|
|
|
525 |
$fastSurvey->network_id = $currentNetwork->id;
|
|
|
526 |
$fastSurvey->company_id = $currentCompany->id;
|
|
|
527 |
$fastSurvey->user_id = $companyUser->id;
|
|
|
528 |
$fastSurvey->status = FastSurvey::STATUS_ACTIVE;
|
| 16928 |
efrain |
529 |
|
| 16701 |
efrain |
530 |
|
|
|
531 |
$fastSurveyMapper = FastSurveyMapper::getInstance($this->adapter);
|
|
|
532 |
$result = $fastSurveyMapper->insert($fastSurvey);
|
|
|
533 |
if ($result) {
|
|
|
534 |
$feed = new Feed();
|
|
|
535 |
$feed->company_id = $currentCompany->id;
|
|
|
536 |
$feed->network_id = $currentNetwork->id;
|
|
|
537 |
$feed->user_id = $companyUser->id;
|
|
|
538 |
$feed->fast_survey_id = $fastSurvey->id;
|
|
|
539 |
$feed->type = Feed::TYPE_COMPANY;
|
|
|
540 |
$feed->file_type = Feed::FILE_TYPE_FAST_SURVEY;
|
|
|
541 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
542 |
$feed->status = Feed::STATUS_PUBLISHED;
|
| 16928 |
efrain |
543 |
$feed->title = '-';
|
|
|
544 |
$feed->description = '-';
|
| 16701 |
efrain |
545 |
$feed->total_comments = 0;
|
|
|
546 |
$feed->total_shared = 0;
|
|
|
547 |
$feed->shared_with = Feed::SHARE_WITH_CONNECTIONS;
|
|
|
548 |
|
|
|
549 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
550 |
$feedMapper->insert($feed);
|
|
|
551 |
|
|
|
552 |
$this->logger->info('Se agrego la encuesta rápida : ' . $fastSurvey->question, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
553 |
|
|
|
554 |
$response = [
|
|
|
555 |
'success' => true,
|
|
|
556 |
'data' => $this->renderFeed($feed->id, $now)
|
|
|
557 |
];
|
|
|
558 |
|
|
|
559 |
|
|
|
560 |
} else {
|
|
|
561 |
$response = [
|
| 7409 |
nelberth |
562 |
'success' => false,
|
| 16701 |
efrain |
563 |
'data' => $fastSurveyMapper->getError()
|
| 7409 |
nelberth |
564 |
];
|
|
|
565 |
}
|
| 16701 |
efrain |
566 |
|
|
|
567 |
return new JsonModel($response);
|
|
|
568 |
} else {
|
|
|
569 |
$messages = [];
|
|
|
570 |
$form_messages = (array) $form->getMessages();
|
|
|
571 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
572 |
|
|
|
573 |
$messages[$fieldname] = array_values($field_messages);
|
| 16322 |
anderson |
574 |
}
|
| 16701 |
efrain |
575 |
|
|
|
576 |
return new JsonModel([
|
|
|
577 |
'success' => false,
|
|
|
578 |
'data' => $messages
|
|
|
579 |
]);
|
|
|
580 |
}
|
|
|
581 |
} else {
|
|
|
582 |
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
|
|
|
586 |
$form = new CreateFeedForm($this->adapter);
|
|
|
587 |
|
|
|
588 |
$form->setData($dataPost);
|
|
|
589 |
|
|
|
590 |
if ($form->isValid()) {
|
|
|
591 |
|
|
|
592 |
|
|
|
593 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
594 |
$now = $companyMapper->getDatebaseNow();
|
|
|
595 |
|
|
|
596 |
|
|
|
597 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
598 |
|
|
|
599 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
600 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($company->id);
|
|
|
601 |
|
|
|
602 |
$dataPost['priority'] = isset($dataPost['priority']) ? Feed::PRIORITY_URGENT : '';
|
|
|
603 |
|
|
|
604 |
|
|
|
605 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
606 |
$feed = new Feed();
|
|
|
607 |
$hydrator->hydrate($dataPost, $feed);
|
| 17002 |
efrain |
608 |
|
| 16983 |
efrain |
609 |
if ($myt_id) {
|
| 16701 |
efrain |
610 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
611 |
$myt = $feedMapper->fetchOneByUuid($myt_id);
|
|
|
612 |
$feed->network_id = $currentUser->network_id;
|
|
|
613 |
$feed->company_id = $currentCompany->id;
|
|
|
614 |
$feed->group_id = null;
|
|
|
615 |
$feed->user_id = $owner->user_id;
|
|
|
616 |
$feed->myt_id = $myt->id;
|
|
|
617 |
$feed->related_feed = $myt->id;
|
|
|
618 |
$feed->type = Feed::TYPE_MYT_ANSWER;
|
|
|
619 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
620 |
$feed->shared_with = Feed::SHARE_WITH_PUBLIC;
|
|
|
621 |
} else {
|
|
|
622 |
$feed->network_id = $currentUser->network_id;
|
|
|
623 |
$feed->company_id = $currentCompany->id;
|
|
|
624 |
$feed->group_id = null;
|
|
|
625 |
$feed->user_id = $owner->user_id;
|
|
|
626 |
$feed->type = Feed::TYPE_COMPANY;
|
|
|
627 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
628 |
$feed->shared_with = Feed::SHARE_WITH_CONNECTIONS;
|
| 1 |
www |
629 |
}
|
| 16701 |
efrain |
630 |
|
|
|
631 |
|
|
|
632 |
|
|
|
633 |
|
|
|
634 |
$feed->total_comments = 0;
|
|
|
635 |
$feed->total_shared = 0;
|
|
|
636 |
|
|
|
637 |
|
|
|
638 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
639 |
$file_type = '';
|
|
|
640 |
if (isset($files['file']) && empty($files['file']['error'])) {
|
|
|
641 |
$feed_tmp_filename = $files['file']['tmp_name'];
|
| 17018 |
efrain |
642 |
$feed_filename = \LeadersLinked\Library\Functions::normalizeStringFilename($files['file']['name']);
|
| 16701 |
efrain |
643 |
|
|
|
644 |
$mime_type = mime_content_type($feed_tmp_filename);
|
|
|
645 |
if ($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
|
|
|
646 |
$file_type = Feed::FILE_TYPE_IMAGE;
|
| 16822 |
efrain |
647 |
} else if ($mime_type == 'video/quicktime' || $mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
|
| 16701 |
efrain |
648 |
$file_type = Feed::FILE_TYPE_VIDEO;
|
|
|
649 |
} else if ($mime_type == 'application/pdf') {
|
|
|
650 |
$file_type = Feed::FILE_TYPE_DOCUMENT;
|
| 1 |
www |
651 |
}
|
|
|
652 |
}
|
| 16701 |
efrain |
653 |
|
|
|
654 |
|
|
|
655 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
656 |
$result = $feedMapper->insert($feed);
|
|
|
657 |
|
|
|
658 |
|
|
|
659 |
if ($result) {
|
|
|
660 |
|
|
|
661 |
$feed = $feedMapper->fetchOne($feed->id);
|
| 17002 |
efrain |
662 |
|
|
|
663 |
|
| 17018 |
efrain |
664 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 17002 |
efrain |
665 |
$target_path = $storage->getPathFeed();
|
|
|
666 |
$interal_path = 'data' . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
|
|
|
667 |
if(!file_exists($interal_path)) {
|
|
|
668 |
mkdir($interal_path, 0775);
|
|
|
669 |
}
|
| 16701 |
efrain |
670 |
if ($file_type == Feed::FILE_TYPE_DOCUMENT) {
|
| 17002 |
efrain |
671 |
|
|
|
672 |
|
|
|
673 |
if ($storage->putFile($target_path, $feed->uuid, $feed_filename)) {
|
|
|
674 |
$feed->file_type = $file_type;
|
|
|
675 |
$feed->file_name = $feed_filename;
|
|
|
676 |
$feedMapper->update($feed);
|
| 1 |
www |
677 |
}
|
| 17002 |
efrain |
678 |
|
|
|
679 |
} else if ($file_type == Feed::FILE_TYPE_IMAGE) {
|
|
|
680 |
$image = Image::getInstance($this->config);
|
|
|
681 |
$target_path = $image->getStorage()->getPathFeed();
|
|
|
682 |
|
|
|
683 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.feed_image_size']);
|
|
|
684 |
|
|
|
685 |
|
|
|
686 |
$feed_filename = substr($feed_filename, 0, strrpos($feed_filename, '.')) . '.png';
|
|
|
687 |
$crop_to_dimensions = false;
|
|
|
688 |
$unlink_source = true;
|
|
|
689 |
|
| 17018 |
efrain |
690 |
if(!$image->uploadProcessChangeSize($feed_tmp_filename, $target_path, $feed->uuid, $feed_filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
|
| 17002 |
efrain |
691 |
$feed->file_type = $file_type;
|
|
|
692 |
$feed->file_name = $feed_filename;
|
|
|
693 |
$feedMapper->update($feed);
|
| 1 |
www |
694 |
}
|
|
|
695 |
}
|
| 16701 |
efrain |
696 |
if ($file_type == Feed::FILE_TYPE_VIDEO) {
|
|
|
697 |
try {
|
| 17002 |
efrain |
698 |
|
|
|
699 |
$full_filename = $interal_path . DIRECTORY_SEPARATOR. $feed_filename;
|
|
|
700 |
$poster_filename = substr($feed_filename, 0, strrpos($feed_filename, '.')). '.jpg';
|
|
|
701 |
$poster_full_filename = $interal_path . DIRECTORY_SEPARATOR . $poster_filename;
|
|
|
702 |
|
|
|
703 |
move_uploaded_file($feed_tmp_filename, $full_filename);
|
|
|
704 |
|
|
|
705 |
$cmd = "/usr/bin/ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=height,width,duration $full_filename";
|
|
|
706 |
$response = trim(shell_exec($cmd));
|
|
|
707 |
|
|
|
708 |
$source_duration = 0;
|
|
|
709 |
$lines = explode("\n", $response);
|
|
|
710 |
foreach ($lines as $line) {
|
|
|
711 |
$line = trim(strtolower($line));
|
|
|
712 |
if (strpos($line, 'duration') !== false) {
|
|
|
713 |
$values = explode('=', $line);
|
|
|
714 |
$source_duration = intval(str_replace($values[1], '#', ''), 10);
|
|
|
715 |
}
|
| 16701 |
efrain |
716 |
}
|
| 17002 |
efrain |
717 |
|
|
|
718 |
|
|
|
719 |
if ($source_duration == 0) {
|
|
|
720 |
$second_extract = '00:00:02';
|
|
|
721 |
} else {
|
|
|
722 |
if ($source_duration > 10) {
|
|
|
723 |
$second_extract = '00:00:10';
|
|
|
724 |
} else {
|
| 16961 |
efrain |
725 |
$second_extract = '00:00:02';
|
|
|
726 |
}
|
| 17002 |
efrain |
727 |
}
|
|
|
728 |
|
|
|
729 |
//$imageSize = $this->config['leaderslinked.image_sizes.feed_image_size'];
|
|
|
730 |
|
|
|
731 |
//$cmd = "/usr/bin/ffmpeg -y -i $full_filename -pix_fmt yuvj422p -deinterlace -an -ss $second_extract -f mjpeg -t 1 -r 1 -y -s $imageSize $generateFile";
|
|
|
732 |
// $cmd = "/usr/bin/ffmpeg -y -i $full_filename -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y -s $imageSize $generateFile";
|
|
|
733 |
$cmd = "/usr/bin/ffmpeg -y -i $full_filename -pix_fmt yuvj422p -an -ss $second_extract -f mjpeg -t 1 -r 1 -y $poster_full_filename";
|
|
|
734 |
exec($cmd);
|
|
|
735 |
|
|
|
736 |
|
|
|
737 |
$ok = $this->storage->putFile($target_path, $feed->uuid, $poster_full_filename);
|
|
|
738 |
$ok = $ok && $this->storage->putFile($target_path, $feed->uuid, $full_filename);
|
|
|
739 |
|
|
|
740 |
if( $ok ) {
|
|
|
741 |
|
| 16701 |
efrain |
742 |
$feed->file_type = $file_type;
|
|
|
743 |
$feed->file_name = basename($feed_filename);
|
| 17002 |
efrain |
744 |
$feed->file_image_preview = basename($poster_filename);;
|
|
|
745 |
|
|
|
746 |
|
|
|
747 |
|
|
|
748 |
if($feedMapper->update($feed)) {
|
|
|
749 |
|
|
|
750 |
$videoConvert = new VideoConvert();
|
|
|
751 |
$videoConvert->uuid = $feed->uuid;
|
|
|
752 |
$videoConvert->filename = basename($feed_filename);
|
|
|
753 |
$videoConvert->type = VideoConvert::TYPE_FEED;
|
|
|
754 |
|
|
|
755 |
$videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
|
|
|
756 |
$videoConvertMapper->insert($videoConvert);
|
|
|
757 |
}
|
| 16701 |
efrain |
758 |
}
|
| 17002 |
efrain |
759 |
|
|
|
760 |
// @unlink($full_filename);
|
|
|
761 |
//@unlink($generate_full_filename);
|
|
|
762 |
|
|
|
763 |
|
| 16701 |
efrain |
764 |
} catch (\Throwable $e) {
|
|
|
765 |
error_log($e->getTraceAsString());
|
|
|
766 |
}
|
|
|
767 |
}
|
|
|
768 |
|
|
|
769 |
|
|
|
770 |
$response = [
|
|
|
771 |
'success' => true,
|
|
|
772 |
'data' => $this->renderFeed($feed->id, $now)
|
|
|
773 |
];
|
|
|
774 |
} else {
|
|
|
775 |
$response = [
|
|
|
776 |
'success' => false,
|
|
|
777 |
'data' => $feedMapper->getError()
|
|
|
778 |
];
|
| 1 |
www |
779 |
}
|
|
|
780 |
} else {
|
| 16701 |
efrain |
781 |
$messages = [];
|
|
|
782 |
$form_messages = (array) $form->getMessages();
|
|
|
783 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
784 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
785 |
}
|
|
|
786 |
|
| 1 |
www |
787 |
$response = [
|
|
|
788 |
'success' => false,
|
| 16701 |
efrain |
789 |
'data' => $messages
|
| 1 |
www |
790 |
];
|
|
|
791 |
}
|
|
|
792 |
}
|
|
|
793 |
} else {
|
|
|
794 |
$response = [
|
|
|
795 |
'success' => false,
|
|
|
796 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
797 |
];
|
|
|
798 |
}
|
| 16322 |
anderson |
799 |
|
| 1 |
www |
800 |
return new JsonModel($response);
|
|
|
801 |
}
|
| 16322 |
anderson |
802 |
|
|
|
803 |
|
| 14740 |
efrain |
804 |
public function timelineAction()
|
|
|
805 |
{
|
| 16322 |
anderson |
806 |
|
| 16701 |
efrain |
807 |
|
|
|
808 |
|
| 16322 |
anderson |
809 |
|
| 1 |
www |
810 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
811 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
812 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 7357 |
nelberth |
813 |
|
| 16322 |
anderson |
814 |
|
|
|
815 |
|
|
|
816 |
|
|
|
817 |
|
| 7366 |
nelberth |
818 |
$request = $this->getRequest();
|
| 16322 |
anderson |
819 |
if ($request->isGet()) {
|
|
|
820 |
|
| 17002 |
efrain |
821 |
$page = (int) $this->params()->fromQuery('page');
|
|
|
822 |
$myt_id = $this->params()->fromRoute('myt_id');
|
|
|
823 |
|
| 16983 |
efrain |
824 |
if ($myt_id) {
|
| 10990 |
eleazar |
825 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 16701 |
efrain |
826 |
$now = $feedMapper->getDatebaseNow();
|
|
|
827 |
|
| 10990 |
eleazar |
828 |
$myt = $feedMapper->fetchOneByUuid($myt_id);
|
| 10601 |
eleazar |
829 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
830 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
831 |
$select->columns(['id']);
|
|
|
832 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
| 16322 |
anderson |
833 |
$select->where->equalTo('company_id', $currentCompany->id);
|
| 10992 |
eleazar |
834 |
$select->where->equalTo('myt_id', $myt->id);
|
| 11001 |
eleazar |
835 |
$select->where->and->equalTo('type', Feed::TYPE_MYT_ANSWER);
|
| 10601 |
eleazar |
836 |
$select->order('added_on desc');
|
| 16322 |
anderson |
837 |
} else {
|
| 10557 |
eleazar |
838 |
|
| 7350 |
nelberth |
839 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
| 16701 |
efrain |
840 |
$now = $queryMapper->getDatebaseNow();
|
|
|
841 |
|
| 7350 |
nelberth |
842 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
843 |
$select->columns(['id']);
|
|
|
844 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
| 16322 |
anderson |
845 |
$select->where->equalTo('company_id', $currentCompany->id);
|
| 7350 |
nelberth |
846 |
$select->where->and->equalTo('type', Feed::TYPE_COMPANY);
|
|
|
847 |
$select->order('added_on desc');
|
| 16701 |
efrain |
848 |
|
|
|
849 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
|
|
850 |
|
| 7350 |
nelberth |
851 |
}
|
| 16322 |
anderson |
852 |
|
|
|
853 |
|
|
|
854 |
|
| 17008 |
efrain |
855 |
$dbSelect = new \Laminas\Paginator\Adapter\DbSelect($select, $this->adapter);
|
|
|
856 |
$paginator = new \Laminas\Paginator\Paginator($dbSelect);
|
| 1 |
www |
857 |
$paginator->setCurrentPageNumber($page ? $page : 1);
|
|
|
858 |
$paginator->setItemCountPerPage(10);
|
| 16322 |
anderson |
859 |
|
| 1 |
www |
860 |
$items = [];
|
|
|
861 |
$feeds = $paginator->getCurrentItems();
|
| 16322 |
anderson |
862 |
|
|
|
863 |
foreach ($feeds as $feed) {
|
| 14740 |
efrain |
864 |
$items[] = $this->renderFeed($feed->id, $now);
|
| 1 |
www |
865 |
}
|
| 16322 |
anderson |
866 |
|
| 1 |
www |
867 |
$response = [
|
|
|
868 |
'success' => true,
|
|
|
869 |
'data' => [
|
|
|
870 |
'total' => [
|
|
|
871 |
'count' => $paginator->getTotalItemCount(),
|
|
|
872 |
'pages' => $paginator->getPages()->pageCount,
|
|
|
873 |
],
|
|
|
874 |
'current' => [
|
|
|
875 |
'items' => $items,
|
|
|
876 |
'page' => $paginator->getCurrentPageNumber(),
|
|
|
877 |
'count' => $paginator->getCurrentItemCount(),
|
|
|
878 |
]
|
|
|
879 |
]
|
|
|
880 |
];
|
| 16322 |
anderson |
881 |
|
| 1 |
www |
882 |
return new JsonModel($response);
|
|
|
883 |
}
|
| 16322 |
anderson |
884 |
|
| 1 |
www |
885 |
$response = [
|
|
|
886 |
'success' => false,
|
|
|
887 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
888 |
];
|
| 16322 |
anderson |
889 |
|
|
|
890 |
|
| 1 |
www |
891 |
return new JsonModel($response);
|
|
|
892 |
}
|
| 16322 |
anderson |
893 |
|
| 14740 |
efrain |
894 |
public function oneFeedAction()
|
|
|
895 |
{
|
| 16701 |
efrain |
896 |
|
|
|
897 |
|
| 16322 |
anderson |
898 |
|
|
|
899 |
|
| 10118 |
nelberth |
900 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
901 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
902 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 11331 |
eleazar |
903 |
|
| 10118 |
nelberth |
904 |
$request = $this->getRequest();
|
| 16322 |
anderson |
905 |
if ($request->isGet()) {
|
|
|
906 |
|
| 11725 |
eleazar |
907 |
$feed_uuid = $this->params()->fromRoute('id');
|
|
|
908 |
$myt_id = $this->params()->fromRoute('id');
|
| 16322 |
anderson |
909 |
|
|
|
910 |
if (!isset($feed_uuid)) {
|
|
|
911 |
$data = [
|
|
|
912 |
'success' => false,
|
|
|
913 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
914 |
];
|
|
|
915 |
|
|
|
916 |
return new JsonModel($data);
|
| 11331 |
eleazar |
917 |
}
|
| 16322 |
anderson |
918 |
|
| 10118 |
nelberth |
919 |
$items = [];
|
| 11331 |
eleazar |
920 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
| 16701 |
efrain |
921 |
$now = $feedMapper->getDatebaseNow();
|
|
|
922 |
|
| 11331 |
eleazar |
923 |
$feed = $feedMapper->fetchOneByUuid($feed_uuid);
|
|
|
924 |
|
|
|
925 |
if (!$feed) {
|
|
|
926 |
$data = [
|
|
|
927 |
'success' => false,
|
|
|
928 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
929 |
];
|
| 16322 |
anderson |
930 |
|
| 11331 |
eleazar |
931 |
return new JsonModel($data);
|
| 16322 |
anderson |
932 |
}
|
|
|
933 |
|
|
|
934 |
if ($feed->type == 'mytq') {
|
|
|
935 |
|
| 14740 |
efrain |
936 |
$items = $this->renderFeed($feed->id, $now, $myt_id);
|
| 11195 |
eleazar |
937 |
|
| 11536 |
eleazar |
938 |
$response = [
|
|
|
939 |
'success' => true,
|
|
|
940 |
'data' => [
|
| 16322 |
anderson |
941 |
'item' => $items,
|
|
|
942 |
'feed_title' => $feed->title,
|
|
|
943 |
'topic_title' => $feed->description
|
| 11536 |
eleazar |
944 |
]
|
|
|
945 |
];
|
| 16983 |
efrain |
946 |
} else if ($feed->type == 'myta') {
|
|
|
947 |
|
| 16322 |
anderson |
948 |
|
| 14740 |
efrain |
949 |
$items = $this->renderFeed($feed->id, $now, $myt_id);
|
| 11519 |
eleazar |
950 |
|
|
|
951 |
$response = [
|
|
|
952 |
'success' => true,
|
|
|
953 |
'data' => [
|
| 16322 |
anderson |
954 |
'item' => $items,
|
|
|
955 |
'feed_title' => $feed->title,
|
|
|
956 |
'topic_title' => $feed->description
|
| 11519 |
eleazar |
957 |
]
|
|
|
958 |
];
|
| 16983 |
efrain |
959 |
}
|
|
|
960 |
|
|
|
961 |
/*else if ($feed->type == 'hptg') {
|
| 11519 |
eleazar |
962 |
|
| 11404 |
eleazar |
963 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
964 |
$topic_uuid = $this->params()->fromRoute('topic_id');
|
| 10118 |
nelberth |
965 |
|
| 16322 |
anderson |
966 |
if (!isset($topic_uuid)) {
|
|
|
967 |
|
| 11404 |
eleazar |
968 |
$data = [
|
|
|
969 |
'success' => false,
|
|
|
970 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
971 |
];
|
| 16322 |
anderson |
972 |
|
| 11404 |
eleazar |
973 |
return new JsonModel($data);
|
|
|
974 |
}
|
| 16322 |
anderson |
975 |
if (!isset($group_uuid)) {
|
|
|
976 |
|
| 11404 |
eleazar |
977 |
$data = [
|
|
|
978 |
'success' => false,
|
|
|
979 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
980 |
];
|
| 16322 |
anderson |
981 |
|
| 11404 |
eleazar |
982 |
return new JsonModel($data);
|
|
|
983 |
}
|
|
|
984 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
985 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
| 16322 |
anderson |
986 |
|
| 11404 |
eleazar |
987 |
if (!$highPerformanceTeamsGroups) {
|
|
|
988 |
$data = [
|
|
|
989 |
'success' => false,
|
|
|
990 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
991 |
];
|
| 16322 |
anderson |
992 |
|
| 11404 |
eleazar |
993 |
return new JsonModel($data);
|
|
|
994 |
}
|
| 10118 |
nelberth |
995 |
|
| 16322 |
anderson |
996 |
|
|
|
997 |
if ($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
998 |
|
| 11404 |
eleazar |
999 |
return new JsonModel([
|
|
|
1000 |
'success' => false,
|
|
|
1001 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1002 |
]);
|
| 16322 |
anderson |
1003 |
}
|
| 10118 |
nelberth |
1004 |
|
| 16322 |
anderson |
1005 |
if ($feed->high_performance_group_id != $highPerformanceTeamsGroups->id) {
|
| 11404 |
eleazar |
1006 |
return new JsonModel([
|
|
|
1007 |
'success' => false,
|
|
|
1008 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1009 |
]);
|
|
|
1010 |
}
|
| 16322 |
anderson |
1011 |
|
| 11404 |
eleazar |
1012 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
|
|
1013 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
| 10118 |
nelberth |
1014 |
|
| 11404 |
eleazar |
1015 |
if (!$topic) {
|
|
|
1016 |
$data = [
|
|
|
1017 |
'success' => false,
|
|
|
1018 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1019 |
];
|
| 16322 |
anderson |
1020 |
|
| 11404 |
eleazar |
1021 |
return new JsonModel($data);
|
| 16322 |
anderson |
1022 |
}
|
| 10118 |
nelberth |
1023 |
|
| 16322 |
anderson |
1024 |
if ($feed->topic_id != $topic->id) {
|
| 11404 |
eleazar |
1025 |
return new JsonModel([
|
|
|
1026 |
'success' => false,
|
|
|
1027 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1028 |
]);
|
| 16322 |
anderson |
1029 |
}
|
| 10521 |
eleazar |
1030 |
|
| 16322 |
anderson |
1031 |
$items = $this->renderFeed($feed->id, $now, $group_uuid);
|
|
|
1032 |
|
| 11404 |
eleazar |
1033 |
$response = [
|
|
|
1034 |
'success' => true,
|
|
|
1035 |
'data' => [
|
| 16322 |
anderson |
1036 |
'item' => $items,
|
|
|
1037 |
'topic_title' => $topic->title,
|
|
|
1038 |
'feed_title' => $feed->title
|
| 11404 |
eleazar |
1039 |
]
|
|
|
1040 |
];
|
| 16983 |
efrain |
1041 |
}*/
|
| 16322 |
anderson |
1042 |
|
| 11331 |
eleazar |
1043 |
return new JsonModel($response);
|
| 11399 |
eleazar |
1044 |
}
|
| 10118 |
nelberth |
1045 |
}
|
| 17018 |
efrain |
1046 |
|
| 16322 |
anderson |
1047 |
|
|
|
1048 |
|
| 1 |
www |
1049 |
/**
|
|
|
1050 |
*
|
|
|
1051 |
* @param int $feed_id
|
| 17008 |
efrain |
1052 |
* @param \LeadersLinked\Model\Company $company
|
| 1 |
www |
1053 |
* @return array
|
|
|
1054 |
*/
|
| 16322 |
anderson |
1055 |
private function renderFeed($feed_id, $now, $group_uuid = '', $myt_id = '')
|
| 1 |
www |
1056 |
{
|
| 15351 |
efrain |
1057 |
|
| 1 |
www |
1058 |
|
|
|
1059 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1060 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1061 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 16322 |
anderson |
1062 |
|
| 1 |
www |
1063 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1064 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 16322 |
anderson |
1065 |
|
| 1 |
www |
1066 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1067 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
| 15351 |
efrain |
1068 |
|
|
|
1069 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
1070 |
$network = $currentNetworkPlugin->getNetwork();
|
| 16322 |
anderson |
1071 |
|
| 1 |
www |
1072 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
| 16322 |
anderson |
1073 |
|
| 1 |
www |
1074 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1075 |
$feed = $feedMapper->fetchOne($feed_id);
|
|
|
1076 |
|
| 16322 |
anderson |
1077 |
|
| 1 |
www |
1078 |
$params = [
|
|
|
1079 |
'id' => $feed->uuid
|
|
|
1080 |
];
|
|
|
1081 |
|
| 17018 |
efrain |
1082 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 17002 |
efrain |
1083 |
$path = $storage->getPathFeed();
|
| 16322 |
anderson |
1084 |
|
| 1 |
www |
1085 |
$item = [
|
|
|
1086 |
'feed_unique' => uniqid(),
|
|
|
1087 |
'feed_uuid' => $feed->uuid,
|
|
|
1088 |
'feed_content_type' => $feed->file_type ? $feed->file_type : '',
|
| 16322 |
anderson |
1089 |
'owner_url' => 'https://' . $network->main_hostname . '/company/view/' . $company->uuid,
|
| 17002 |
efrain |
1090 |
'owner_image' => $storage->getCompanyImage($company),
|
| 16322 |
anderson |
1091 |
'owner_name' => $company->name,
|
| 1 |
www |
1092 |
];
|
| 16701 |
efrain |
1093 |
|
| 16322 |
anderson |
1094 |
|
| 16701 |
efrain |
1095 |
|
|
|
1096 |
|
| 17008 |
efrain |
1097 |
$userMapper = \LeadersLinked\Mapper\UserMapper::getInstance($this->adapter);
|
| 1 |
www |
1098 |
$user = $userMapper->fetchOne($feed->user_id);
|
|
|
1099 |
|
| 16322 |
anderson |
1100 |
|
| 16701 |
efrain |
1101 |
|
| 1 |
www |
1102 |
$item['owner_shared'] = $feed->total_shared;
|
|
|
1103 |
$item['owner_comments'] = $feed->total_comments;
|
| 16701 |
efrain |
1104 |
|
|
|
1105 |
|
|
|
1106 |
if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
1107 |
$fastSurveyMapper = FastSurveyMapper::getInstance($this->adapter);
|
|
|
1108 |
$fastSurvey = $fastSurveyMapper->fetchOne($feed->fast_survey_id);
|
|
|
1109 |
|
|
|
1110 |
$owner_description = [
|
|
|
1111 |
'question' => $fastSurvey->question,
|
|
|
1112 |
'number_of_answers' => $fastSurvey->number_of_answers,
|
|
|
1113 |
'answer1' => $fastSurvey->answer1,
|
|
|
1114 |
'answer2' => $fastSurvey->answer2,
|
|
|
1115 |
'answer3' => $fastSurvey->answer3,
|
|
|
1116 |
'answer4' => $fastSurvey->answer4,
|
|
|
1117 |
'answer5' => $fastSurvey->answer5,
|
|
|
1118 |
'result_type' => $fastSurvey->result_type,
|
|
|
1119 |
|
|
|
1120 |
];
|
|
|
1121 |
|
|
|
1122 |
if($fastSurvey->expire_on > $now) {
|
|
|
1123 |
|
|
|
1124 |
|
|
|
1125 |
|
|
|
1126 |
$owner_description['active'] = 1;
|
|
|
1127 |
$owner_description['time_remaining'] = Functions::getDateDiff($now, $fastSurvey->expire_on);
|
|
|
1128 |
|
|
|
1129 |
} else {
|
|
|
1130 |
if($fastSurvey->result_type == FastSurvey::RESULT_TYPE_PUBLIC) {
|
|
|
1131 |
$owner_description['votes1'] = $fastSurvey->votes1;
|
|
|
1132 |
$owner_description['votes2'] = $fastSurvey->votes2;
|
|
|
1133 |
$owner_description['votes3'] = $fastSurvey->votes3;
|
|
|
1134 |
$owner_description['votes4'] = $fastSurvey->votes4;
|
|
|
1135 |
$owner_description['votes5'] = $fastSurvey->votes5;
|
|
|
1136 |
}
|
|
|
1137 |
|
|
|
1138 |
|
|
|
1139 |
$owner_description['active'] = 0;
|
|
|
1140 |
$owner_description['time_remaining'] = 0;
|
|
|
1141 |
}
|
|
|
1142 |
|
|
|
1143 |
|
|
|
1144 |
$item['owner_description'] = $owner_description;
|
|
|
1145 |
|
|
|
1146 |
|
|
|
1147 |
$item['feed_delete_url'] = '';
|
|
|
1148 |
} else {
|
|
|
1149 |
$item['owner_description'] = strip_tags($feed->description, 'p');
|
|
|
1150 |
$item['feed_delete_url'] = $this->url()->fromRoute('feeds/delete', $params);
|
|
|
1151 |
}
|
| 16322 |
anderson |
1152 |
|
|
|
1153 |
|
|
|
1154 |
$item['owner_time_elapse'] = Functions::timeAgo($feed->added_on, $now);
|
|
|
1155 |
|
|
|
1156 |
if ($feed->file_type == Feed::FILE_TYPE_IMAGE) {
|
| 17002 |
efrain |
1157 |
$item['owner_file_image'] = $storage->getGenericImage($path, $feed->uuid, $feed->file_name);
|
| 1 |
www |
1158 |
}
|
| 16322 |
anderson |
1159 |
if ($feed->file_type == Feed::FILE_TYPE_DOCUMENT) {
|
| 17002 |
efrain |
1160 |
$item['owner_file_document'] = $storage->getGenericFile($path, $feed->uuid, $feed->file_name);
|
| 1 |
www |
1161 |
}
|
| 16322 |
anderson |
1162 |
if ($feed->file_type == Feed::FILE_TYPE_VIDEO) {
|
| 17002 |
efrain |
1163 |
$item['owner_file_image_preview'] = $storage->getGenericImage($path, $feed->uuid, $feed->file_image_preview);
|
|
|
1164 |
$item['owner_file_video'] = $$storage->getGenericFile($path, $feed->uuid, $feed->file_name);
|
| 1 |
www |
1165 |
}
|
| 16322 |
anderson |
1166 |
|
| 16817 |
efrain |
1167 |
|
|
|
1168 |
|
|
|
1169 |
|
| 16701 |
efrain |
1170 |
if($feed->file_type == Feed::FILE_TYPE_FAST_SURVEY) {
|
|
|
1171 |
$item['comment_add_url'] = '';
|
|
|
1172 |
$item['comments'] = [];
|
|
|
1173 |
} else {
|
|
|
1174 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
1175 |
$records = $commentMapper->fetchAllPublishedByFeedId($feed->id);
|
| 16817 |
efrain |
1176 |
|
| 16701 |
efrain |
1177 |
|
|
|
1178 |
$comments = [];
|
|
|
1179 |
$comment_count = 0;
|
|
|
1180 |
foreach ($records as $record) {
|
|
|
1181 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
1182 |
|
|
|
1183 |
$comment = [];
|
|
|
1184 |
$comment['unique'] = uniqid();
|
|
|
1185 |
$comment_count++;
|
|
|
1186 |
$comment['comment_index'] = $comment_count;
|
|
|
1187 |
$user = $userMapper->fetchOne($record->user_id);
|
| 16322 |
anderson |
1188 |
if ($user->id == $owner->user_id) {
|
| 17002 |
efrain |
1189 |
$comment['user_image'] = $storage->getCompanyImage($company);
|
| 16701 |
efrain |
1190 |
$comment['user_url'] = 'https://' . $network->main_hostname . '/company/view/' . $company->uuid;
|
|
|
1191 |
$comment['user_name'] = $company->name;
|
| 8414 |
nelberth |
1192 |
} else {
|
| 17012 |
efrain |
1193 |
$comment['user_image'] = $storage->getUserImage($user);
|
| 16701 |
efrain |
1194 |
$comment['user_url'] = 'https://' . $network->main_hostname . '/profile/view/' . $user->uuid;
|
|
|
1195 |
$comment['user_name'] = $user->first_name . ' ' . $user->last_name;
|
| 10406 |
nelberth |
1196 |
}
|
| 16701 |
efrain |
1197 |
$comment['link_delete'] = $this->url()->fromRoute('feeds/comments/delete', ['id' => $feed->uuid, 'comment' => $record->uuid]);
|
|
|
1198 |
$comment['link_answer_add'] = $this->url()->fromRoute('feeds/comments/answer', ['id' => $feed->uuid, 'comment' => $record->uuid]);
|
|
|
1199 |
$comment['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
|
|
|
1200 |
$comment['comment'] = $record->comment;
|
|
|
1201 |
|
|
|
1202 |
$records2 = $commentMapper->fetchAllPublishedByCommentId($record->id);
|
|
|
1203 |
$answers = [];
|
|
|
1204 |
$contador = 0;
|
|
|
1205 |
foreach ($records2 as $record2) {
|
|
|
1206 |
$user = $userMapper->fetchOne($record2->user_id);
|
|
|
1207 |
|
|
|
1208 |
|
|
|
1209 |
$answer = [];
|
|
|
1210 |
$answer['unique'] = uniqid();
|
|
|
1211 |
|
|
|
1212 |
|
|
|
1213 |
$user = $userMapper->fetchOne($record2->user_id);
|
|
|
1214 |
if ($user->id == $owner->user_id) {
|
| 17002 |
efrain |
1215 |
$answer['user_image'] = $storage->getCompanyImage($company);
|
| 16701 |
efrain |
1216 |
$answer['user_url'] = 'https://' . $network->main_hostname . '/company/view/' . $company->uuid;
|
|
|
1217 |
$answer['user_name'] = $company->name;
|
|
|
1218 |
} else {
|
| 17002 |
efrain |
1219 |
$answer['user_image'] = $storage->getUserImage( $user);
|
| 16701 |
efrain |
1220 |
$answer['user_url'] = 'https://' . $network->main_hostname . '/profile/view/' . $user->uuid;
|
|
|
1221 |
$answer['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
1222 |
}
|
|
|
1223 |
$answer['link_delete'] = $this->url()->fromRoute('feeds/comments/delete', ['id' => $feed->uuid, 'comment' => $record2->uuid]);
|
|
|
1224 |
$answer['time_elapsed'] = Functions::timeAgo($record2->added_on, $now);
|
|
|
1225 |
$answer['comment'] = $record2->comment;
|
|
|
1226 |
|
|
|
1227 |
$records2 = $commentMapper->fetchAllPublishedByCommentId($record2->id);
|
|
|
1228 |
|
|
|
1229 |
$contador++;
|
|
|
1230 |
array_push($answers, $answer);
|
|
|
1231 |
}
|
|
|
1232 |
$comment['number_answers'] = $contador;
|
|
|
1233 |
$comment['answers'] = $answers;
|
|
|
1234 |
array_push($comments, $comment);
|
| 8414 |
nelberth |
1235 |
}
|
| 16701 |
efrain |
1236 |
$item['comment_add_url'] = $this->url()->fromRoute('feeds/comments', ['id' => $feed->uuid]);
|
|
|
1237 |
$item['comments'] = $comments;
|
| 1 |
www |
1238 |
}
|
| 16322 |
anderson |
1239 |
|
|
|
1240 |
|
| 1 |
www |
1241 |
return $item;
|
|
|
1242 |
}
|
| 16322 |
anderson |
1243 |
|
| 1 |
www |
1244 |
/**
|
|
|
1245 |
*
|
|
|
1246 |
* @param int $comment_id
|
|
|
1247 |
* @return array
|
|
|
1248 |
*/
|
| 14740 |
efrain |
1249 |
private function renderComment($comment_id, $now)
|
| 1 |
www |
1250 |
{
|
|
|
1251 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1252 |
$currentUser = $currentUserPlugin->getUser();
|
| 16322 |
anderson |
1253 |
|
| 15351 |
efrain |
1254 |
$currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
|
|
|
1255 |
$network = $currentNetworkPlugin->getNetwork();
|
| 16322 |
anderson |
1256 |
|
|
|
1257 |
|
| 1 |
www |
1258 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 16322 |
anderson |
1259 |
|
| 1 |
www |
1260 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1261 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
| 15351 |
efrain |
1262 |
|
| 16322 |
anderson |
1263 |
|
| 1 |
www |
1264 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
| 16322 |
anderson |
1265 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
1266 |
|
|
|
1267 |
|
|
|
1268 |
|
|
|
1269 |
|
|
|
1270 |
|
|
|
1271 |
|
| 1 |
www |
1272 |
$item = [];
|
| 16322 |
anderson |
1273 |
|
| 1 |
www |
1274 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
1275 |
$record = $commentMapper->fetchOne($comment_id);
|
| 16322 |
anderson |
1276 |
|
| 1 |
www |
1277 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1278 |
$feed = $feedMapper->fetchOne($record->feed_id);
|
| 16322 |
anderson |
1279 |
|
|
|
1280 |
if ($record) {
|
| 17008 |
efrain |
1281 |
$userMapper = \LeadersLinked\Mapper\UserMapper::getInstance($this->adapter);
|
| 14740 |
efrain |
1282 |
|
| 16322 |
anderson |
1283 |
|
| 1 |
www |
1284 |
$item = [];
|
|
|
1285 |
$item['unique'] = uniqid();
|
| 16322 |
anderson |
1286 |
|
| 17018 |
efrain |
1287 |
$storage = Storage::getInstance($this->config, $this->adapter);
|
| 17002 |
efrain |
1288 |
|
| 16322 |
anderson |
1289 |
|
| 1 |
www |
1290 |
$user = $userMapper->fetchOne($record->user_id);
|
| 16322 |
anderson |
1291 |
if ($user->id == $owner->user_id) {
|
| 17002 |
efrain |
1292 |
$item['user_image'] = $storage->getCompanyImage($company);
|
| 16322 |
anderson |
1293 |
$item['user_url'] = 'https://' . $network->main_hostname . '/company/view/' . $company->uuid;
|
| 1 |
www |
1294 |
$item['user_name'] = $company->name;
|
|
|
1295 |
} else {
|
| 17002 |
efrain |
1296 |
$item['user_image'] = $storage->getUserImage($user);
|
| 16322 |
anderson |
1297 |
$item['user_url'] = 'https://' . $network->main_hostname . '/profile/view/' . $user->uuid;
|
| 1 |
www |
1298 |
$item['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
1299 |
}
|
| 16322 |
anderson |
1300 |
|
|
|
1301 |
|
|
|
1302 |
|
|
|
1303 |
$item['link_answer_add'] = $this->url()->fromRoute('feeds/comments/answer', ['id' => $feed->uuid, 'comment' => $record->uuid]);
|
|
|
1304 |
$item['link_delete'] = $this->url()->fromRoute('feeds/comments/delete', ['id' => $feed->uuid, 'comment' => $record->uuid]);
|
| 14740 |
efrain |
1305 |
$item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
|
| 1 |
www |
1306 |
$item['comment'] = $record->comment;
|
|
|
1307 |
}
|
|
|
1308 |
return $item;
|
|
|
1309 |
}
|
| 16322 |
anderson |
1310 |
|
| 1 |
www |
1311 |
/**
|
|
|
1312 |
*
|
|
|
1313 |
* @param string $path
|
|
|
1314 |
* @return boolean
|
|
|
1315 |
*/
|
|
|
1316 |
private function deletePath($path)
|
|
|
1317 |
{
|
|
|
1318 |
try {
|
| 16322 |
anderson |
1319 |
if (is_dir($path)) {
|
| 1 |
www |
1320 |
if ($dh = opendir($path)) {
|
| 16322 |
anderson |
1321 |
while (($file = readdir($dh)) !== false) {
|
|
|
1322 |
if ($file == '.' || $file == '..') {
|
| 1 |
www |
1323 |
continue;
|
|
|
1324 |
}
|
|
|
1325 |
unlink($path . DIRECTORY_SEPARATOR . $file);
|
|
|
1326 |
}
|
|
|
1327 |
closedir($dh);
|
|
|
1328 |
}
|
| 16322 |
anderson |
1329 |
|
| 1 |
www |
1330 |
rmdir($path);
|
|
|
1331 |
}
|
|
|
1332 |
return true;
|
| 16322 |
anderson |
1333 |
} catch (\Throwable $e) {
|
| 1 |
www |
1334 |
error_log($e->getTraceAsString());
|
|
|
1335 |
return false;
|
|
|
1336 |
}
|
|
|
1337 |
}
|
|
|
1338 |
}
|