10273 |
eleazar |
1 |
<?php
|
11317 |
eleazar |
2 |
declare(strict_types=1);
|
10273 |
eleazar |
3 |
|
11317 |
eleazar |
4 |
namespace LeadersLinked\Controller;
|
10273 |
eleazar |
5 |
|
11317 |
eleazar |
6 |
use Laminas\Authentication\AuthenticationService;
|
|
|
7 |
use Laminas\Authentication\Result as AuthResult;
|
|
|
8 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
9 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
10 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
11 |
use Laminas\Mvc\I18n\Translator;
|
11798 |
eleazar |
12 |
use LeadersLinked\Form\CommentForm;
|
|
|
13 |
use LeadersLinked\Form\CommentAnswerForm;
|
|
|
14 |
use LeadersLinked\Model\Comment;
|
|
|
15 |
use LeadersLinked\Mapper\CommentMapper;
|
|
|
16 |
use LeadersLinked\Mapper\FeedMapper;
|
|
|
17 |
use LeadersLinked\Mapper\GroupMapper;
|
11317 |
eleazar |
18 |
use Laminas\Log\LoggerInterface;
|
|
|
19 |
use Laminas\View\Model\ViewModel;
|
|
|
20 |
use Laminas\View\Model\JsonModel;
|
|
|
21 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
|
|
22 |
use LeadersLinked\Mapper\MyTrainerQuestionsMapper;
|
11791 |
eleazar |
23 |
use LeadersLinked\Mapper\CompanyUserMapper;
|
|
|
24 |
use LeadersLinked\Mapper\CompanyMapper;
|
11709 |
eleazar |
25 |
use LeadersLinked\Mapper\FeedTopicMapper;
|
11317 |
eleazar |
26 |
use LeadersLinked\Form\MyTrainerQuestionForm;
|
|
|
27 |
use LeadersLinked\Model\MyTrainerQuestions;
|
11795 |
eleazar |
28 |
use LeadersLinked\Library\Image;
|
|
|
29 |
use LeadersLinked\Model\VideoConvert;
|
|
|
30 |
use LeadersLinked\Mapper\VideoConvertMapper;
|
|
|
31 |
use LeadersLinked\Mapper\LikeMapper;
|
|
|
32 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
33 |
use Laminas\Paginator\Paginator;
|
|
|
34 |
use LeadersLinked\Mapper\UserMapper;
|
|
|
35 |
use LeadersLinked\Library\Functions;
|
|
|
36 |
use LeadersLinked\Model\Company;
|
|
|
37 |
use LeadersLinked\Model\UserType;
|
10601 |
eleazar |
38 |
|
11317 |
eleazar |
39 |
use LeadersLinked\Model\Feed;
|
11709 |
eleazar |
40 |
use LeadersLinked\Model\FeedTopic;
|
11317 |
eleazar |
41 |
use LeadersLinked\Form\CreateFeedForm;
|
|
|
42 |
use LeadersLinked\Form\TopicForm;
|
10601 |
eleazar |
43 |
|
11317 |
eleazar |
44 |
class MyTrainerAnswerController extends AbstractActionController
|
|
|
45 |
{
|
|
|
46 |
/**
|
|
|
47 |
*
|
|
|
48 |
* @var AdapterInterface
|
|
|
49 |
*/
|
|
|
50 |
private $adapter;
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
* @var AbstractAdapter
|
|
|
56 |
*/
|
|
|
57 |
private $cache;
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
*
|
|
|
61 |
* @var LoggerInterface
|
|
|
62 |
*/
|
|
|
63 |
private $logger;
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
*
|
|
|
67 |
* @var array
|
|
|
68 |
*/
|
|
|
69 |
private $config;
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
/**
|
|
|
74 |
*
|
|
|
75 |
* @param AdapterInterface $adapter
|
|
|
76 |
* @param AbstractAdapter $cache
|
|
|
77 |
* @param LoggerInterface $logger
|
|
|
78 |
* @param array $config
|
|
|
79 |
*/
|
|
|
80 |
public function __construct($adapter, $cache , $logger, $config)
|
|
|
81 |
{
|
|
|
82 |
$this->adapter = $adapter;
|
|
|
83 |
$this->cache = $cache;
|
|
|
84 |
$this->logger = $logger;
|
|
|
85 |
$this->config = $config;
|
|
|
86 |
|
|
|
87 |
|
10273 |
eleazar |
88 |
}
|
10601 |
eleazar |
89 |
|
11873 |
eleazar |
90 |
public function indexAction()
|
|
|
91 |
{
|
|
|
92 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
93 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
94 |
$currentCompany = $currentUserPlugin->getCompany();
|
11882 |
eleazar |
95 |
$id = $this->params()->fromRoute('id');
|
11873 |
eleazar |
96 |
|
|
|
97 |
|
11837 |
eleazar |
98 |
$request = $this->getRequest();
|
11873 |
eleazar |
99 |
if($request->isGet()) {
|
|
|
100 |
$headers = $request->getHeaders();
|
|
|
101 |
|
|
|
102 |
$isJson = false;
|
|
|
103 |
if($headers->has('Accept')) {
|
|
|
104 |
$accept = $headers->get('Accept');
|
|
|
105 |
|
|
|
106 |
$prioritized = $accept->getPrioritized();
|
|
|
107 |
|
|
|
108 |
foreach($prioritized as $key => $value) {
|
|
|
109 |
$raw = trim($value->getRaw());
|
|
|
110 |
|
|
|
111 |
if(!$isJson) {
|
|
|
112 |
$isJson = strpos($raw, 'json');
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
$form = new CreateFeedForm($this->adapter);
|
|
|
119 |
|
|
|
120 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
121 |
$viewModel = new ViewModel();
|
11877 |
eleazar |
122 |
$viewModel->setTemplate('leaders-linked/my-trainer-answer/index.phtml');
|
11873 |
eleazar |
123 |
$viewModel->setVariables([
|
11878 |
eleazar |
124 |
'form' => $form,
|
11882 |
eleazar |
125 |
'id' => $id,
|
11873 |
eleazar |
126 |
]);
|
|
|
127 |
return $viewModel ;
|
|
|
128 |
|
|
|
129 |
|
|
|
130 |
} else {
|
|
|
131 |
return new JsonModel([
|
|
|
132 |
'success' => false,
|
|
|
133 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
134 |
]);
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
public function feedAction(){
|
11317 |
eleazar |
139 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
11873 |
eleazar |
140 |
$currentUser = $currentUserPlugin->getUser();
|
11837 |
eleazar |
141 |
$currentCompany = $currentUserPlugin->getCompany();
|
11873 |
eleazar |
142 |
|
|
|
143 |
$request = $this->getRequest();
|
|
|
144 |
if($request->isGet()) {
|
|
|
145 |
|
|
|
146 |
$feed_uuid = $this->params()->fromRoute('id');
|
|
|
147 |
|
|
|
148 |
if(!isset($feed_uuid)){
|
|
|
149 |
$data = [
|
|
|
150 |
'success' => false,
|
|
|
151 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
152 |
];
|
|
|
153 |
|
|
|
154 |
return new JsonModel($data);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
$items = [];
|
|
|
158 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
159 |
$feed = $feedMapper->fetchOneByUuid($feed_uuid);
|
11876 |
eleazar |
160 |
|
11873 |
eleazar |
161 |
if (!$feed) {
|
|
|
162 |
$data = [
|
|
|
163 |
'success' => false,
|
|
|
164 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
165 |
];
|
|
|
166 |
|
|
|
167 |
return new JsonModel($data);
|
|
|
168 |
}
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
$items = $this->renderFeed($feed->id);
|
|
|
173 |
|
|
|
174 |
$response = [
|
|
|
175 |
'success' => true,
|
|
|
176 |
'data' => [
|
|
|
177 |
'item' =>$items,
|
|
|
178 |
'feed_title'=>$feed->title,
|
|
|
179 |
'topic_title'=>$feed->description
|
|
|
180 |
]
|
|
|
181 |
];
|
|
|
182 |
|
|
|
183 |
return new JsonModel($response);
|
|
|
184 |
}
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
// public function indexAction() {
|
|
|
188 |
// $request = $this->getRequest();
|
|
|
189 |
// $currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
190 |
// $currentCompany = $currentUserPlugin->getCompany();
|
|
|
191 |
// $currentUser = $currentUserPlugin->getUser();
|
|
|
192 |
// $id = $this->params()->fromRoute('id');
|
11837 |
eleazar |
193 |
|
11873 |
eleazar |
194 |
// $request = $this->getRequest();
|
11869 |
eleazar |
195 |
|
11873 |
eleazar |
196 |
// try{
|
|
|
197 |
// if($request->isGet()) {
|
11870 |
eleazar |
198 |
|
11873 |
eleazar |
199 |
// $id = $this->params()->fromRoute('id');
|
11871 |
eleazar |
200 |
|
11873 |
eleazar |
201 |
// $headers = $request->getHeaders();
|
|
|
202 |
// $isJson = false;
|
|
|
203 |
// if($headers->has('Accept')) {
|
|
|
204 |
// $accept = $headers->get('Accept');
|
11837 |
eleazar |
205 |
|
11873 |
eleazar |
206 |
// $prioritized = $accept->getPrioritized();
|
11837 |
eleazar |
207 |
|
11873 |
eleazar |
208 |
// foreach($prioritized as $key => $value) {
|
|
|
209 |
// $raw = trim($value->getRaw());
|
11837 |
eleazar |
210 |
|
11873 |
eleazar |
211 |
// if(!$isJson) {
|
|
|
212 |
// $isJson = strpos($raw, 'json');
|
|
|
213 |
// }
|
11837 |
eleazar |
214 |
|
11873 |
eleazar |
215 |
// }
|
|
|
216 |
// }
|
11872 |
eleazar |
217 |
|
11873 |
eleazar |
218 |
// $acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
219 |
// $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'my-trainer/question/answer/add');
|
|
|
220 |
// $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'my-trainer/question/answer/edit');
|
|
|
221 |
// $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'my-trainer/question/answer/delete');
|
11837 |
eleazar |
222 |
|
11873 |
eleazar |
223 |
// $form = new CreateFeedForm($this->adapter);
|
|
|
224 |
// $questionsMapper = FeedMapper::getInstance($this->adapter);
|
|
|
225 |
// $question = $questionsMapper->fetchOneByUuid($id);
|
11837 |
eleazar |
226 |
|
|
|
227 |
|
11873 |
eleazar |
228 |
// $answer = $questionsMapper->fetchAllByMytAnswer($question->related_feed);
|
11837 |
eleazar |
229 |
|
11873 |
eleazar |
230 |
// $items = $this->renderFeed($id);
|
11837 |
eleazar |
231 |
|
11873 |
eleazar |
232 |
// $response = [
|
|
|
233 |
// 'success' => true,
|
|
|
234 |
// 'data' => [
|
|
|
235 |
// 'item' =>$items,
|
|
|
236 |
// 'feed_title'=>$question->title,
|
|
|
237 |
// 'topic_title'=>$question->description
|
|
|
238 |
// ]
|
|
|
239 |
// ];
|
11872 |
eleazar |
240 |
|
11873 |
eleazar |
241 |
// return new JsonModel([
|
|
|
242 |
// 'success' => false,
|
|
|
243 |
// 'data' => $response
|
|
|
244 |
// ]);
|
11821 |
eleazar |
245 |
|
11873 |
eleazar |
246 |
// // $posts;
|
11837 |
eleazar |
247 |
|
11873 |
eleazar |
248 |
// $viewModel = new ViewModel();
|
|
|
249 |
// $this->layout()->setTemplate('layout/layout-backend');
|
|
|
250 |
// $viewModel->setTemplate('leaders-linked/my-trainer-answer/index.phtml');
|
|
|
251 |
// $viewModel->setVariables([
|
|
|
252 |
// 'form' => $form,
|
|
|
253 |
// 'id' => $id,
|
|
|
254 |
// 'question_title' => $question->title,
|
|
|
255 |
// 'question_description' => $question->description,
|
11837 |
eleazar |
256 |
|
11873 |
eleazar |
257 |
// ]);
|
|
|
258 |
// return $viewModel;
|
|
|
259 |
// } else {
|
|
|
260 |
// return new JsonModel([
|
|
|
261 |
// 'success' => false,
|
|
|
262 |
// 'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
263 |
// ]);
|
|
|
264 |
// }
|
11813 |
eleazar |
265 |
|
11802 |
eleazar |
266 |
|
11873 |
eleazar |
267 |
// return new JsonModel($response);
|
|
|
268 |
// } catch (\Throwable $e) {
|
|
|
269 |
// $e->getMessage();
|
|
|
270 |
// return new JsonModel([
|
|
|
271 |
// 'success' => false,
|
|
|
272 |
// 'data' => $e
|
|
|
273 |
// ]);
|
|
|
274 |
// }
|
|
|
275 |
// }
|
11336 |
eleazar |
276 |
|
|
|
277 |
public function addAction() {
|
|
|
278 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
279 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
280 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
281 |
|
11787 |
eleazar |
282 |
$id = $this->params()->fromRoute('id');
|
11343 |
eleazar |
283 |
$questionsMapper = FeedMapper::getInstance($this->adapter);
|
11787 |
eleazar |
284 |
$question = $questionsMapper->fetchOneByUuid($id);
|
11336 |
eleazar |
285 |
$request = $this->getRequest();
|
|
|
286 |
try{
|
|
|
287 |
if($request->isPost()) {
|
|
|
288 |
$form = new CreateFeedForm($this->adapter);
|
11710 |
eleazar |
289 |
|
|
|
290 |
$dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
|
11336 |
eleazar |
291 |
$categoriesId = $dataPost['category_id'] ?? [];
|
|
|
292 |
$dataPost['category_id'] = null;
|
|
|
293 |
$form->setData($dataPost);
|
|
|
294 |
|
|
|
295 |
if($form->isValid()) {
|
|
|
296 |
|
|
|
297 |
$dataPost = (array) $form->getData();
|
|
|
298 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
299 |
$feed = new Feed();
|
|
|
300 |
$hydrator->hydrate($dataPost, $feed);
|
|
|
301 |
|
|
|
302 |
$feed->user_id = $currentUser->id;
|
|
|
303 |
$feed->company_id = $currentCompany->id;
|
|
|
304 |
$feed->user_id = $currentUser->id;
|
11343 |
eleazar |
305 |
$feed->type = Feed::TYPE_MYT_ANSWER;
|
11336 |
eleazar |
306 |
$feed->posted_or_shared = Feed::POSTED;
|
|
|
307 |
$feed->shared_with = Feed::SHARE_WITH_PUBLIC;
|
11343 |
eleazar |
308 |
$feed->related_feed = $question->id;
|
11336 |
eleazar |
309 |
|
11710 |
eleazar |
310 |
$feed->total_comments = 0;
|
|
|
311 |
$feed->total_shared = 0;
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
315 |
$file_type = '';
|
|
|
316 |
if(isset($files['file']) && empty($files['file']['error'])) {
|
|
|
317 |
$feed_tmp_filename = $files['file']['tmp_name'];
|
|
|
318 |
$feed_filename = $this->normalizeString($files['file']['name']);
|
|
|
319 |
|
|
|
320 |
$mime_type = mime_content_type($feed_tmp_filename);
|
|
|
321 |
if($mime_type == 'image/jpg' || $mime_type == 'image/jpeg' || $mime_type == 'image/png') {
|
|
|
322 |
$file_type = Feed::FILE_TYPE_IMAGE;
|
|
|
323 |
} else if($mime_type == 'video/webm' || $mime_type == 'video/mpeg' || $mime_type == 'video/mpg' || $mime_type == 'video/mp4') {
|
|
|
324 |
$file_type = Feed::FILE_TYPE_VIDEO;
|
|
|
325 |
} else if($mime_type == 'application/pdf') {
|
|
|
326 |
$file_type = Feed::FILE_TYPE_DOCUMENT;
|
|
|
327 |
}
|
|
|
328 |
}
|
|
|
329 |
|
11336 |
eleazar |
330 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
331 |
|
|
|
332 |
if($feedMapper->insert($feed)) {
|
11343 |
eleazar |
333 |
$feed = $feedMapper->fetchOne($feed->id);
|
|
|
334 |
$category = new FeedTopic();
|
|
|
335 |
$feedMapper->update($feed);
|
11705 |
eleazar |
336 |
|
11336 |
eleazar |
337 |
|
11705 |
eleazar |
338 |
$feed = $feedMapper->fetchOne($feed->id);
|
|
|
339 |
|
|
|
340 |
if( $file_type == Feed::FILE_TYPE_DOCUMENT) {
|
|
|
341 |
try {
|
|
|
342 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid;
|
|
|
343 |
if(!file_exists($target_path)) {
|
|
|
344 |
mkdir($target_path, 0755);
|
|
|
345 |
}
|
|
|
346 |
|
|
|
347 |
$full_filename = $target_path . DIRECTORY_SEPARATOR .$feed_filename;
|
|
|
348 |
$result = move_uploaded_file($feed_tmp_filename , $full_filename);
|
|
|
349 |
if($result) {
|
|
|
350 |
|
|
|
351 |
$feed->file_type = $file_type;
|
|
|
352 |
$feed->file_name = basename($feed_filename);
|
|
|
353 |
$feedMapper->update($feed);
|
|
|
354 |
} else {
|
|
|
355 |
error_log('no se pudo mover o renombrar el documento : ' . $feed_tmp_filename . ' al directorio : ' . $full_filename );
|
|
|
356 |
}
|
|
|
357 |
} catch(\Throwable $e) {
|
|
|
358 |
error_log($e->getTraceAsString());
|
|
|
359 |
}
|
|
|
360 |
}
|
|
|
361 |
if( $file_type == Feed::FILE_TYPE_IMAGE) {
|
|
|
362 |
try {
|
|
|
363 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid;
|
|
|
364 |
if(!file_exists($target_path)) {
|
|
|
365 |
mkdir($target_path, 0755);
|
|
|
366 |
}
|
|
|
367 |
|
|
|
368 |
list($target_width, $target_height) = explode('x', $this->config['leaderslinked.image_sizes.feed_image_size']);
|
|
|
369 |
|
|
|
370 |
$feed_filename = substr($feed_filename, 0, strrpos($feed_filename, '.')) . '.png';
|
|
|
371 |
$crop_to_dimensions = false;
|
|
|
372 |
if(Image::uploadImage($feed_tmp_filename, $target_path, $feed_filename, $target_width, $target_height, $crop_to_dimensions )) {
|
|
|
373 |
$feed->file_type = $file_type;
|
|
|
374 |
$feed->file_name = basename($feed_filename);
|
|
|
375 |
$feedMapper->update($feed);
|
|
|
376 |
}
|
|
|
377 |
} catch(\Throwable $e) {
|
|
|
378 |
error_log($e->getTraceAsString());
|
|
|
379 |
}
|
|
|
380 |
}
|
|
|
381 |
if( $file_type == Feed::FILE_TYPE_VIDEO) {
|
|
|
382 |
try {
|
|
|
383 |
$target_path = $this->config['leaderslinked.fullpath.feed'] . $feed->uuid;
|
|
|
384 |
if(!file_exists($target_path)) {
|
|
|
385 |
mkdir($target_path, 0755);
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
$full_filename = $target_path . DIRECTORY_SEPARATOR . $feed_filename;
|
|
|
389 |
|
|
|
390 |
$result = move_uploaded_file($feed_tmp_filename , $full_filename);
|
|
|
391 |
if($result) {
|
|
|
392 |
|
|
|
393 |
$size = $this->config['leaderslinked.image_sizes.feed_image_size'];
|
|
|
394 |
$getFromSecound = 2;
|
|
|
395 |
|
|
|
396 |
//extracción del cover
|
|
|
397 |
$generateFileName = substr($feed_filename, 0, strrpos($feed_filename, '.'));
|
|
|
398 |
$generateFile = $target_path . DIRECTORY_SEPARATOR . $generateFileName . '.png';
|
|
|
399 |
$cmd = "/usr/bin/ffmpeg -i $full_filename -an -ss $getFromSecound -s $size $generateFile";
|
|
|
400 |
exec($cmd);
|
|
|
401 |
|
|
|
402 |
|
|
|
403 |
$feed->file_type = $file_type;
|
|
|
404 |
$feed->file_name = basename($feed_filename);
|
|
|
405 |
$feed->file_image_preview = basename($generateFile);
|
|
|
406 |
$feedMapper->update($feed);
|
|
|
407 |
|
|
|
408 |
$videoConvert = new VideoConvert();
|
|
|
409 |
$videoConvert->filename = $full_filename;
|
|
|
410 |
$videoConvert->type = VideoConvert::TYPE_FEED;
|
|
|
411 |
|
|
|
412 |
$videoConvertMapper = VideoConvertMapper::getInstance($this->adapter);
|
|
|
413 |
$videoConvertMapper->insert($videoConvert);
|
|
|
414 |
} else {
|
|
|
415 |
error_log('no se pudo mover o renombrar el documento : ' . $feed_tmp_filename . ' al directorio : ' . $full_filename );
|
|
|
416 |
}
|
|
|
417 |
} catch(\Throwable $e) {
|
|
|
418 |
error_log($e->getTraceAsString());
|
|
|
419 |
}
|
|
|
420 |
}
|
11714 |
eleazar |
421 |
|
|
|
422 |
|
|
|
423 |
$response = [
|
|
|
424 |
'success' => true,
|
|
|
425 |
'data' => 'success'
|
|
|
426 |
];
|
11336 |
eleazar |
427 |
} else {
|
11705 |
eleazar |
428 |
$messages = [];
|
|
|
429 |
$form_messages = (array) $form->getMessages();
|
|
|
430 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
431 |
{
|
|
|
432 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
433 |
}
|
|
|
434 |
|
11336 |
eleazar |
435 |
}
|
|
|
436 |
|
|
|
437 |
} else {
|
11705 |
eleazar |
438 |
$response = [
|
|
|
439 |
'success' => false,
|
|
|
440 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
441 |
];
|
11336 |
eleazar |
442 |
}
|
|
|
443 |
|
11714 |
eleazar |
444 |
return new JsonModel($response);
|
11336 |
eleazar |
445 |
}
|
|
|
446 |
|
|
|
447 |
} catch (\Throwable $e) {
|
|
|
448 |
$e->getMessage();
|
|
|
449 |
return new JsonModel([
|
|
|
450 |
'success' => false,
|
|
|
451 |
'data' => $e
|
|
|
452 |
]);
|
|
|
453 |
}
|
|
|
454 |
}
|
11791 |
eleazar |
455 |
|
11793 |
eleazar |
456 |
private function renderFeed($id){
|
11791 |
eleazar |
457 |
|
11885 |
eleazar |
458 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
|
|
459 |
if($sandbox) {
|
|
|
460 |
$company_profile_url = $this->config['leaderslinked.frontend.sandbox_company_profile'];
|
|
|
461 |
$user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
|
|
|
462 |
|
|
|
463 |
} else {
|
|
|
464 |
$company_profile_url = $this->config['leaderslinked.frontend.production_company_profile'];
|
|
|
465 |
$user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
|
|
|
466 |
}
|
11791 |
eleazar |
467 |
|
|
|
468 |
|
|
|
469 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
470 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
471 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
472 |
|
|
|
473 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
474 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
475 |
|
|
|
476 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
477 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
478 |
|
|
|
479 |
|
|
|
480 |
|
|
|
481 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
482 |
|
|
|
483 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
11794 |
eleazar |
484 |
$feed = $feedMapper->fetchOne($id);
|
11817 |
eleazar |
485 |
|
11791 |
eleazar |
486 |
|
|
|
487 |
$params = [
|
11859 |
eleazar |
488 |
'id' => $id,
|
11791 |
eleazar |
489 |
];
|
|
|
490 |
|
|
|
491 |
$item = [
|
|
|
492 |
'feed_unique' => uniqid(),
|
|
|
493 |
'feed_uuid' => $feed->uuid,
|
11859 |
eleazar |
494 |
'feed_delete_url' => $this->url()->fromRoute('my-trainer/question/answer/delete', $params),
|
11791 |
eleazar |
495 |
'feed_content_type' => $feed->file_type ? $feed->file_type : '',
|
|
|
496 |
'feed_priority'=> $feed->priority,
|
|
|
497 |
];
|
|
|
498 |
|
|
|
499 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
500 |
$user = $userMapper->fetchOne($feed->user_id);
|
11854 |
eleazar |
501 |
$item['feed_delete_url'] = $this->url()->fromRoute('my-trainer/question/answer/delete', $params);
|
11791 |
eleazar |
502 |
$item['owner_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
503 |
$item['owner_image'] = $this->url()->fromRoute('storage', ['code' => $company->uuid, 'type' => 'user', 'filename' => $company->image]);
|
|
|
504 |
$item['owner_name'] = $company->name;
|
|
|
505 |
|
|
|
506 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $feed->added_on);
|
|
|
507 |
$item['owner_time_elapse'] = Functions::timeElapsedString( $dt->getTimestamp());
|
|
|
508 |
|
|
|
509 |
if($feed->file_type == Feed::FILE_TYPE_IMAGE) {
|
|
|
510 |
$item['owner_file_image'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_name]);
|
|
|
511 |
|
|
|
512 |
}
|
|
|
513 |
if($feed->file_type == Feed::FILE_TYPE_DOCUMENT) {
|
|
|
514 |
$item['owner_file_document'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_name]);
|
|
|
515 |
}
|
|
|
516 |
if($feed->file_type == Feed::FILE_TYPE_VIDEO) {
|
|
|
517 |
$item['owner_file_image_preview'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_image_preview]);
|
|
|
518 |
$item['owner_file_video'] = $this->url()->fromRoute('storage', ['code' => $feed->uuid, 'type' => 'feed', 'filename' => $feed->file_name]);
|
|
|
519 |
}
|
|
|
520 |
if($feed->file_type == Feed::FILE_TYPE_MEETING) {
|
|
|
521 |
$dt = \DateTime::createFromFormat('Y-m-d', $feed->date);
|
|
|
522 |
$dt2 = \DateTime::createFromFormat('H:i:s', $feed->time);
|
|
|
523 |
$item['owner_meeting'] = true;
|
|
|
524 |
$item['owner_meeting_date'] = $dt->format('d/m/Y');
|
|
|
525 |
$item['owner_meeting_time'] = $dt2->format('h:i a');
|
|
|
526 |
$item['owner_meeting_link_type'] = $feed->link_type;
|
|
|
527 |
$item['owner_meeting_link_name'] = $feed->link_name;
|
|
|
528 |
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
532 |
$records = $commentMapper->fetchAllPublishedByFeedId($feed->id);
|
|
|
533 |
|
|
|
534 |
|
|
|
535 |
$comments = [];
|
|
|
536 |
$comment_count=0;
|
|
|
537 |
foreach($records as $record)
|
|
|
538 |
{
|
|
|
539 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
540 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
|
|
|
541 |
|
|
|
542 |
$comment = [];
|
|
|
543 |
$comment['unique'] = uniqid();
|
|
|
544 |
$comment_count++;
|
|
|
545 |
$comment['comment_index']=$comment_count;
|
|
|
546 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
547 |
if($user->id == $owner->user_id) {
|
|
|
548 |
$comment['user_image'] = $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image ]);
|
|
|
549 |
$comment['user_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
550 |
$comment['user_name'] = $company->name;
|
|
|
551 |
} else {
|
|
|
552 |
$comment['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
|
|
553 |
$comment['user_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
|
|
554 |
$comment['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
555 |
}
|
11854 |
eleazar |
556 |
$comment['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
11791 |
eleazar |
557 |
|
|
|
558 |
|
11854 |
eleazar |
559 |
$comment['link_answer_add'] = $this->url()->fromRoute('my-trainer/question/answer/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
11791 |
eleazar |
560 |
$comment['time_elapsed'] = Functions::timeElapsedString($dt->getTimestamp());
|
|
|
561 |
$comment['comment'] = $record->comment;
|
|
|
562 |
|
|
|
563 |
$records2 = $commentMapper->fetchAllPublishedByCommentId($record->id);
|
|
|
564 |
$answers = [];
|
|
|
565 |
$contador=0;
|
|
|
566 |
foreach($records2 as $record2)
|
|
|
567 |
{
|
|
|
568 |
$user = $userMapper->fetchOne($record2->user_id);
|
|
|
569 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record2->added_on);
|
|
|
570 |
|
|
|
571 |
$answer = [];
|
|
|
572 |
$answer['unique'] = uniqid();
|
|
|
573 |
|
|
|
574 |
|
|
|
575 |
$user = $userMapper->fetchOne($record2->user_id);
|
|
|
576 |
if($user->id == $owner->user_id) {
|
|
|
577 |
$answer['user_image'] = $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image ]);
|
|
|
578 |
$answer['user_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
579 |
$answer['user_name'] = $company->name;
|
|
|
580 |
} else {
|
|
|
581 |
$answer['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
|
|
582 |
$answer['user_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
|
|
583 |
$answer['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
584 |
}
|
|
|
585 |
|
11854 |
eleazar |
586 |
$answer['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record2->uuid ]);
|
11791 |
eleazar |
587 |
|
|
|
588 |
|
|
|
589 |
$answer['time_elapsed'] = Functions::timeElapsedString($dt->getTimestamp());
|
|
|
590 |
$answer['comment'] = $record2->comment;
|
|
|
591 |
|
|
|
592 |
$records2 = $commentMapper->fetchAllPublishedByCommentId($record2->id);
|
|
|
593 |
|
|
|
594 |
$contador++;
|
|
|
595 |
array_push($answers, $answer);
|
|
|
596 |
}
|
|
|
597 |
$comment['number_answers']=$contador;
|
|
|
598 |
$comment['answers'] = $answers;
|
|
|
599 |
array_push($comments, $comment);
|
|
|
600 |
}
|
11854 |
eleazar |
601 |
$item['comment_add_url'] = $this->url()->fromRoute('my-trainer/question/answer/comments', ['id' => $feed->uuid]);
|
11791 |
eleazar |
602 |
$item['comments'] = $comments;
|
|
|
603 |
|
|
|
604 |
|
|
|
605 |
|
|
|
606 |
return $item;
|
|
|
607 |
}
|
11809 |
eleazar |
608 |
|
|
|
609 |
public function commentAction()
|
|
|
610 |
{
|
|
|
611 |
|
|
|
612 |
|
|
|
613 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
614 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
615 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
616 |
|
|
|
617 |
|
|
|
618 |
$id = $this->params()->fromRoute('id');
|
|
|
619 |
|
|
|
620 |
$request = $this->getRequest();
|
|
|
621 |
if($request->isPost()) {
|
|
|
622 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
623 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
624 |
if(!$feed) {
|
|
|
625 |
$response = [
|
|
|
626 |
'success' => false,
|
|
|
627 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
628 |
];
|
|
|
629 |
return new JsonModel($response);
|
|
|
630 |
}
|
|
|
631 |
|
|
|
632 |
if($feed->company_id != $currentCompany->id) {
|
|
|
633 |
$response = [
|
|
|
634 |
'success' => false,
|
|
|
635 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
636 |
];
|
|
|
637 |
return new JsonModel($response);
|
|
|
638 |
}
|
|
|
639 |
|
|
|
640 |
$dataPost = $request->getPost()->toArray();
|
|
|
641 |
$form = new CommentForm();
|
|
|
642 |
$form->setData($dataPost);
|
|
|
643 |
|
|
|
644 |
if($form->isValid()) {
|
|
|
645 |
|
|
|
646 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
647 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
648 |
|
|
|
649 |
$dataPost = (array) $form->getData();
|
|
|
650 |
$comment = new Comment();
|
|
|
651 |
$comment->comment = $dataPost['comment'];
|
|
|
652 |
$comment->feed_id = $feed->id;
|
|
|
653 |
$comment->user_id = $currentCompany->id;
|
|
|
654 |
|
|
|
655 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
656 |
if($commentMapper->insert($comment)) {
|
|
|
657 |
|
|
|
658 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
659 |
|
|
|
660 |
$feed->total_comments = $total_comments;
|
|
|
661 |
$feedMapper->update($feed);
|
|
|
662 |
|
|
|
663 |
$response = [
|
|
|
664 |
'success' => true,
|
|
|
665 |
'data' => $this->renderComment($comment->id),
|
|
|
666 |
'total_comments' => $total_comments
|
|
|
667 |
];
|
|
|
668 |
|
|
|
669 |
return new JsonModel($response);
|
|
|
670 |
|
|
|
671 |
} else {
|
|
|
672 |
|
|
|
673 |
$response = [
|
|
|
674 |
'success' => false,
|
|
|
675 |
'data' => $commentMapper->getError()
|
|
|
676 |
];
|
|
|
677 |
|
|
|
678 |
return new JsonModel($response);
|
|
|
679 |
}
|
|
|
680 |
|
|
|
681 |
} else {
|
|
|
682 |
$message = '';;
|
|
|
683 |
$form_messages = (array) $form->getMessages();
|
|
|
684 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
685 |
{
|
|
|
686 |
foreach( $field_messages as $key => $value)
|
|
|
687 |
{
|
|
|
688 |
$message = $value;
|
|
|
689 |
}
|
|
|
690 |
}
|
|
|
691 |
|
|
|
692 |
$response = [
|
|
|
693 |
'success' => false,
|
|
|
694 |
'data' => $message
|
|
|
695 |
];
|
|
|
696 |
|
|
|
697 |
return new JsonModel($response);
|
|
|
698 |
}
|
|
|
699 |
|
|
|
700 |
|
|
|
701 |
} else {
|
|
|
702 |
$response = [
|
|
|
703 |
'success' => false,
|
|
|
704 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
705 |
];
|
|
|
706 |
|
|
|
707 |
return new JsonModel($response);
|
|
|
708 |
}
|
|
|
709 |
|
|
|
710 |
|
|
|
711 |
}
|
11317 |
eleazar |
712 |
|
11837 |
eleazar |
713 |
public function answerAction()
|
11809 |
eleazar |
714 |
{
|
11317 |
eleazar |
715 |
|
11809 |
eleazar |
716 |
|
|
|
717 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
718 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
719 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
720 |
|
|
|
721 |
|
|
|
722 |
$id = $this->params()->fromRoute('id');
|
|
|
723 |
$comment_uuid = $this->params()->fromRoute('comment');
|
|
|
724 |
|
|
|
725 |
$request = $this->getRequest();
|
|
|
726 |
if($request->isPost()) {
|
|
|
727 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
728 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
729 |
if(!$feed) {
|
|
|
730 |
$response = [
|
|
|
731 |
'success' => false,
|
|
|
732 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
733 |
];
|
|
|
734 |
return new JsonModel($response);
|
|
|
735 |
}
|
|
|
736 |
|
|
|
737 |
if($feed->company_id != $currentCompany->id) {
|
|
|
738 |
$response = [
|
|
|
739 |
'success' => false,
|
|
|
740 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
741 |
];
|
|
|
742 |
return new JsonModel($response);
|
|
|
743 |
}
|
|
|
744 |
|
|
|
745 |
$dataPost = $request->getPost()->toArray();
|
|
|
746 |
$form = new CommentAnswerForm();
|
|
|
747 |
$form->setData($dataPost);
|
|
|
748 |
|
|
|
749 |
if($form->isValid()) {
|
|
|
750 |
|
|
|
751 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
752 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
753 |
|
|
|
754 |
$dataPost = (array) $form->getData();
|
|
|
755 |
$answer = new Comment();
|
|
|
756 |
$answer->comment = $dataPost['answer'];
|
|
|
757 |
$answer->feed_id = $feed->id;
|
|
|
758 |
|
|
|
759 |
$answer->user_id = $owner->user_id;
|
|
|
760 |
|
|
|
761 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
762 |
$comment=$commentMapper->fetchOneByUuid($comment_uuid);
|
|
|
763 |
$answer->parent_id = $comment->id;
|
|
|
764 |
|
|
|
765 |
if($commentMapper->insert($answer)) {
|
|
|
766 |
|
|
|
767 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
768 |
|
|
|
769 |
$feed->total_comments = $total_comments;
|
|
|
770 |
$feedMapper->update($feed);
|
|
|
771 |
|
|
|
772 |
$response = [
|
|
|
773 |
'success' => true,
|
|
|
774 |
'data' => $this->renderComment($answer->id),
|
|
|
775 |
'total_comments' => $total_comments
|
|
|
776 |
];
|
|
|
777 |
|
|
|
778 |
return new JsonModel($response);
|
|
|
779 |
|
|
|
780 |
} else {
|
|
|
781 |
|
|
|
782 |
$response = [
|
|
|
783 |
'success' => false,
|
|
|
784 |
'data' => $commentMapper->getError()
|
|
|
785 |
];
|
|
|
786 |
|
|
|
787 |
return new JsonModel($response);
|
|
|
788 |
}
|
|
|
789 |
|
|
|
790 |
} else {
|
|
|
791 |
$message = '';;
|
|
|
792 |
$form_messages = (array) $form->getMessages();
|
|
|
793 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
794 |
{
|
|
|
795 |
foreach( $field_messages as $key => $value)
|
|
|
796 |
{
|
|
|
797 |
$message = $value;
|
|
|
798 |
}
|
|
|
799 |
}
|
|
|
800 |
|
|
|
801 |
$response = [
|
|
|
802 |
'success' => false,
|
|
|
803 |
'data' => $message
|
|
|
804 |
];
|
|
|
805 |
|
|
|
806 |
return new JsonModel($response);
|
|
|
807 |
}
|
|
|
808 |
|
|
|
809 |
|
|
|
810 |
} else {
|
|
|
811 |
$response = [
|
|
|
812 |
'success' => false,
|
|
|
813 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
814 |
];
|
|
|
815 |
|
|
|
816 |
return new JsonModel($response);
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
|
|
|
820 |
}
|
|
|
821 |
|
|
|
822 |
public function commentDeleteAction()
|
|
|
823 |
{
|
|
|
824 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
825 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
826 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
827 |
|
|
|
828 |
$request = $this->getRequest();
|
|
|
829 |
if($request->isPost()) {
|
|
|
830 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
831 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
832 |
|
|
|
833 |
$id = $this->params()->fromRoute('id');
|
|
|
834 |
$comment = $this->params()->fromRoute('comment');
|
|
|
835 |
|
|
|
836 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
837 |
$feed = $feedMapper->fetchOneByUuid($id);
|
|
|
838 |
if(!$feed) {
|
|
|
839 |
$response = [
|
|
|
840 |
'success' => false,
|
|
|
841 |
'data' => 'ERROR_POST_NOT_FOUND'
|
|
|
842 |
];
|
|
|
843 |
return new JsonModel($response);
|
|
|
844 |
}
|
|
|
845 |
|
|
|
846 |
if($feed->company_id != $currentCompany->id) {
|
|
|
847 |
$response = [
|
|
|
848 |
'success' => false,
|
|
|
849 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
850 |
];
|
|
|
851 |
return new JsonModel($response);
|
|
|
852 |
}
|
|
|
853 |
|
|
|
854 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
855 |
$comment = $commentMapper->fetchOneByUuid($comment);
|
|
|
856 |
|
|
|
857 |
if($comment && $comment->feed_id == $feed->id) {
|
|
|
858 |
$comment->status = Comment::STATUS_DELETED;
|
|
|
859 |
if($commentMapper->update($comment)) {
|
|
|
860 |
$total_comments = $commentMapper->fetchCountCommentByFeedId($comment->feed_id);
|
|
|
861 |
|
|
|
862 |
$feed = $feedMapper->fetchOne($comment->feed_id);
|
|
|
863 |
$feed->total_comments = $total_comments;
|
|
|
864 |
$feedMapper->update($feed);
|
|
|
865 |
|
|
|
866 |
|
|
|
867 |
|
|
|
868 |
|
|
|
869 |
|
|
|
870 |
$response = [
|
|
|
871 |
'success' => true,
|
|
|
872 |
'data' => [
|
|
|
873 |
'message' => 'LABEL_COMMENT_WAS_DELETED',
|
|
|
874 |
'total_comments' => $total_comments
|
|
|
875 |
]
|
|
|
876 |
];
|
|
|
877 |
} else {
|
|
|
878 |
$response = [
|
|
|
879 |
'success' => false,
|
|
|
880 |
'data' => $commentMapper->getError()
|
|
|
881 |
];
|
|
|
882 |
}
|
|
|
883 |
|
|
|
884 |
} else {
|
|
|
885 |
$response = [
|
|
|
886 |
'success' => false,
|
|
|
887 |
'data' => 'ERROR_COMMENT_NOT_FOUND'
|
|
|
888 |
];
|
|
|
889 |
}
|
|
|
890 |
|
|
|
891 |
} else {
|
|
|
892 |
$response = [
|
|
|
893 |
'success' => false,
|
|
|
894 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
895 |
];
|
|
|
896 |
}
|
|
|
897 |
|
|
|
898 |
return new JsonModel($response);
|
|
|
899 |
}
|
|
|
900 |
|
|
|
901 |
private function renderComment($comment_id)
|
|
|
902 |
{
|
|
|
903 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
904 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
905 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
906 |
|
|
|
907 |
$companyMapper = CompanyMapper::getInstance($this->adapter);
|
|
|
908 |
$company = $companyMapper->fetchOne($currentCompany->id);
|
|
|
909 |
|
|
|
910 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
|
|
911 |
$owner = $companyUserMapper->fetchOwnerByCompanyId($currentCompany->id);
|
|
|
912 |
|
|
|
913 |
|
|
|
914 |
|
|
|
915 |
$sandbox = $this->config['leaderslinked.runmode.sandbox'];
|
|
|
916 |
if($sandbox) {
|
|
|
917 |
$company_profile_url = $this->config['leaderslinked.frontend.sandbox_company_profile'];
|
|
|
918 |
$user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
|
|
|
919 |
} else {
|
|
|
920 |
$company_profile_url = $this->config['leaderslinked.frontend.production_company_profile'];
|
|
|
921 |
$user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
|
|
|
922 |
}
|
|
|
923 |
|
|
|
924 |
|
|
|
925 |
$item = [];
|
|
|
926 |
|
|
|
927 |
$commentMapper = CommentMapper::getInstance($this->adapter);
|
|
|
928 |
$record = $commentMapper->fetchOne($comment_id);
|
|
|
929 |
|
|
|
930 |
$feedMapper = FeedMapper::getInstance($this->adapter);
|
|
|
931 |
$feed = $feedMapper->fetchOne($record->feed_id);
|
|
|
932 |
|
|
|
933 |
if($record) {
|
|
|
934 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
935 |
|
|
|
936 |
$dt = \DateTime::createFromFormat('Y-m-d H:i:s', $record->added_on);
|
|
|
937 |
|
|
|
938 |
|
|
|
939 |
$item = [];
|
|
|
940 |
$item['unique'] = uniqid();
|
|
|
941 |
|
|
|
942 |
|
|
|
943 |
$user = $userMapper->fetchOne($record->user_id);
|
|
|
944 |
if($user->id == $owner->user_id) {
|
|
|
945 |
$item['user_image'] = $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $company->uuid, 'filename' => $company->image ]);
|
|
|
946 |
$item['user_url'] = str_replace('[uuid]', $company->uuid, $company_profile_url);
|
|
|
947 |
$item['user_name'] = $company->name;
|
|
|
948 |
} else {
|
|
|
949 |
$item['user_image'] = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image ]);
|
|
|
950 |
$item['user_url'] = str_replace('[uuid]', $user->uuid, $user_profile_url);
|
|
|
951 |
$item['user_name'] = $user->first_name . ' ' . $user->last_name;
|
|
|
952 |
}
|
|
|
953 |
|
|
|
954 |
|
|
|
955 |
|
11854 |
eleazar |
956 |
$item['link_answer_add'] = $this->url()->fromRoute('my-trainer/question/answer/comments/answer',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
|
|
957 |
$item['link_delete'] = $this->url()->fromRoute('my-trainer/question/answer/comments/delete',['id' => $feed->uuid, 'comment' => $record->uuid ]);
|
11809 |
eleazar |
958 |
$item['time_elapsed'] = Functions::timeElapsedString($dt->getTimestamp());
|
|
|
959 |
$item['comment'] = $record->comment;
|
|
|
960 |
|
|
|
961 |
}
|
|
|
962 |
return $item;
|
|
|
963 |
}
|
|
|
964 |
|
11317 |
eleazar |
965 |
}
|