| 1 |
www |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
*
|
|
|
4 |
* Controlador: Mis Perfiles
|
|
|
5 |
*
|
|
|
6 |
*/
|
|
|
7 |
declare(strict_types=1);
|
|
|
8 |
|
|
|
9 |
namespace LeadersLinked\Controller;
|
|
|
10 |
|
|
|
11 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
12 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
13 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
14 |
use Laminas\Log\LoggerInterface;
|
|
|
15 |
use Laminas\View\Model\ViewModel;
|
|
|
16 |
use Laminas\View\Model\JsonModel;
|
|
|
17 |
|
|
|
18 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
19 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
20 |
use LeadersLinked\Form\CreateFeedForm;
|
|
|
21 |
use LeadersLinked\Form\CommentForm;
|
| 8402 |
nelberth |
22 |
use LeadersLinked\Form\CommentAnswerForm;
|
| 1 |
www |
23 |
use LeadersLinked\Model\Comment;
|
|
|
24 |
use LeadersLinked\Mapper\CommentMapper;
|
|
|
25 |
use LeadersLinked\Mapper\FeedMapper;
|
|
|
26 |
use LeadersLinked\Mapper\GroupMapper;
|
|
|
27 |
use LeadersLinked\Model\Feed;
|
|
|
28 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
29 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
30 |
use LeadersLinked\Library\Image;
|
|
|
31 |
use LeadersLinked\Model\VideoConvert;
|
|
|
32 |
use LeadersLinked\Mapper\VideoConvertMapper;
|
|
|
33 |
use LeadersLinked\Mapper\LikeMapper;
|
|
|
34 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
35 |
use Laminas\Paginator\Paginator;
|
|
|
36 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
37 |
use LeadersLinked\Library\Functions;
|
|
|
38 |
use LeadersLinked\Model\Company;
|
|
|
39 |
use LeadersLinked\Model\UserType;
|
|
|
40 |
|
| 9537 |
nelberth |
41 |
use LeadersLinked\Mapper\TopicMapper;
|
| 7381 |
nelberth |
42 |
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
|
|
|
43 |
use LeadersLinked\Model\HighPerformanceTeamsGroups;
|
|
|
44 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
|
|
|
45 |
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
|
| 14740 |
efrain |
46 |
use LeadersLinked\Mapper\UtilMapper;
|
| 7381 |
nelberth |
47 |
|
| 1 |
www |
48 |
class FeedController extends AbstractActionController
|
|
|
49 |
{
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var AdapterInterface
|
|
|
53 |
*/
|
|
|
54 |
private $adapter;
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
*
|
|
|
59 |
* @var AbstractAdapter
|
|
|
60 |
*/
|
|
|
61 |
private $cache;
|
|
|
62 |
|
|
|
63 |
/**
|
|
|
64 |
*
|
|
|
65 |
* @var LoggerInterface
|
|
|
66 |
*/
|
|
|
67 |
private $logger;
|
|
|
68 |
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
*
|
|
|
72 |
* @var array
|
|
|
73 |
*/
|
|
|
74 |
private $config;
|
|
|
75 |
|
|
|
76 |
/**
|
|
|
77 |
*
|
|
|
78 |
* @param AdapterInterface $adapter
|
|
|
79 |
* @param AbstractAdapter $cache
|
|
|
80 |
* @param LoggerInterface $logger
|
|
|
81 |
* @param array $config
|
|
|
82 |
*/
|
|
|
83 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
84 |
{
|
|
|
85 |
$this->adapter = $adapter;
|
|
|
86 |
$this->cache = $cache;
|
|
|
87 |
$this->logger = $logger;
|
|
|
88 |
$this->config = $config;
|
|
|
89 |
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
*
|
|
|
94 |
* Generación del listado de perfiles
|
|
|
95 |
* {@inheritDoc}
|
|
|
96 |
* @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
|
|
|
97 |
*/
|
|
|
98 |
public function indexAction()
|
|
|
99 |
{
|
|
|
100 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
101 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
102 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
103 |
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
$request = $this->getRequest();
|
|
|
107 |
if($request->isGet()) {
|
|
|
108 |
$headers = $request->getHeaders();
|
|
|
109 |
|
|
|
110 |
$isJson = false;
|
|
|
111 |
if($headers->has('Accept')) {
|
|
|
112 |
$accept = $headers->get('Accept');
|
|
|
113 |
|
|
|
114 |
$prioritized = $accept->getPrioritized();
|
|
|
115 |
|
|
|
116 |
foreach($prioritized as $key => $value) {
|
|
|
117 |
$raw = trim($value->getRaw());
|
|
|
118 |
|
|
|
119 |
if(!$isJson) {
|
|
|
120 |
$isJson = strpos($raw, 'json');
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
}
|
|
|
124 |
}
|
|
|
125 |
|
| 7645 |
nelberth |
126 |
$formFeed = new CreateFeedForm($this->adapter);
|
| 1 |
www |
127 |
|
|
|
128 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
129 |
$viewModel = new ViewModel();
|
|
|
130 |
$viewModel->setTemplate('leaders-linked/feeds/index.phtml');
|
|
|
131 |
$viewModel->setVariables([
|
|
|
132 |
'formFeed' => $formFeed,
|
|
|
133 |
]);
|
|
|
134 |
return $viewModel ;
|
|
|
135 |
|
|
|
136 |
|
|
|
137 |
} else {
|
|
|
138 |
return new JsonModel([
|
|
|
139 |
'success' => false,
|
|
|
140 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
141 |
]);
|
|
|
142 |
}
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
public function commentAction()
|
|
|
147 |
{
|
| 8396 |
nelberth |
148 |
|
| 8394 |
nelberth |
149 |
|
| 1 |
www |
150 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
151 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
152 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
$id = $this->params()->fromRoute('id');
|
|
|
156 |
|
|
|
157 |
$request = $this->getRequest();
|
|
|
158 |
if($request->isPost()) {
|
|
|
159 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
160 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
161 |
if(!$feed) {
|
|
|
162 |
$response = [
|
|
|
163 |
'success' => false,
|
|
|
164 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
165 |
];
|
|
|
166 |
return new JsonModel($response);
|
|
|
167 |
}
|
| 8398 |
nelberth |
168 |
|
| 1 |
www |
169 |
if($feed->company_id != $currentCompany->id) {
|
|
|
170 |
$response = [
|
|
|
171 |
'success' => false,
|
|
|
172 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
173 |
];
|
|
|
174 |
return new JsonModel($response);
|
|
|
175 |
}
|
|
|
176 |
|
|
|
177 |
$dataPost = $request->getPost()->toArray();
|
|
|
178 |
$form = new CommentForm();
|
|
|
179 |
$form->setData($dataPost);
|
| 8399 |
nelberth |
180 |
|
| 1 |
www |
181 |
if($form->isValid()) {
|
| 14740 |
efrain |
182 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
183 |
$now = $utilMapper->getDatebaseNow();
|
| 8400 |
nelberth |
184 |
|
| 1 |
www |
185 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
186 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
187 |
|
|
|
188 |
$dataPost = (array) $form->getData();
|
|
|
189 |
$comment = new Comment();
|
|
|
190 |
$comment->comment = $dataPost['comment'];
|
|
|
191 |
$comment->feed_id = $feed->id;
|
|
|
192 |
|
| 8232 |
nelberth |
193 |
if($feed->type=='hptg'){
|
|
|
194 |
$comment->user_id = $currentUser->id;
|
| 11600 |
eleazar |
195 |
} else if($feed->type=='mytq'){
|
| 11420 |
eleazar |
196 |
$comment->user_id = $currentCompany->id;
|
| 11419 |
eleazar |
197 |
}
|
|
|
198 |
else{
|
| 8232 |
nelberth |
199 |
$comment->user_id = $owner->user_id;
|
|
|
200 |
}
|
|
|
201 |
|
| 1 |
www |
202 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
203 |
if($commentMapper->insert($comment)) {
|
|
|
204 |
|
|
|
205 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
206 |
|
|
|
207 |
$feed->total_comments = $total_comments;
|
|
|
208 |
$feedMapper->update($feed);
|
|
|
209 |
|
|
|
210 |
$response = [
|
|
|
211 |
'success' => true,
|
| 14740 |
efrain |
212 |
'data' => $this->renderComment($comment->id, $now),
|
| 1 |
www |
213 |
'total_comments' => $total_comments
|
|
|
214 |
];
|
|
|
215 |
|
|
|
216 |
return new JsonModel($response);
|
|
|
217 |
|
|
|
218 |
} else {
|
|
|
219 |
|
|
|
220 |
$response = [
|
|
|
221 |
'success' => false,
|
|
|
222 |
'data' => $commentMapper->getError()
|
|
|
223 |
];
|
|
|
224 |
|
|
|
225 |
return new JsonModel($response);
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
} else {
|
|
|
229 |
$message = '';;
|
|
|
230 |
$form_messages = (array) $form->getMessages();
|
|
|
231 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
232 |
{
|
|
|
233 |
foreach( $field_messages as $key => $value)
|
|
|
234 |
{
|
|
|
235 |
$message = $value;
|
|
|
236 |
}
|
|
|
237 |
}
|
|
|
238 |
|
|
|
239 |
$response = [
|
|
|
240 |
'success' => false,
|
|
|
241 |
'data' => $message
|
|
|
242 |
];
|
|
|
243 |
|
|
|
244 |
return new JsonModel($response);
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
|
|
|
248 |
} else {
|
|
|
249 |
$response = [
|
|
|
250 |
'success' => false,
|
|
|
251 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
252 |
];
|
|
|
253 |
|
|
|
254 |
return new JsonModel($response);
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
|
|
|
258 |
}
|
| 8390 |
nelberth |
259 |
|
| 8402 |
nelberth |
260 |
public function answerAction()
|
|
|
261 |
{
|
| 1 |
www |
262 |
|
| 8404 |
nelberth |
263 |
|
| 8402 |
nelberth |
264 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
265 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
266 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
$id = $this->params()->fromRoute('id');
|
|
|
270 |
$comment_uuid = $this->params()->fromRoute('comment');
|
| 8405 |
nelberth |
271 |
|
| 8402 |
nelberth |
272 |
$request = $this->getRequest();
|
|
|
273 |
if($request->isPost()) {
|
|
|
274 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
275 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
276 |
if(!$feed) {
|
|
|
277 |
$response = [
|
|
|
278 |
'success' => false,
|
|
|
279 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
280 |
];
|
|
|
281 |
return new JsonModel($response);
|
|
|
282 |
}
|
|
|
283 |
|
|
|
284 |
if($feed->company_id != $currentCompany->id) {
|
|
|
285 |
$response = [
|
|
|
286 |
'success' => false,
|
|
|
287 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
288 |
];
|
|
|
289 |
return new JsonModel($response);
|
|
|
290 |
}
|
| 8406 |
nelberth |
291 |
|
| 8402 |
nelberth |
292 |
$dataPost = $request->getPost()->toArray();
|
|
|
293 |
$form = new CommentAnswerForm();
|
|
|
294 |
$form->setData($dataPost);
|
|
|
295 |
|
|
|
296 |
if($form->isValid()) {
|
| 8407 |
nelberth |
297 |
|
| 14740 |
efrain |
298 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
299 |
$now = $utilMapper->getDatebaseNow();
|
|
|
300 |
|
| 8402 |
nelberth |
301 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
302 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
303 |
|
|
|
304 |
$dataPost = (array) $form->getData();
|
| 8408 |
nelberth |
305 |
$answer = new Comment();
|
|
|
306 |
$answer->comment = $dataPost['answer'];
|
|
|
307 |
$answer->feed_id = $feed->id;
|
| 8402 |
nelberth |
308 |
|
|
|
309 |
if($feed->type=='hptg'){
|
| 8408 |
nelberth |
310 |
$answer->user_id = $currentUser->id;
|
| 8402 |
nelberth |
311 |
|
|
|
312 |
}else{
|
| 8408 |
nelberth |
313 |
$answer->user_id = $owner->user_id;
|
| 8402 |
nelberth |
314 |
|
|
|
315 |
}
|
| 8408 |
nelberth |
316 |
|
|
|
317 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
318 |
$comment=$commentMapper->fetchOneByUuid($comment_uuid);
|
|
|
319 |
$answer->parent_id = $comment->id;
|
| 8402 |
nelberth |
320 |
|
| 8408 |
nelberth |
321 |
if($commentMapper->insert($answer)) {
|
| 8402 |
nelberth |
322 |
|
|
|
323 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
324 |
|
|
|
325 |
$feed->total_comments = $total_comments;
|
|
|
326 |
$feedMapper->update($feed);
|
|
|
327 |
|
|
|
328 |
$response = [
|
|
|
329 |
'success' => true,
|
| 14740 |
efrain |
330 |
'data' => $this->renderComment($answer->id, $now),
|
| 8402 |
nelberth |
331 |
'total_comments' => $total_comments
|
|
|
332 |
];
|
|
|
333 |
|
|
|
334 |
return new JsonModel($response);
|
|
|
335 |
|
|
|
336 |
} else {
|
|
|
337 |
|
|
|
338 |
$response = [
|
|
|
339 |
'success' => false,
|
|
|
340 |
'data' => $commentMapper->getError()
|
|
|
341 |
];
|
|
|
342 |
|
|
|
343 |
return new JsonModel($response);
|
|
|
344 |
}
|
|
|
345 |
|
|
|
346 |
} else {
|
|
|
347 |
$message = '';;
|
|
|
348 |
$form_messages = (array) $form->getMessages();
|
|
|
349 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
350 |
{
|
|
|
351 |
foreach( $field_messages as $key => $value)
|
|
|
352 |
{
|
|
|
353 |
$message = $value;
|
|
|
354 |
}
|
|
|
355 |
}
|
|
|
356 |
|
|
|
357 |
$response = [
|
|
|
358 |
'success' => false,
|
|
|
359 |
'data' => $message
|
|
|
360 |
];
|
|
|
361 |
|
|
|
362 |
return new JsonModel($response);
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
|
|
|
366 |
} else {
|
|
|
367 |
$response = [
|
|
|
368 |
'success' => false,
|
|
|
369 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
370 |
];
|
|
|
371 |
|
|
|
372 |
return new JsonModel($response);
|
|
|
373 |
}
|
|
|
374 |
|
|
|
375 |
|
|
|
376 |
}
|
|
|
377 |
|
| 1 |
www |
378 |
|
| 8402 |
nelberth |
379 |
|
| 1 |
www |
380 |
public function commentDeleteAction()
|
|
|
381 |
{
|
|
|
382 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
383 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
384 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
385 |
|
|
|
386 |
$request = $this->getRequest();
|
|
|
387 |
if($request->isPost()) {
|
|
|
388 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
389 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
390 |
|
|
|
391 |
$id = $this->params()->fromRoute('id');
|
|
|
392 |
$comment = $this->params()->fromRoute('comment');
|
|
|
393 |
|
|
|
394 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
395 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
396 |
if(!$feed) {
|
|
|
397 |
$response = [
|
|
|
398 |
'success' => false,
|
|
|
399 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
400 |
];
|
|
|
401 |
return new JsonModel($response);
|
|
|
402 |
}
|
|
|
403 |
|
|
|
404 |
if($feed->company_id != $currentCompany->id) {
|
|
|
405 |
$response = [
|
|
|
406 |
'success' => false,
|
|
|
407 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
408 |
];
|
|
|
409 |
return new JsonModel($response);
|
|
|
410 |
}
|
|
|
411 |
|
|
|
412 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
413 |
$comment = $commentMapper->fetchOneByUuid($comment);
|
|
|
414 |
|
|
|
415 |
if($comment && $comment->feed_id == $feed->id) {
|
|
|
416 |
$comment->status = Comment::STATUS_DELETED;
|
|
|
417 |
if($commentMapper->update($comment)) {
|
|
|
418 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
419 |
|
|
|
420 |
$feed = $feedMapper->fetchOne($comment->feed_id);
|
|
|
421 |
$feed->total_comments = $total_comments;
|
|
|
422 |
$feedMapper->update($feed);
|
|
|
423 |
|
|
|
424 |
|
|
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
|
428 |
$response = [
|
|
|
429 |
'success' => true,
|
|
|
430 |
'data' => [
|
|
|
431 |
'message' => 'LABEL_COMMENT_WAS_DELETED',
|
|
|
432 |
'total_comments' => $total_comments
|
|
|
433 |
]
|
|
|
434 |
];
|
|
|
435 |
} else {
|
|
|
436 |
$response = [
|
|
|
437 |
'success' => false,
|
|
|
438 |
'data' => $commentMapper->getError()
|
|
|
439 |
];
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
} else {
|
|
|
443 |
$response = [
|
|
|
444 |
'success' => false,
|
|
|
445 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
446 |
];
|
|
|
447 |
}
|
|
|
448 |
|
|
|
449 |
} else {
|
|
|
450 |
$response = [
|
|
|
451 |
'success' => false,
|
|
|
452 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
453 |
];
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
return new JsonModel($response);
|
|
|
457 |
}
|
|
|
458 |
|
|
|
459 |
public function deleteAction()
|
|
|
460 |
{
|
|
|
461 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
462 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
463 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
464 |
|
|
|
465 |
$request = $this->getRequest();
|
|
|
466 |
if($request->isPost()) {
|
|
|
467 |
|
|
|
468 |
|
|
|
469 |
$id = $this->params()->fromRoute('id');
|
|
|
470 |
|
|
|
471 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
472 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
473 |
if(!$feed) {
|
|
|
474 |
$response = [
|
|
|
475 |
'success' => false,
|
|
|
476 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
477 |
];
|
|
|
478 |
return new JsonModel($response);
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
if($feed->company_id != $currentCompany->id) {
|
|
|
482 |
$response = [
|
|
|
483 |
'success' => false,
|
|
|
484 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
485 |
];
|
|
|
486 |
return new JsonModel($response);
|
|
|
487 |
}
|
|
|
488 |
|
|
|
489 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
490 |
$feed->status = Feed::STATUS_DELETED;
|
|
|
491 |
if($feedMapper->update($feed)) {
|
|
|
492 |
$response = [
|
|
|
493 |
'success' => true,
|
|
|
494 |
'data' => 'LABEL_FEED_WAS_DELETED'
|
|
|
495 |
];
|
|
|
496 |
|
|
|
497 |
} else {
|
|
|
498 |
$response = [
|
|
|
499 |
'success' => false,
|
|
|
500 |
'data' => $feedMapper->getError()
|
|
|
501 |
];
|
|
|
502 |
}
|
|
|
503 |
|
|
|
504 |
|
|
|
505 |
return new JsonModel($response);
|
|
|
506 |
|
|
|
507 |
} else {
|
|
|
508 |
$response = [
|
|
|
509 |
'success' => false,
|
|
|
510 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
511 |
];
|
|
|
512 |
}
|
|
|
513 |
|
|
|
514 |
return new JsonModel($response);
|
|
|
515 |
}
|
|
|
516 |
|
|
|
517 |
public function addAction()
|
|
|
518 |
{
|
| 14740 |
efrain |
519 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
520 |
$now = $utilMapper->getDatebaseNow();
|
|
|
521 |
|
| 1 |
www |
522 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
523 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
524 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 10970 |
eleazar |
525 |
$myt_id = $this->params()->fromRoute('myt_id');
|
| 11122 |
nelberth |
526 |
$hptg_uuid = $this->params()->fromRoute('hptg_id');
|
| 7403 |
nelberth |
527 |
|
|
|
528 |
$request = $this->getRequest();
|
|
|
529 |
if($request->isPost()) {
|
| 7653 |
nelberth |
530 |
|
|
|
531 |
|
|
|
532 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
|
|
533 |
|
|
|
534 |
$form = new CreateFeedForm($this->adapter);
|
| 7654 |
nelberth |
535 |
|
| 1 |
www |
536 |
$form->setData($dataPost);
|
| 7673 |
nelberth |
537 |
|
| 1 |
www |
538 |
if($form->isValid()) {
|
|
|
539 |
|
| 7680 |
nelberth |
540 |
|
| 1 |
www |
541 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
542 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
543 |
|
|
|
544 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
545 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($company->id);
|
|
|
546 |
|
| 9049 |
nelberth |
547 |
$dataPost['priority'] = isset($dataPost['priority']) ? Feed::PRIORITY_URGENT : '';
|
| 9050 |
nelberth |
548 |
|
| 7408 |
nelberth |
549 |
|
| 1 |
www |
550 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
551 |
$feed = new Feed();
|
|
|
552 |
$hydrator->hydrate($dataPost, $feed);
|
| 11122 |
nelberth |
553 |
if($hptg_uuid){
|
| 7407 |
nelberth |
554 |
|
| 11122 |
nelberth |
555 |
|
| 8612 |
nelberth |
556 |
|
| 7409 |
nelberth |
557 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 11122 |
nelberth |
558 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($hptg_uuid);
|
| 7414 |
nelberth |
559 |
|
| 7409 |
nelberth |
560 |
if (!$highPerformanceTeamsGroups) {
|
|
|
561 |
$data = [
|
|
|
562 |
'success' => false,
|
| 7414 |
nelberth |
563 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 7409 |
nelberth |
564 |
];
|
| 7407 |
nelberth |
565 |
|
| 7409 |
nelberth |
566 |
return new JsonModel($data);
|
|
|
567 |
}
|
|
|
568 |
|
|
|
569 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
570 |
|
|
|
571 |
return new JsonModel([
|
|
|
572 |
'success' => false,
|
| 7414 |
nelberth |
573 |
'data' => 'ERROR_UNAUTHORIZED'
|
| 7409 |
nelberth |
574 |
]);
|
|
|
575 |
|
|
|
576 |
}
|
|
|
577 |
|
|
|
578 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
579 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
580 |
if($highPerformanceTeamsGroupsMember) {
|
| 7413 |
nelberth |
581 |
if($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN ){
|
|
|
582 |
$id = $highPerformanceTeamsGroups->id;
|
|
|
583 |
}else{
|
|
|
584 |
|
|
|
585 |
return new JsonModel([
|
|
|
586 |
'success' => false,
|
|
|
587 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
588 |
]);
|
|
|
589 |
}
|
| 7409 |
nelberth |
590 |
|
|
|
591 |
} else {
|
|
|
592 |
|
|
|
593 |
return new JsonModel([
|
|
|
594 |
'success' => false,
|
| 7414 |
nelberth |
595 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 7409 |
nelberth |
596 |
]);
|
|
|
597 |
}
|
| 11126 |
nelberth |
598 |
$topic_uuid = $this->params()->fromRoute('topic_id');
|
|
|
599 |
if($topic_uuid){
|
| 9539 |
nelberth |
600 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
| 11126 |
nelberth |
601 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
| 9537 |
nelberth |
602 |
if($topic){
|
| 9569 |
nelberth |
603 |
$feed->topic_id = $topic->id;
|
| 7644 |
nelberth |
604 |
}else{
|
|
|
605 |
return new JsonModel([
|
|
|
606 |
'success' => false,
|
|
|
607 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
608 |
]);
|
|
|
609 |
}
|
| 9572 |
nelberth |
610 |
|
| 7644 |
nelberth |
611 |
}
|
| 9544 |
nelberth |
612 |
|
| 7409 |
nelberth |
613 |
|
|
|
614 |
$feed->company_id = $currentCompany->id;
|
|
|
615 |
$feed->group_id = null;
|
|
|
616 |
$feed->high_performance_group_id = $id;
|
| 8222 |
nelberth |
617 |
$feed->user_id = $currentUser->id;
|
| 7409 |
nelberth |
618 |
$feed->type = Feed::TYPE_HPTG;
|
|
|
619 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
620 |
$feed->shared_with = Feed::SHARE_WITH_CONNECTIONS;
|
|
|
621 |
|
| 11600 |
eleazar |
622 |
} else if($myt_id){
|
| 10985 |
eleazar |
623 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
624 |
$myt = $feedMapper->fetchOneByUuid($myt_id);
|
| 10601 |
eleazar |
625 |
$feed->company_id = $currentCompany->id;
|
| 10981 |
eleazar |
626 |
$feed->group_id = null;
|
| 10601 |
eleazar |
627 |
$feed->user_id = $owner->user_id;
|
| 10985 |
eleazar |
628 |
$feed->myt_id = $myt->id;
|
| 10988 |
eleazar |
629 |
$feed->related_feed = $myt->id;
|
| 11491 |
eleazar |
630 |
$feed->type = Feed::TYPE_MYT_ANSWER;
|
| 10601 |
eleazar |
631 |
$feed->posted_or_shared = Feed::POSTED;
|
| 10680 |
eleazar |
632 |
$feed->shared_with = Feed::SHARE_WITH_PUBLIC;
|
| 7407 |
nelberth |
633 |
}else{
|
|
|
634 |
$feed->company_id = $currentCompany->id;
|
|
|
635 |
$feed->group_id = null;
|
|
|
636 |
$feed->user_id = $owner->user_id;
|
|
|
637 |
$feed->type = Feed::TYPE_COMPANY;
|
|
|
638 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
639 |
$feed->shared_with = Feed::SHARE_WITH_CONNECTIONS;
|
|
|
640 |
}
|
| 1 |
www |
641 |
|
|
|
642 |
|
|
|
643 |
|
| 9545 |
nelberth |
644 |
|
| 1 |
www |
645 |
$feed->total_comments = 0;
|
|
|
646 |
$feed->total_shared = 0;
|
|
|
647 |
|
|
|
648 |
|
|
|
649 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
650 |
$file_type = '';
|
|
|
651 |
if(isset($files['file']) && empty($files['file']['error'])) {
|
|
|
652 |
$feed_tmp_filename = $files['file']['tmp_name'];
|
|
|
653 |
$feed_filename = $this->normalizeString($files['file']['name']);
|
|
|
654 |
|
|
|
655 |
$mime_type = mime_content_type($feed_tmp_filename);
|
|
|
656 |
if($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
|
|
|
657 |
$file_type = Feed::FILE_TYPE_IMAGE;
|
|
|
658 |
} else if($mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
|
|
|
659 |
$file_type = Feed::FILE_TYPE_VIDEO;
|
|
|
660 |
} else if($mime_type == 'application/pdf') {
|
|
|
661 |
$file_type = Feed::FILE_TYPE_DOCUMENT;
|
|
|
662 |
}
|
|
|
663 |
}
|
| 9549 |
nelberth |
664 |
|
| 1 |
www |
665 |
|
|
|
666 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
667 |
$result = $feedMapper->insert($feed);
|
| 9565 |
nelberth |
668 |
|
| 9551 |
nelberth |
669 |
|
| 1 |
www |
670 |
if($result) {
|
| 9552 |
nelberth |
671 |
|
|
|
672 |
$feed = $feedMapper->fetchOne($feed->id);
|
| 9553 |
nelberth |
673 |
|
| 1 |
www |
674 |
if( $file_type == Feed::FILE_TYPE_DOCUMENT) {
|
|
|
675 |
try {
|
|
|
676 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid;
|
|
|
677 |
if(!file_exists($target_path)) {
|
|
|
678 |
mkdir($target_path, 0755);
|
|
|
679 |
}
|
|
|
680 |
|
|
|
681 |
$full_filename = $target_path . DIRECTORY_SEPARATOR .$feed_filename;
|
|
|
682 |
$result = move_uploaded_file($feed_tmp_filename , $full_filename);
|
|
|
683 |
if($result) {
|
|
|
684 |
|
|
|
685 |
$feed->file_type = $file_type;
|
|
|
686 |
$feed->file_name = basename($feed_filename);
|
|
|
687 |
$feedMapper->update($feed);
|
|
|
688 |
} else {
|
|
|
689 |
error_log('no se pudo mover o renombrar el documento : ' . $feed_tmp_filename . ' al directorio : ' . $full_filename );
|
|
|
690 |
}
|
|
|
691 |
} catch(\Throwable $e) {
|
|
|
692 |
error_log($e->getTraceAsString());
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
if( $file_type == Feed::FILE_TYPE_IMAGE) {
|
|
|
696 |
try {
|
|
|
697 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid;
|
|
|
698 |
if(!file_exists($target_path)) {
|
|
|
699 |
mkdir($target_path, 0755);
|
|
|
700 |
}
|
|
|
701 |
|
|
|
702 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.feed_image_size']);
|
|
|
703 |
|
|
|
704 |
$feed_filename = substr($feed_filename, 0, strrpos($feed_filename, '.')) . '.png';
|
|
|
705 |
$crop_to_dimensions = false;
|
|
|
706 |
if(Image::uploadImage($feed_tmp_filename, $target_path, $feed_filename, $target_width, $target_height, $crop_to_dimensions )) {
|
|
|
707 |
$feed->file_type = $file_type;
|
|
|
708 |
$feed->file_name = basename($feed_filename);
|
|
|
709 |
$feedMapper->update($feed);
|
|
|
710 |
}
|
|
|
711 |
} catch(\Throwable $e) {
|
|
|
712 |
error_log($e->getTraceAsString());
|
|
|
713 |
}
|
|
|
714 |
}
|
|
|
715 |
if( $file_type == Feed::FILE_TYPE_VIDEO) {
|
|
|
716 |
try {
|
|
|
717 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid;
|
|
|
718 |
if(!file_exists($target_path)) {
|
|
|
719 |
mkdir($target_path, 0755);
|
|
|
720 |
}
|
|
|
721 |
|
|
|
722 |
$full_filename = $target_path . DIRECTORY_SEPARATOR . $feed_filename;
|
|
|
723 |
|
|
|
724 |
$result = move_uploaded_file($feed_tmp_filename , $full_filename);
|
|
|
725 |
if($result) {
|
|
|
726 |
|
|
|
727 |
$size = $this->config['leaderslinked.image_sizes.feed_image_size'];
|
|
|
728 |
$getFromSecound = 2;
|
|
|
729 |
|
|
|
730 |
//extracción del cover
|
|
|
731 |
$generateFileName = substr($feed_filename, 0, strrpos($feed_filename, '.'));
|
|
|
732 |
$generateFile = $target_path . DIRECTORY_SEPARATOR . $generateFileName . '.png';
|
|
|
733 |
$cmd = "/usr/bin/ffmpeg -i $full_filename -an -ss $getFromSecound -s $size $generateFile";
|
|
|
734 |
exec($cmd);
|
|
|
735 |
|
|
|
736 |
|
|
|
737 |
$feed->file_type = $file_type;
|
|
|
738 |
$feed->file_name = basename($feed_filename);
|
|
|
739 |
$feed->file_image_preview = basename($generateFile);
|
|
|
740 |
$feedMapper->update($feed);
|
|
|
741 |
|
|
|
742 |
$videoConvert = new VideoConvert();
|
|
|
743 |
$videoConvert->filename = $full_filename;
|
|
|
744 |
$videoConvert->type = VideoConvert::TYPE_FEED;
|
|
|
745 |
|
|
|
746 |
$videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
|
|
|
747 |
$videoConvertMapper->insert($videoConvert);
|
|
|
748 |
} else {
|
|
|
749 |
error_log('no se pudo mover o renombrar el documento : ' . $feed_tmp_filename . ' al directorio : ' . $full_filename );
|
|
|
750 |
}
|
|
|
751 |
} catch(\Throwable $e) {
|
|
|
752 |
error_log($e->getTraceAsString());
|
|
|
753 |
}
|
|
|
754 |
}
|
|
|
755 |
|
| 9564 |
nelberth |
756 |
|
| 9557 |
nelberth |
757 |
$response = [
|
|
|
758 |
'success' => true,
|
| 14740 |
efrain |
759 |
'data' => $this->renderFeed($feed->id, $now)
|
| 9557 |
nelberth |
760 |
];
|
| 9558 |
nelberth |
761 |
|
| 1 |
www |
762 |
} else {
|
|
|
763 |
$response = [
|
|
|
764 |
'success' => false,
|
|
|
765 |
'data' => $feedMapper->getError()
|
|
|
766 |
];
|
|
|
767 |
}
|
|
|
768 |
} else {
|
|
|
769 |
$messages = [];
|
|
|
770 |
$form_messages = (array) $form->getMessages();
|
|
|
771 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
772 |
{
|
|
|
773 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
774 |
}
|
|
|
775 |
|
|
|
776 |
$response = [
|
|
|
777 |
'success' => false,
|
|
|
778 |
'data' => $messages
|
|
|
779 |
];
|
|
|
780 |
}
|
|
|
781 |
|
|
|
782 |
} else {
|
|
|
783 |
$response = [
|
|
|
784 |
'success' => false,
|
|
|
785 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
786 |
];
|
|
|
787 |
}
|
|
|
788 |
|
|
|
789 |
return new JsonModel($response);
|
|
|
790 |
}
|
|
|
791 |
|
|
|
792 |
|
| 14740 |
efrain |
793 |
public function timelineAction()
|
|
|
794 |
{
|
| 11112 |
nelberth |
795 |
|
| 14740 |
efrain |
796 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
797 |
$now = $utilMapper->getDatebaseNow();
|
|
|
798 |
|
| 1 |
www |
799 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
800 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
801 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 8679 |
nelberth |
802 |
|
| 7366 |
nelberth |
803 |
|
| 7381 |
nelberth |
804 |
|
| 7378 |
nelberth |
805 |
|
| 7357 |
nelberth |
806 |
|
| 7366 |
nelberth |
807 |
$request = $this->getRequest();
|
| 1 |
www |
808 |
if($request->isGet()) {
|
| 8672 |
nelberth |
809 |
|
| 8673 |
nelberth |
810 |
|
| 8672 |
nelberth |
811 |
$page = (int) $this->params()->fromQuery('page');
|
|
|
812 |
$type = $this->params()->fromRoute('type');
|
| 11091 |
nelberth |
813 |
$topic_uuid = $this->params()->fromRoute('topic_id');
|
| 8672 |
nelberth |
814 |
$urgent = $this->params()->fromRoute('urgent');
|
| 10820 |
eleazar |
815 |
$myt_id = $this->params()->fromRoute('myt_id');
|
| 11098 |
nelberth |
816 |
$hptg_uuid = $this->params()->fromRoute('hptg_id');
|
| 11108 |
nelberth |
817 |
|
| 11109 |
nelberth |
818 |
|
| 11098 |
nelberth |
819 |
if($hptg_uuid){
|
| 11113 |
nelberth |
820 |
|
| 11114 |
nelberth |
821 |
|
| 7381 |
nelberth |
822 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 11098 |
nelberth |
823 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($hptg_uuid);
|
| 7425 |
nelberth |
824 |
|
| 7414 |
nelberth |
825 |
if (!$highPerformanceTeamsGroups) {
|
|
|
826 |
$data = [
|
|
|
827 |
'success' => false,
|
|
|
828 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
829 |
];
|
|
|
830 |
|
|
|
831 |
return new JsonModel($data);
|
|
|
832 |
}
|
|
|
833 |
|
|
|
834 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
835 |
|
|
|
836 |
return new JsonModel([
|
|
|
837 |
'success' => false,
|
|
|
838 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
839 |
]);
|
|
|
840 |
|
|
|
841 |
}
|
|
|
842 |
|
|
|
843 |
$highPerformanceTeamsGroupsMemberMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
844 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMemberMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
845 |
if($highPerformanceTeamsGroupsMember) {
|
|
|
846 |
if($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN ){
|
| 7701 |
nelberth |
847 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
848 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
849 |
$select->columns(['id']);
|
|
|
850 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
|
|
851 |
$select->where->equalTo('company_id',$currentCompany->id);
|
|
|
852 |
$select->where->equalTo('high_performance_group_id',$highPerformanceTeamsGroups->id);
|
| 8739 |
nelberth |
853 |
|
| 8737 |
nelberth |
854 |
|
| 7643 |
nelberth |
855 |
if(isset($topic_uuid)){
|
| 9539 |
nelberth |
856 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
|
|
857 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
| 9537 |
nelberth |
858 |
if($topic){
|
|
|
859 |
if($topic->status!='a'){
|
| 7766 |
nelberth |
860 |
return new JsonModel([
|
|
|
861 |
'success' => false,
|
|
|
862 |
'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
|
|
|
863 |
]);
|
|
|
864 |
}
|
| 9569 |
nelberth |
865 |
$select->where->equalTo('topic_id',$topic->id);
|
| 7701 |
nelberth |
866 |
|
| 7643 |
nelberth |
867 |
}else{
|
|
|
868 |
return new JsonModel([
|
|
|
869 |
'success' => false,
|
| 8689 |
nelberth |
870 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
| 7643 |
nelberth |
871 |
]);
|
|
|
872 |
}
|
| 7701 |
nelberth |
873 |
}else{
|
| 8739 |
nelberth |
874 |
if(isset($urgent)){
|
|
|
875 |
$select->where->equalTo('priority', Feed::PRIORITY_URGENT);
|
|
|
876 |
}else{
|
| 9569 |
nelberth |
877 |
$select->where->IsNull('topic_id');
|
| 8739 |
nelberth |
878 |
}
|
| 7701 |
nelberth |
879 |
|
| 7643 |
nelberth |
880 |
}
|
| 7701 |
nelberth |
881 |
|
|
|
882 |
|
| 7420 |
nelberth |
883 |
$select->where->and->equalTo('type', Feed::TYPE_HPTG);
|
|
|
884 |
$select->order('added_on desc');
|
|
|
885 |
|
| 7414 |
nelberth |
886 |
}else{
|
|
|
887 |
return new JsonModel([
|
|
|
888 |
'success' => false,
|
|
|
889 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
890 |
]);
|
|
|
891 |
}
|
|
|
892 |
|
| 7381 |
nelberth |
893 |
} else {
|
| 7414 |
nelberth |
894 |
|
|
|
895 |
return new JsonModel([
|
|
|
896 |
'success' => false,
|
|
|
897 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
898 |
]);
|
| 7381 |
nelberth |
899 |
}
|
| 7379 |
nelberth |
900 |
|
| 7381 |
nelberth |
901 |
|
| 7414 |
nelberth |
902 |
|
| 7420 |
nelberth |
903 |
|
| 7381 |
nelberth |
904 |
|
| 11115 |
nelberth |
905 |
}else if($myt_id){
|
| 10990 |
eleazar |
906 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
907 |
$myt = $feedMapper->fetchOneByUuid($myt_id);
|
| 10601 |
eleazar |
908 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
909 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
910 |
$select->columns(['id']);
|
|
|
911 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
|
|
912 |
$select->where->equalTo('company_id',$currentCompany->id);
|
| 10992 |
eleazar |
913 |
$select->where->equalTo('myt_id', $myt->id);
|
| 11001 |
eleazar |
914 |
$select->where->and->equalTo('type', Feed::TYPE_MYT_ANSWER);
|
| 10601 |
eleazar |
915 |
$select->order('added_on desc');
|
| 10557 |
eleazar |
916 |
|
| 7350 |
nelberth |
917 |
}else{
|
| 7380 |
nelberth |
918 |
|
| 7350 |
nelberth |
919 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
920 |
$select = $queryMapper->getSql()->select(FeedMapper::_TABLE);
|
|
|
921 |
$select->columns(['id']);
|
|
|
922 |
$select->where->equalTo('status', Feed::STATUS_PUBLISHED);
|
|
|
923 |
$select->where->equalTo('company_id',$currentCompany->id);
|
|
|
924 |
$select->where->and->equalTo('type', Feed::TYPE_COMPANY);
|
|
|
925 |
$select->order('added_on desc');
|
|
|
926 |
}
|
|
|
927 |
|
| 1 |
www |
928 |
|
|
|
929 |
|
|
|
930 |
$dbSelect = new DbSelect($select, $this->adapter);
|
|
|
931 |
$paginator = new Paginator($dbSelect);
|
|
|
932 |
$paginator->setCurrentPageNumber($page ? $page : 1);
|
|
|
933 |
$paginator->setItemCountPerPage(10);
|
|
|
934 |
|
|
|
935 |
$items = [];
|
|
|
936 |
$feeds = $paginator->getCurrentItems();
|
| 10400 |
nelberth |
937 |
|
| 1 |
www |
938 |
foreach($feeds as $feed)
|
|
|
939 |
{
|
| 14740 |
efrain |
940 |
$items[] = $this->renderFeed($feed->id, $now);
|
| 1 |
www |
941 |
}
|
|
|
942 |
|
|
|
943 |
$response = [
|
|
|
944 |
'success' => true,
|
|
|
945 |
'data' => [
|
|
|
946 |
'total' => [
|
|
|
947 |
'count' => $paginator->getTotalItemCount(),
|
|
|
948 |
'pages' => $paginator->getPages()->pageCount,
|
|
|
949 |
],
|
|
|
950 |
'current' => [
|
|
|
951 |
'items' => $items,
|
|
|
952 |
'page' => $paginator->getCurrentPageNumber(),
|
|
|
953 |
'count' => $paginator->getCurrentItemCount(),
|
|
|
954 |
]
|
|
|
955 |
]
|
|
|
956 |
];
|
|
|
957 |
|
|
|
958 |
return new JsonModel($response);
|
|
|
959 |
}
|
|
|
960 |
|
|
|
961 |
$response = [
|
|
|
962 |
'success' => false,
|
|
|
963 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
964 |
];
|
|
|
965 |
|
|
|
966 |
|
|
|
967 |
return new JsonModel($response);
|
|
|
968 |
}
|
|
|
969 |
|
| 14740 |
efrain |
970 |
public function oneFeedAction()
|
|
|
971 |
{
|
|
|
972 |
$utilMapper = UtilMapper::getInstance($this->adapter);
|
|
|
973 |
$now = $utilMapper->getDatebaseNow();
|
|
|
974 |
|
|
|
975 |
|
| 10118 |
nelberth |
976 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
977 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
978 |
$currentCompany = $currentUserPlugin->getCompany();
|
| 11331 |
eleazar |
979 |
|
| 10118 |
nelberth |
980 |
$request = $this->getRequest();
|
|
|
981 |
if($request->isGet()) {
|
|
|
982 |
|
| 11725 |
eleazar |
983 |
$feed_uuid = $this->params()->fromRoute('id');
|
|
|
984 |
$myt_id = $this->params()->fromRoute('id');
|
| 10118 |
nelberth |
985 |
|
| 11331 |
eleazar |
986 |
if(!isset($feed_uuid)){
|
|
|
987 |
$data = [
|
|
|
988 |
'success' => false,
|
|
|
989 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
990 |
];
|
|
|
991 |
|
|
|
992 |
return new JsonModel($data);
|
|
|
993 |
}
|
| 10118 |
nelberth |
994 |
|
|
|
995 |
$items = [];
|
| 11331 |
eleazar |
996 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
997 |
$feed = $feedMapper->fetchOneByUuid($feed_uuid);
|
|
|
998 |
|
|
|
999 |
if (!$feed) {
|
|
|
1000 |
$data = [
|
|
|
1001 |
'success' => false,
|
|
|
1002 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1003 |
];
|
|
|
1004 |
|
|
|
1005 |
return new JsonModel($data);
|
|
|
1006 |
}
|
| 11195 |
eleazar |
1007 |
|
| 11536 |
eleazar |
1008 |
if ($feed->type=='mytq'){
|
| 11413 |
eleazar |
1009 |
|
| 14740 |
efrain |
1010 |
$items = $this->renderFeed($feed->id, $now, $myt_id);
|
| 11195 |
eleazar |
1011 |
|
| 11536 |
eleazar |
1012 |
$response = [
|
|
|
1013 |
'success' => true,
|
|
|
1014 |
'data' => [
|
|
|
1015 |
'item' =>$items,
|
|
|
1016 |
'feed_title'=>$feed->title,
|
|
|
1017 |
'topic_title'=>$feed->description
|
|
|
1018 |
]
|
|
|
1019 |
];
|
| 11195 |
eleazar |
1020 |
|
| 11600 |
eleazar |
1021 |
} else if ($feed->type=='myta'){
|
| 11519 |
eleazar |
1022 |
|
| 14740 |
efrain |
1023 |
$items = $this->renderFeed($feed->id, $now, $myt_id);
|
| 11519 |
eleazar |
1024 |
|
|
|
1025 |
$response = [
|
|
|
1026 |
'success' => true,
|
|
|
1027 |
'data' => [
|
|
|
1028 |
'item' =>$items,
|
|
|
1029 |
'feed_title'=>$feed->title,
|
|
|
1030 |
'topic_title'=>$feed->description
|
|
|
1031 |
]
|
|
|
1032 |
];
|
|
|
1033 |
|
| 11600 |
eleazar |
1034 |
}else if($feed->type=='hptg'){
|
| 11519 |
eleazar |
1035 |
|
| 11404 |
eleazar |
1036 |
$group_uuid = $this->params()->fromRoute('group_id');
|
|
|
1037 |
$topic_uuid = $this->params()->fromRoute('topic_id');
|
| 10118 |
nelberth |
1038 |
|
| 11404 |
eleazar |
1039 |
if(!isset($topic_uuid)){
|
| 10118 |
nelberth |
1040 |
|
| 11404 |
eleazar |
1041 |
$data = [
|
|
|
1042 |
'success' => false,
|
|
|
1043 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1044 |
];
|
| 10118 |
nelberth |
1045 |
|
| 11404 |
eleazar |
1046 |
return new JsonModel($data);
|
|
|
1047 |
}
|
|
|
1048 |
if(!isset($group_uuid)){
|
| 10118 |
nelberth |
1049 |
|
| 11404 |
eleazar |
1050 |
$data = [
|
|
|
1051 |
'success' => false,
|
|
|
1052 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
1053 |
];
|
| 10118 |
nelberth |
1054 |
|
| 11404 |
eleazar |
1055 |
return new JsonModel($data);
|
|
|
1056 |
}
|
|
|
1057 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
|
|
1058 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
|
| 10118 |
nelberth |
1059 |
|
| 11404 |
eleazar |
1060 |
if (!$highPerformanceTeamsGroups) {
|
|
|
1061 |
$data = [
|
|
|
1062 |
'success' => false,
|
|
|
1063 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1064 |
];
|
| 10118 |
nelberth |
1065 |
|
| 11404 |
eleazar |
1066 |
return new JsonModel($data);
|
|
|
1067 |
}
|
| 10118 |
nelberth |
1068 |
|
|
|
1069 |
|
| 11404 |
eleazar |
1070 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
| 10118 |
nelberth |
1071 |
|
| 11404 |
eleazar |
1072 |
return new JsonModel([
|
|
|
1073 |
'success' => false,
|
|
|
1074 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1075 |
]);
|
| 10118 |
nelberth |
1076 |
|
| 11404 |
eleazar |
1077 |
}
|
| 10118 |
nelberth |
1078 |
|
| 11404 |
eleazar |
1079 |
if($feed->high_performance_group_id!=$highPerformanceTeamsGroups->id){
|
|
|
1080 |
return new JsonModel([
|
|
|
1081 |
'success' => false,
|
|
|
1082 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1083 |
]);
|
|
|
1084 |
}
|
| 10118 |
nelberth |
1085 |
|
| 11404 |
eleazar |
1086 |
$topicMapper = TopicMapper::getInstance($this->adapter);
|
|
|
1087 |
$topic = $topicMapper->fetchOneByUuid($topic_uuid);
|
| 10118 |
nelberth |
1088 |
|
| 11404 |
eleazar |
1089 |
if (!$topic) {
|
|
|
1090 |
$data = [
|
|
|
1091 |
'success' => false,
|
|
|
1092 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1093 |
];
|
| 10118 |
nelberth |
1094 |
|
| 11404 |
eleazar |
1095 |
return new JsonModel($data);
|
|
|
1096 |
}
|
| 10118 |
nelberth |
1097 |
|
| 11404 |
eleazar |
1098 |
if($feed->topic_id!=$topic->id){
|
|
|
1099 |
return new JsonModel([
|
|
|
1100 |
'success' => false,
|
|
|
1101 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
1102 |
]);
|
|
|
1103 |
}
|
| 10521 |
eleazar |
1104 |
|
| 14740 |
efrain |
1105 |
$items = $this->renderFeed($feed->id, $now, $group_uuid);
|
| 10118 |
nelberth |
1106 |
|
| 11404 |
eleazar |
1107 |
$response = [
|
|
|
1108 |
'success' => true,
|
|
|
1109 |
'data' => [
|
|
|
1110 |
'item' =>$items,
|
|
|
1111 |
'topic_title'=>$topic->title,
|
|
|
1112 |
'feed_title'=>$feed->title
|
|
|
1113 |
]
|
|
|
1114 |
];
|
|
|
1115 |
}
|
| 10118 |
nelberth |
1116 |
|
| 11331 |
eleazar |
1117 |
return new JsonModel($response);
|
| 11399 |
eleazar |
1118 |
}
|
| 10118 |
nelberth |
1119 |
}
|
| 1 |
www |
1120 |
/**
|
|
|
1121 |
*
|
|
|
1122 |
* @param string $str
|
|
|
1123 |
* @return string
|
|
|
1124 |
*/
|
| 10118 |
nelberth |
1125 |
private function normalizeString ($str = ''){
|
| 1 |
www |
1126 |
$basename = substr($str, 0, strrpos($str, '.'));
|
|
|
1127 |
$basename = str_replace('.', '-', $basename);
|
|
|
1128 |
|
|
|
1129 |
$extension = substr($str, strrpos($str, '.'));
|
|
|
1130 |
|
|
|
1131 |
$str = $basename . $extension;
|
|
|
1132 |
|
|
|
1133 |
$str = strip_tags($str);
|
|
|
1134 |
$str = preg_replace('/[\r\n\t ]+/', ' ', $str);
|
|
|
1135 |
$str = preg_replace('/[\"\*\/\:\<\>\?\'\|\,]+/', ' ', $str);
|
|
|
1136 |
$str = strtolower($str);
|
|
|
1137 |
$str = html_entity_decode( $str, ENT_QUOTES, "utf-8" );
|
|
|
1138 |
$str = htmlentities($str, ENT_QUOTES, "utf-8");
|
|
|
1139 |
$str = preg_replace("/(&)([a-z])([a-z]+;)/i", '$2', $str);
|
|
|
1140 |
$str = str_replace(' ', '-', $str);
|
|
|
1141 |
$str = rawurlencode($str);
|
|
|
1142 |
$str = str_replace('%', '-', $str);
|
|
|
1143 |
return trim(strtolower($str));
|
|
|
1144 |
}
|
|
|
1145 |
|
|
|
1146 |
|
|
|
1147 |
|
|
|
1148 |
/**
|
|
|
1149 |
*
|
|
|
1150 |
* @param int $feed_id
|
|
|
1151 |
* @param Company $company
|
|
|
1152 |
* @return array
|
|
|
1153 |
*/
|
| 14740 |
efrain |
1154 |
private function renderFeed($feed_id, $now , $group_uuid = '', $myt_id = '' )
|
| 1 |
www |
1155 |
{
|
| 9562 |
nelberth |
1156 |
|
| 1 |
www |
1157 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
|
|
1158 |
if($sandbox) {
|
|
|
1159 |
$company_profile_url = $this->config['leaderslinked.frontend.sandbox_company_profile'];
|
|
|
1160 |
$user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
|
|
|
1161 |
|
|
|
1162 |
} else {
|
|
|
1163 |
$company_profile_url = $this->config['leaderslinked.frontend.production_company_profile'];
|
|
|
1164 |
$user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
|
|
|
1165 |
}
|
|
|
1166 |
|
|
|
1167 |
|
|
|
1168 |
|
| 9561 |
nelberth |
1169 |
|
| 1 |
www |
1170 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1171 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1172 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1173 |
|
|
|
1174 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1175 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
1176 |
|
|
|
1177 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1178 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
1179 |
|
|
|
1180 |
|
|
|
1181 |
|
|
|
1182 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
1183 |
|
|
|
1184 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1185 |
$feed = $feedMapper->fetchOne($feed_id);
|
|
|
1186 |
|
|
|
1187 |
|
|
|
1188 |
$params = [
|
|
|
1189 |
'id' => $feed->uuid
|
|
|
1190 |
];
|
|
|
1191 |
|
|
|
1192 |
|
|
|
1193 |
$item = [
|
|
|
1194 |
'feed_unique' => uniqid(),
|
|
|
1195 |
'feed_uuid' => $feed->uuid,
|
| 8218 |
nelberth |
1196 |
'feed_delete_url' => $this->url()->fromRoute('feeds/delete', $params),
|
| 1 |
www |
1197 |
'feed_content_type' => $feed->file_type ? $feed->file_type : '',
|
| 8627 |
nelberth |
1198 |
'feed_priority'=> $feed->priority,
|
| 1 |
www |
1199 |
];
|
| 8205 |
nelberth |
1200 |
if($feed->type == Feed::TYPE_HPTG)
|
|
|
1201 |
{
|
| 10394 |
nelberth |
1202 |
|
| 11120 |
nelberth |
1203 |
$uuid = $this->params()->fromRoute('hptg_id');
|
| 11119 |
nelberth |
1204 |
if($group_uuid!=''){
|
|
|
1205 |
$uuid=$group_uuid;
|
|
|
1206 |
}
|
| 8217 |
nelberth |
1207 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1208 |
$user = $userMapper->fetchOne($feed->user_id);
|
| 8224 |
nelberth |
1209 |
$item['owner_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
| 8217 |
nelberth |
1210 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]);
|
|
|
1211 |
$item['owner_name'] = $user->first_name . ' ' . $user->last_name;
|
| 10406 |
nelberth |
1212 |
$highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
|
| 11119 |
nelberth |
1213 |
$highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($uuid);
|
| 10393 |
nelberth |
1214 |
|
|
|
1215 |
if (!$highPerformanceTeamsGroups) {
|
|
|
1216 |
$data = [
|
|
|
1217 |
'success' => false,
|
|
|
1218 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1219 |
];
|
|
|
1220 |
|
|
|
1221 |
return new JsonModel($data);
|
|
|
1222 |
}
|
|
|
1223 |
if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
|
|
|
1224 |
|
|
|
1225 |
return new JsonModel([
|
|
|
1226 |
'success' => false,
|
|
|
1227 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
1228 |
]);
|
|
|
1229 |
|
|
|
1230 |
}
|
| 10392 |
nelberth |
1231 |
$highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
|
|
|
1232 |
$highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
|
|
|
1233 |
if(!$highPerformanceTeamsGroupsMember) {
|
|
|
1234 |
return new JsonModel([
|
|
|
1235 |
'success' => false,
|
|
|
1236 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
1237 |
]);
|
|
|
1238 |
}
|
|
|
1239 |
if($feed->user_id == $currentUser->id||$highPerformanceTeamsGroupsMember->type!=HighPerformanceTeamsGroupsMembers::TYPE_USER) {
|
| 10391 |
nelberth |
1240 |
$item['feed_delete_url'] = $this->url()->fromRoute('feeds/delete', $params);
|
|
|
1241 |
}else{
|
|
|
1242 |
$item['feed_delete_url'] = '';
|
| 8217 |
nelberth |
1243 |
}
|
| 10406 |
nelberth |
1244 |
|
| 11600 |
eleazar |
1245 |
}else if($feed->type == Feed::TYPE_MYT_QUESTION){
|
| 11195 |
eleazar |
1246 |
$uuid = $this->params()->fromRoute('myt_id');
|
|
|
1247 |
if($myt_id!=''){
|
|
|
1248 |
$uuid=$myt_id;
|
|
|
1249 |
}
|
|
|
1250 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1251 |
$user = $userMapper->fetchOne($feed->user_id);
|
| 10620 |
eleazar |
1252 |
$item['feed_delete_url'] = $this->url()->fromRoute('feeds/delete', $params);
|
|
|
1253 |
$item['owner_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
1254 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $company->uuid, 'type' => 'user', 'filename' => $company->image]);
|
|
|
1255 |
$item['owner_name'] = $company->name;
|
| 11600 |
eleazar |
1256 |
} else if($feed->type == Feed::TYPE_MYT_ANSWER){
|
|
|
1257 |
$uuid = $this->params()->fromRoute('myt_id');
|
|
|
1258 |
if($myt_id!=''){
|
|
|
1259 |
$uuid=$myt_id;
|
|
|
1260 |
}
|
|
|
1261 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1262 |
$user = $userMapper->fetchOne($feed->user_id);
|
|
|
1263 |
$item['feed_delete_url'] = $this->url()->fromRoute('feeds/delete', $params);
|
|
|
1264 |
$item['owner_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
1265 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $company->uuid, 'type' => 'user', 'filename' => $company->image]);
|
|
|
1266 |
$item['owner_name'] = $company->name;
|
| 11519 |
eleazar |
1267 |
}else {
|
| 10402 |
nelberth |
1268 |
$item['feed_delete_url'] = $this->url()->fromRoute('feeds/delete', $params);
|
| 8205 |
nelberth |
1269 |
$item['owner_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
1270 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $company->uuid, 'type' => 'company', 'filename' => $company->image]);
|
|
|
1271 |
$item['owner_name'] = $company->name;
|
|
|
1272 |
}
|
| 1 |
www |
1273 |
|
|
|
1274 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1275 |
$user = $userMapper->fetchOne($feed->user_id);
|
|
|
1276 |
|
|
|
1277 |
|
| 7235 |
stevensc |
1278 |
$item['owner_description'] = strip_tags($feed->description, 'p');
|
| 1 |
www |
1279 |
$item['owner_shared'] = $feed->total_shared;
|
|
|
1280 |
$item['owner_comments'] = $feed->total_comments;
|
|
|
1281 |
|
|
|
1282 |
|
| 14740 |
efrain |
1283 |
$item['owner_time_elapse'] = Functions::timeAgo( $feed->added_on, $now);
|
| 1 |
www |
1284 |
|
|
|
1285 |
if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
|
|
|
1286 |
$item['owner_file_image'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_name]);
|
|
|
1287 |
|
|
|
1288 |
}
|
|
|
1289 |
if($feed->file_type == Feed::FILE_TYPE_DOCUMENT) {
|
|
|
1290 |
$item['owner_file_document'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_name]);
|
|
|
1291 |
}
|
|
|
1292 |
if($feed->file_type == Feed::FILE_TYPE_VIDEO) {
|
|
|
1293 |
$item['owner_file_image_preview'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_image_preview]);
|
|
|
1294 |
$item['owner_file_video'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_name]);
|
|
|
1295 |
}
|
| 9021 |
nelberth |
1296 |
if($feed->file_type == Feed::FILE_TYPE_MEETING) {
|
| 9081 |
nelberth |
1297 |
$dt = \DateTime::createFromFormat('Y-m-d', $feed->date);
|
| 9086 |
nelberth |
1298 |
$dt2 = \DateTime::createFromFormat('H:i:s', $feed->time);
|
| 9023 |
nelberth |
1299 |
$item['owner_meeting'] = true;
|
| 9082 |
nelberth |
1300 |
$item['owner_meeting_date'] = $dt->format('d/m/Y');
|
| 9088 |
nelberth |
1301 |
$item['owner_meeting_time'] = $dt2->format('h:i a');
|
| 9021 |
nelberth |
1302 |
$item['owner_meeting_link_type'] = $feed->link_type;
|
|
|
1303 |
$item['owner_meeting_link_name'] = $feed->link_name;
|
|
|
1304 |
|
|
|
1305 |
}
|
| 1 |
www |
1306 |
|
|
|
1307 |
|
|
|
1308 |
|
|
|
1309 |
|
|
|
1310 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
1311 |
$records = $commentMapper->fetchAllPublishedByFeedId($feed->id);
|
|
|
1312 |
|
|
|
1313 |
|
|
|
1314 |
$comments = [];
|
| 10073 |
nelberth |
1315 |
$comment_count=0;
|
| 1 |
www |
1316 |
foreach($records as $record)
|
|
|
1317 |
{
|
|
|
1318 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
1319 |
|
|
|
1320 |
$comment = [];
|
|
|
1321 |
$comment['unique'] = uniqid();
|
| 10073 |
nelberth |
1322 |
$comment_count++;
|
|
|
1323 |
$comment['comment_index']=$comment_count;
|
| 1 |
www |
1324 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
1325 |
if($user->id == $owner->user_id) {
|
|
|
1326 |
$comment['user_image'] = $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image ]);
|
|
|
1327 |
$comment['user_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
1328 |
$comment['user_name'] = $company->name;
|
|
|
1329 |
} else {
|
|
|
1330 |
$comment['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
|
|
1331 |
$comment['user_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
|
|
1332 |
$comment['user_name'] = $user->first_name . ' ' . $user->last_name;
|
| 10406 |
nelberth |
1333 |
}
|
| 10395 |
nelberth |
1334 |
if($feed->type == Feed::TYPE_HPTG)
|
|
|
1335 |
{
|
| 10397 |
nelberth |
1336 |
if($record->user_id == $currentUser->id||$highPerformanceTeamsGroupsMember->type!=HighPerformanceTeamsGroupsMembers::TYPE_USER) {
|
| 10395 |
nelberth |
1337 |
$comment['link_delete'] = $this->url()->fromRoute('feeds/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
|
|
1338 |
}else{
|
| 10398 |
nelberth |
1339 |
$comment['link_delete'] = '';
|
| 10395 |
nelberth |
1340 |
}
|
|
|
1341 |
}else{
|
|
|
1342 |
$comment['link_delete'] = $this->url()->fromRoute('feeds/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
|
|
1343 |
}
|
| 10406 |
nelberth |
1344 |
|
| 8385 |
nelberth |
1345 |
$comment['link_answer_add'] = $this->url()->fromRoute('feeds/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
| 14740 |
efrain |
1346 |
$comment['time_elapsed'] = Functions::timeAgo( $record->added_on, $now);
|
| 1 |
www |
1347 |
$comment['comment'] = $record->comment;
|
|
|
1348 |
|
| 8414 |
nelberth |
1349 |
$records2 = $commentMapper->fetchAllPublishedByCommentId($record->id);
|
|
|
1350 |
$answers = [];
|
| 8499 |
nelberth |
1351 |
$contador=0;
|
| 8414 |
nelberth |
1352 |
foreach($records2 as $record2)
|
|
|
1353 |
{
|
|
|
1354 |
$user = $userMapper->fetchOne($record2->user_id);
|
|
|
1355 |
|
| 14740 |
efrain |
1356 |
|
| 8414 |
nelberth |
1357 |
$answer = [];
|
|
|
1358 |
$answer['unique'] = uniqid();
|
|
|
1359 |
|
|
|
1360 |
|
|
|
1361 |
$user = $userMapper->fetchOne($record2->user_id);
|
|
|
1362 |
if($user->id == $owner->user_id) {
|
|
|
1363 |
$answer['user_image'] = $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image ]);
|
|
|
1364 |
$answer['user_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
1365 |
$answer['user_name'] = $company->name;
|
|
|
1366 |
} else {
|
|
|
1367 |
$answer['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
|
|
1368 |
$answer['user_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
|
|
1369 |
$answer['user_name'] = $user->first_name . ' ' . $user->last_name;
|
| 10406 |
nelberth |
1370 |
}
|
| 10398 |
nelberth |
1371 |
if($feed->type == Feed::TYPE_HPTG)
|
|
|
1372 |
{
|
| 10399 |
nelberth |
1373 |
if($record2->user_id == $currentUser->id||$highPerformanceTeamsGroupsMember->type!=HighPerformanceTeamsGroupsMembers::TYPE_USER) {
|
| 10398 |
nelberth |
1374 |
$answer['link_delete'] = $this->url()->fromRoute('feeds/comments/delete',['id' => $feed->uuid, 'comment' => $record2->uuid ]);
|
|
|
1375 |
}else{
|
|
|
1376 |
$answer['link_delete'] ='';
|
|
|
1377 |
}
|
|
|
1378 |
}else{
|
|
|
1379 |
$answer['link_delete'] = $this->url()->fromRoute('feeds/comments/delete',['id' => $feed->uuid, 'comment' => $record2->uuid ]);
|
|
|
1380 |
}
|
| 10406 |
nelberth |
1381 |
|
| 14740 |
efrain |
1382 |
$answer['time_elapsed'] = Functions::timeAgo($record2->added_on, $now);
|
| 8414 |
nelberth |
1383 |
$answer['comment'] = $record2->comment;
|
|
|
1384 |
|
|
|
1385 |
$records2 = $commentMapper->fetchAllPublishedByCommentId($record2->id);
|
|
|
1386 |
|
| 8499 |
nelberth |
1387 |
$contador++;
|
| 8414 |
nelberth |
1388 |
array_push($answers, $answer);
|
|
|
1389 |
}
|
| 8499 |
nelberth |
1390 |
$comment['number_answers']=$contador;
|
| 8416 |
nelberth |
1391 |
$comment['answers'] = $answers;
|
| 1 |
www |
1392 |
array_push($comments, $comment);
|
|
|
1393 |
}
|
|
|
1394 |
$item['comment_add_url'] = $this->url()->fromRoute('feeds/comments', ['id' => $feed->uuid]);
|
| 9064 |
nelberth |
1395 |
$item['comments'] = $comments;
|
| 1 |
www |
1396 |
|
| 9064 |
nelberth |
1397 |
|
| 9065 |
nelberth |
1398 |
|
| 1 |
www |
1399 |
return $item;
|
|
|
1400 |
}
|
|
|
1401 |
|
|
|
1402 |
/**
|
|
|
1403 |
*
|
|
|
1404 |
* @param int $comment_id
|
|
|
1405 |
* @return array
|
|
|
1406 |
*/
|
| 14740 |
efrain |
1407 |
private function renderComment($comment_id, $now)
|
| 1 |
www |
1408 |
{
|
|
|
1409 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
1410 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
1411 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
1412 |
|
|
|
1413 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
1414 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
1415 |
|
|
|
1416 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
1417 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
1418 |
|
|
|
1419 |
|
|
|
1420 |
|
|
|
1421 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
|
|
1422 |
if($sandbox) {
|
|
|
1423 |
$company_profile_url = $this->config['leaderslinked.frontend.sandbox_company_profile'];
|
|
|
1424 |
$user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
|
|
|
1425 |
} else {
|
|
|
1426 |
$company_profile_url = $this->config['leaderslinked.frontend.production_company_profile'];
|
|
|
1427 |
$user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
|
|
|
1428 |
}
|
|
|
1429 |
|
|
|
1430 |
|
|
|
1431 |
$item = [];
|
|
|
1432 |
|
|
|
1433 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
1434 |
$record = $commentMapper->fetchOne($comment_id);
|
|
|
1435 |
|
|
|
1436 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
1437 |
$feed = $feedMapper->fetchOne($record->feed_id);
|
|
|
1438 |
|
|
|
1439 |
if($record) {
|
|
|
1440 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
1441 |
|
| 14740 |
efrain |
1442 |
|
| 1 |
www |
1443 |
$item = [];
|
|
|
1444 |
$item['unique'] = uniqid();
|
|
|
1445 |
|
|
|
1446 |
|
|
|
1447 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
1448 |
if($user->id == $owner->user_id) {
|
|
|
1449 |
$item['user_image'] = $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image ]);
|
|
|
1450 |
$item['user_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
1451 |
$item['user_name'] = $company->name;
|
|
|
1452 |
} else {
|
|
|
1453 |
$item['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
|
|
1454 |
$item['user_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
|
|
1455 |
$item['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
1456 |
}
|
|
|
1457 |
|
|
|
1458 |
|
|
|
1459 |
|
| 8446 |
nelberth |
1460 |
$item['link_answer_add'] = $this->url()->fromRoute('feeds/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
| 1 |
www |
1461 |
$item['link_delete'] = $this->url()->fromRoute('feeds/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
| 14740 |
efrain |
1462 |
$item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
|
| 1 |
www |
1463 |
$item['comment'] = $record->comment;
|
|
|
1464 |
|
|
|
1465 |
}
|
|
|
1466 |
return $item;
|
|
|
1467 |
}
|
|
|
1468 |
|
|
|
1469 |
/**
|
|
|
1470 |
*
|
|
|
1471 |
* @param string $path
|
|
|
1472 |
* @return boolean
|
|
|
1473 |
*/
|
|
|
1474 |
private function deletePath($path)
|
|
|
1475 |
{
|
|
|
1476 |
try {
|
|
|
1477 |
if (is_dir($path)){
|
|
|
1478 |
if ($dh = opendir($path)) {
|
|
|
1479 |
while (($file = readdir($dh)) !== false)
|
|
|
1480 |
{
|
|
|
1481 |
if($file == '.' || $file == '..') {
|
|
|
1482 |
continue;
|
|
|
1483 |
}
|
|
|
1484 |
unlink($path . DIRECTORY_SEPARATOR . $file);
|
|
|
1485 |
}
|
|
|
1486 |
closedir($dh);
|
|
|
1487 |
}
|
|
|
1488 |
|
|
|
1489 |
rmdir($path);
|
|
|
1490 |
}
|
|
|
1491 |
return true;
|
|
|
1492 |
}
|
|
|
1493 |
catch (\Throwable $e)
|
|
|
1494 |
{
|
|
|
1495 |
error_log($e->getTraceAsString());
|
|
|
1496 |
return false;
|
|
|
1497 |
}
|
|
|
1498 |
}
|
|
|
1499 |
|
|
|
1500 |
}
|