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