Proyectos de Subversion LeadersLinked - Services

Rev

Rev 242 | Rev 333 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
 
3
/**
4
 *
5
 * Controlador: Mis Perfiles
6
 *
7
 */
8
 
9
declare(strict_types=1);
10
 
11
namespace LeadersLinked\Controller;
12
 
13
use Laminas\Db\Adapter\AdapterInterface;
14
 
15
use Laminas\Mvc\Controller\AbstractActionController;
16
use Laminas\Log\LoggerInterface;
17
use Laminas\View\Model\ViewModel;
18
use Laminas\View\Model\JsonModel;
19
use LeadersLinked\Library\Functions;
20
use LeadersLinked\Library\Image;
21
use LeadersLinked\Mapper\KnowledgeAreaCategoryMapper;
22
use LeadersLinked\Mapper\KnowledgeAreaCategoryUserMapper;
23
use LeadersLinked\Mapper\UserMapper;
24
use LeadersLinked\Model\KnowledgeAreaCategory;
25
use LeadersLinked\Model\KnowledgeAreaCategoryUser;
26
use LeadersLinked\Form\KnowledgeArea\KnowledgeAreaCreateForm;
27
use LeadersLinked\Mapper\KnowledgeAreaContentMapper;
28
use LeadersLinked\Model\KnowledgeAreaContent;
29
use LeadersLinked\Form\KnowledgeArea\KnowledgeAreaEditForm;
30
use LeadersLinked\Mapper\CommentMapper;
31
use LeadersLinked\Form\KnowledgeArea\CommentForm;
32
use LeadersLinked\Model\Comment;
33
use LeadersLinked\Mapper\ContentReactionMapper;
34
use LeadersLinked\Model\ContentReaction;
35
use LeadersLinked\Mapper\KnowledgeAreaCategoryJobDescriptionMapper;
36
use LeadersLinked\Mapper\OrganizationPositionMapper;
242 efrain 37
use LeadersLinked\Model\User;
283 www 38
use LeadersLinked\Library\Storage;
1 efrain 39
 
40
class KnowledgeAreaController extends AbstractActionController
41
{
42
    /**
43
     *
44
     * @var \Laminas\Db\Adapter\AdapterInterface
45
     */
46
    private $adapter;
47
 
48
    /**
49
     *
50
     * @var \LeadersLinked\Cache\CacheInterface
51
     */
52
    private $cache;
53
 
54
 
55
    /**
56
     *
57
     * @var \Laminas\Log\LoggerInterface
58
     */
59
    private $logger;
60
 
61
    /**
62
     *
63
     * @var array
64
     */
65
    private $config;
66
 
67
 
68
    /**
69
     *
70
     * @var \Laminas\Mvc\I18n\Translator
71
     */
72
    private $translator;
73
 
74
 
75
    /**
76
     *
77
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
78
     * @param \LeadersLinked\Cache\CacheInterface $cache
79
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
80
     * @param array $config
81
     * @param \Laminas\Mvc\I18n\Translator $translator
82
     */
83
    public function __construct($adapter, $cache, $logger, $config, $translator)
84
    {
85
        $this->adapter      = $adapter;
86
        $this->cache        = $cache;
87
        $this->logger       = $logger;
88
        $this->config       = $config;
89
        $this->translator   = $translator;
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
 
103
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
104
        $currentNetwork = $currentNetworkPlugin->getNetwork();
105
 
106
        $request = $this->getRequest();
107
        if ($request->isGet()) {
108
 
109
 
110
 
111
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
112
                $allowAdd       = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/add') ? 1 : 0;
113
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/edit');
114
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/delete');
115
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'knowledge-area/view');
116
 
117
 
118
 
119
                $category_filter_id = Functions::sanitizeFilterString($this->params()->fromQuery('category_id'));
120
                $search = Functions::sanitizeFilterString($this->params()->fromQuery('search'));
121
                $page   = intval($this->params()->fromQuery('start', 1), 10);
122
 
123
                $order_field        = 'added_on';
124
                $order_direction    = 'asc';
125
                $records_x_page     = 12;
126
 
127
 
128
 
129
                $category_with_edition_ids = [];
130
                $category_with_edition_uuids = [];
131
                $category_ids = [];
132
                $categories = [];
133
 
134
 
135
                $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
136
 
137
                $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
138
                $records =  $knowledgeAreaCategoryUserMapper->fetchAllByUserId($currentUser->id);
139
 
140
 
141
 
142
                foreach ($records as $record) {
143
                    if ($record->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR || $record->role == KnowledgeAreaCategoryUser::ROLE_USER) {
144
 
145
                        array_push($category_with_edition_ids, $record->category_id);
146
 
147
                        $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOne($record->category_id);
148
                        if($knowledgeAreaCategory) {
149
                            array_push($category_with_edition_uuids, $knowledgeAreaCategory->uuid);
150
                        }
151
 
152
                    }
153
 
154
                    array_push($category_ids, $record->category_id);
155
                }
156
 
157
                $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
158
 
159
                if ($category_ids) {
160
                    $records =  $knowledgeAreaCategoryMapper->fetchAllByIds($category_ids);
161
                    foreach ($records as $record) {
162
                        if (!isset($categories[$record->id])) {
163
 
164
                            $categories[$record->id] = [
165
                                'uuid' => $record->uuid,
166
                                'name' => $record->name,
167
                            ];
168
                        }
169
                    }
170
                }
171
 
172
 
173
 
174
                $records =  $knowledgeAreaCategoryMapper->fetchAllPublicByNetworkId($currentNetwork->id);
175
                foreach ($records as $record) {
176
                    if (!isset($categories[$record->id])) {
177
 
178
                        $categories[$record->id] = [
179
                            'uuid' => $record->uuid,
180
                            'name' => $record->name,
181
                        ];
182
                    }
183
                }
184
 
185
 
186
                uasort($categories, function ($a, $b) {
187
                    return $a['name'] <=> $b['name'];
188
                });
189
 
190
 
191
                if ($category_filter_id) {
192
                    $categoryFilter = $knowledgeAreaCategoryMapper->fetchOneByUuid($category_filter_id);
193
                    if ($categoryFilter) {
194
                        $category_ids = [$categoryFilter->id];
195
                    } else {
196
                        $category_ids = [];
197
                    }
198
                }
283 www 199
 
200
                $storage = Storage::getInstance($this->config);
201
                $path = $storage->getPathKnowledgeArea();
1 efrain 202
 
203
                $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
204
                $paginator = $knowledgeAreaContentMapper->fetchAllDataTableByCategoryIds($category_ids,  $search, $page, $records_x_page, $order_field, $order_direction);
205
 
206
 
207
                $items = [];
208
                $records = $paginator->getCurrentItems();
209
                foreach ($records as $record)
210
                {
211
 
212
 
213
                    if (!isset($categories[$record->category_id])) {
214
                        $category = $knowledgeAreaCategoryMapper->fetchOne($record->category_id);
215
                        if ($category) {
216
                            $categories[$category->id] = [
217
                                'uuid' =>  $category->uuid,
218
                                'name' =>  $category->name,
219
                            ];
220
                        }
221
                    }
222
 
223
 
224
 
225
 
226
 
227
                    $description = strip_tags($record->description);
228
                    if (strlen($description) > 120) {
229
                        $description = substr($description, 0, 120) . '...';
230
                    }
231
 
232
                    $item = [
283 www 233
                        'image' => $storage->getGenericImage($path, $record->uuid,   $record->image),
1 efrain 234
                        'title' => $record->title,
235
                        'description' => $description,
236
                        'category' => $categories[$record->category_id]['name'],
237
                        'link_view' => $allowView ?  $this->url()->fromRoute('knowledge-area/view', ['id' => $record->uuid]) : '',
242 efrain 238
 
1 efrain 239
                    ];
240
 
241
 
242
 
243
                    if (in_array($record->category_id, $category_with_edition_ids)) {
244
                        $item['link_edit'] = $allowEdit ?  $this->url()->fromRoute('knowledge-area/edit', ['id' => $record->uuid]) : '';
245
                        $item['link_delete'] = $allowDelete ? $this->url()->fromRoute('knowledge-area/delete', ['id' => $record->uuid]) : '';
246
                    }
247
 
248
                    array_push($items, $item);
249
                }
250
 
251
 
252
 
253
                $image_size = $this->config['leaderslinked.image_sizes.knowledge_area'];
254
 
255
                return new JsonModel([
256
                    'success' => true,
257
                    'data' => [
258
                        'items' => $items,
259
                        'total' => $paginator->getTotalItemCount(),
260
                        'page' => $paginator->getCurrentPageNumber(),
261
                        'total_pages' => $paginator->getPages()->pageCount,
262
                        'categories' => $categories,
263
                        'categories_with_edition' => $category_with_edition_uuids,
264
                        'link_add' => $allowAdd ? $this->url()->fromRoute('knowledge-area/add') : '',
265
                        'image_size' => $image_size,
266
                        'content_edit' => count($category_with_edition_ids) > 0,
267
 
268
                    ]
269
                ]);
270
 
271
        } else {
272
            return new JsonModel([
273
                'success' => false,
274
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
275
            ]);
276
        }
277
    }
278
 
279
    public function addAction()
280
    {
281
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
282
        $currentUser        = $currentUserPlugin->getUser();
283
 
284
        $request            = $this->getRequest();
285
 
286
        if ($request->isPost()) {
287
            $category_with_edition_ids = [];
288
            $category_ids = [];
289
 
290
 
291
            $categories = [];
292
 
293
 
294
            $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
295
            $records =  $knowledgeAreaCategoryUserMapper->fetchAllByUserId($currentUser->id);
296
            foreach ($records as $record) {
297
                if ($record->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR || $record->role == KnowledgeAreaCategoryUser::ROLE_USER) {
298
 
299
                    array_push($category_with_edition_ids, $record->category_id);
300
                }
301
 
302
                array_push($category_ids, $record->category_id);
303
            }
304
 
305
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
306
 
307
            if ($category_ids) {
308
                $records =  $knowledgeAreaCategoryMapper->fetchAllByIds($category_ids);
309
                foreach ($records as $record) {
310
                    if ($record->status == KnowledgeAreaCategory::STATUS_ACTIVE) {
311
 
312
                        $categories[$record->id] = [
313
                            'uuid' => $record->uuid,
314
                            'name' => $record->name,
315
                        ];
316
                    }
317
                }
318
            }
319
 
320
 
321
 
322
            $categories = array_values($categories);
323
            usort($categories, function ($a, $b) {
324
                return $a['name'] <=> $b['name'];
325
            });
326
 
327
 
328
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
329
            $form = new KnowledgeAreaCreateForm($this->adapter, $category_with_edition_ids);
330
 
331
            $form->setData($dataPost);
332
 
333
            if ($form->isValid()) {
334
                $dataPost = (array) $form->getData();
335
 
336
                $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
337
                $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($dataPost['category_id']);
338
 
339
 
340
                $knowledgeAreaContent = new KnowledgeAreaContent();
341
                $knowledgeAreaContent->network_id = $knowledgeAreaCategory->network_id;
342
                $knowledgeAreaContent->company_id = $knowledgeAreaCategory->company_id;
343
                $knowledgeAreaContent->category_id = $knowledgeAreaCategory->id;
344
                $knowledgeAreaContent->user_id = $currentUser->id;
345
                $knowledgeAreaContent->title = $dataPost['title'];
346
                $knowledgeAreaContent->description = $dataPost['description'];
347
                $knowledgeAreaContent->link = $dataPost['link'];
348
 
349
                $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
350
                if ($knowledgeAreaContentMapper->insert($knowledgeAreaContent)) {
351
                    $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOne($knowledgeAreaContent->id);
352
 
283 www 353
                    //$target_size = $this->config['leaderslinked.image_sizes.knowledge_area'];
354
                    //list($target_width, $target_height) = explode('x', $target_size);
1 efrain 355
 
356
 
283 www 357
                    $image = Image::getInstance($this->config);
358
                    $target_path = $image->getStorage()->getPathKnowledgeArea();
359
 
1 efrain 360
 
361
 
362
                    $files = $this->getRequest()->getFiles()->toArray();
363
 
364
 
365
                    if (isset($files['image']) && empty($files['image']['error'])) {
366
                        $tmp_filename  = $files['image']['tmp_name'];
367
                        $filename      = explode('.',  $files['image']['name']);
368
                        $filename       = Functions::normalizeString(uniqid() . '-' . $filename[0] . '.png');
283 www 369
                        $unlink_source = true;
1 efrain 370
 
283 www 371
                        if($image->uploadImageRaw($tmp_filename, $target_path, $knowledgeAreaCategory->uuid, $filename, $unlink_source)) {
1 efrain 372
                            $knowledgeAreaContent->image = $filename;
373
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
374
                        }
375
                    }
376
 
377
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
378
                        $tmp_filename   = $files['attachment']['tmp_name'];
379
                        $filename       = Functions::normalizeString($files['attachment']['name']);
283 www 380
 
381
 
382
                        if($image->getStorage()->putFile($target_path, $knowledgeAreaCategory->uuid, $filename)) {
1 efrain 383
                            $knowledgeAreaContent->attachment = $filename;
384
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
385
                        }
386
                    }
387
 
388
 
389
                    $this->logger->info('Se agrego el contenido ' . $knowledgeAreaContent->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
390
 
391
                    $data = [
392
                        'success'   => true,
393
                        'data'   => 'LABEL_RECORD_ADDED'
394
                    ];
395
                } else {
396
                    $data = [
397
                        'success'   => false,
398
                        'data'      => $knowledgeAreaContentMapper->getError()
399
                    ];
400
                }
401
 
402
                return new JsonModel($data);
403
            } else {
404
                $messages = [];
405
                $form_messages = (array) $form->getMessages();
406
                foreach ($form_messages  as $fieldname => $field_messages) {
407
 
408
                    $messages[$fieldname] = array_values($field_messages);
409
                }
410
 
411
                return new JsonModel([
412
                    'success'   => false,
413
                    'data'   => $messages
414
                ]);
415
            }
416
        } else {
417
            $data = [
418
                'success' => false,
419
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
420
            ];
421
 
422
            return new JsonModel($data);
423
        }
424
 
425
        return new JsonModel($data);
426
    }
427
 
428
    public function deleteAction()
429
    {
430
        $currentUserPlugin = $this->plugin('currentUserPlugin');
431
        $currentUser    = $currentUserPlugin->getUser();
432
 
433
 
434
        $request    = $this->getRequest();
435
        $id         = $this->params()->fromRoute('id');
436
 
437
 
438
 
439
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
440
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
441
        if (!$knowledgeAreaContent) {
442
            return new JsonModel([
443
                'success'   => false,
444
                'data'   => 'ERROR_RECORD_NOT_FOUND'
445
            ]);
446
        }
447
 
448
 
449
 
450
        $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
451
        $knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaContent->category_id, $currentUser->id);
452
 
453
        $ok = false;
454
        if ($knowledgeAreaCategoryUser) {
455
 
456
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_EDITOR) {
457
                $ok = $knowledgeAreaContent->user_id == $currentUser->id;
458
            }
459
 
460
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR) {
461
                $ok = true;
462
            }
463
        }
464
 
465
        if (!$ok) {
466
            return new JsonModel([
467
                'success'   => false,
468
                'data'   => 'ERROR_KNOWLEDGE_AREA_YOU_DO_NOT_HAVE_PERMISSION'
469
            ]);
470
        }
471
 
472
        if ($request->isPost()) {
473
 
474
            $result =  $knowledgeAreaContentMapper->delete($knowledgeAreaContent);
475
            if ($result) {
476
                $this->logger->info('Se borro el cotenido : ' .  $knowledgeAreaContent->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
477
 
283 www 478
 
479
                $storage = Storage::getInstance($this->config);
480
                $target_path = $storage->getPathKnowledgeArea();
481
 
482
 
483
                if($knowledgeAreaContent->attachment) {
484
                    $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->attachment);
485
                }
486
 
487
 
488
 
1 efrain 489
                if ($knowledgeAreaContent->image) {
283 www 490
                    $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->image);
1 efrain 491
                }
492
 
493
                $data = [
494
                    'success' => true,
495
                    'data' => 'LABEL_RECORD_DELETED'
496
                ];
497
            } else {
498
 
499
                $data = [
500
                    'success'   => false,
501
                    'data'      => $knowledgeAreaContentMapper->getError()
502
                ];
503
 
504
                return new JsonModel($data);
505
            }
506
        } else {
507
            $data = [
508
                'success' => false,
509
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
510
            ];
511
 
512
            return new JsonModel($data);
513
        }
514
 
515
        return new JsonModel($data);
516
    }
517
 
518
 
519
    public function editAction()
520
    {
521
        $currentUserPlugin = $this->plugin('currentUserPlugin');
522
        $currentUser    = $currentUserPlugin->getUser();
523
 
524
        $request    = $this->getRequest();
525
        $id    = $this->params()->fromRoute('id');
526
 
527
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
528
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
529
        if (!$knowledgeAreaContent) {
530
            return new JsonModel([
531
                'success'   => false,
532
                'data'   => 'ERROR_RECORD_NOT_FOUND'
533
            ]);
534
        }
535
 
536
 
537
 
538
        $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
539
        $knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaContent->category_id, $currentUser->id);
540
 
541
        $ok = false;
542
        if ($knowledgeAreaCategoryUser) {
543
 
544
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_EDITOR) {
545
                $ok = $knowledgeAreaContent->user_id == $currentUser->id;
546
            }
547
 
548
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR) {
549
                $ok = true;
550
            }
551
        }
552
 
553
        if (!$ok) {
554
            return new JsonModel([
555
                'success'   => false,
556
                'data'   => 'ERROR_KNOWLEDGE_AREA_YOU_DO_NOT_HAVE_PERMISSION'
557
            ]);
558
        }
559
 
560
        if ($request->isGet()) {
561
 
562
 
563
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
564
            $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOne($knowledgeAreaContent->category_id);
565
 
566
 
567
 
568
            $data = [
569
                'success' => true,
570
                'data' => [
571
                    'category_id' => $knowledgeAreaCategory->uuid,
572
                    'title' => $knowledgeAreaContent->title,
573
                    'description' => $knowledgeAreaContent->description,
574
                    'link' => $knowledgeAreaContent->link,
575
                ]
576
            ];
577
 
578
            return new JsonModel($data);
579
        } else if ($request->isPost()) {
580
            $category_with_edition_ids = [];
581
            $category_ids = [];
582
 
583
 
584
            $categories = [];
585
 
586
 
587
            $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
588
            $records =  $knowledgeAreaCategoryUserMapper->fetchAllByUserId($currentUser->id);
589
            foreach ($records as $record) {
590
                if ($record->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR || $record->role == KnowledgeAreaCategoryUser::ROLE_USER) {
591
 
592
                    array_push($category_with_edition_ids, $record->category_id);
593
                }
594
 
595
                array_push($category_ids, $record->category_id);
596
            }
597
 
598
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
599
 
600
            if ($category_ids) {
601
                $records =  $knowledgeAreaCategoryMapper->fetchAllByIds($category_ids);
602
                foreach ($records as $record) {
603
                    if ($record->status == KnowledgeAreaCategory::STATUS_ACTIVE) {
604
 
605
                        $categories[$record->id] = [
606
                            'uuid' => $record->uuid,
607
                            'name' => $record->name,
608
                        ];
609
                    }
610
                }
611
            }
612
 
613
 
614
 
615
            $categories = array_values($categories);
616
            usort($categories, function ($a, $b) {
617
                return $a['name'] <=> $b['name'];
618
            });
619
 
620
 
621
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
622
            $form = new KnowledgeAreaEditForm($this->adapter, $category_with_edition_ids);
623
            $form->setData($dataPost);
624
 
625
            if ($form->isValid()) {
626
                $dataPost = (array) $form->getData();
627
 
628
 
629
                $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
630
                $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($dataPost['category_id']);
631
 
632
 
633
 
634
                $knowledgeAreaContent->category_id = $knowledgeAreaCategory->id;
635
                $knowledgeAreaContent->title = $dataPost['title'];
636
                $knowledgeAreaContent->description = $dataPost['description'];
637
 
638
 
639
                if ($knowledgeAreaContentMapper->update($knowledgeAreaContent)) {
640
 
283 www 641
                    //$target_size = $this->config['leaderslinked.image_sizes.knowledge_area'];
642
                    //list($target_width, $target_height) = explode('x', $target_size);
1 efrain 643
 
644
 
283 www 645
                    $image = Image::getInstance($this->config);
646
                    $target_path = $image->getStorage()->getPathKnowledgeArea();
1 efrain 647
 
648
                    $files = $this->getRequest()->getFiles()->toArray();
649
 
650
 
651
                    if (isset($files['image']) && empty($files['image']['error'])) {
652
 
283 www 653
 
1 efrain 654
                        if ($knowledgeAreaContent->image) {
283 www 655
                            $image->getStorage()->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->image);
1 efrain 656
                        }
657
 
283 www 658
 
1 efrain 659
                        $tmp_filename  = $files['image']['tmp_name'];
660
                        $filename      = explode('.',  $files['image']['name']);
661
                        $filename       = Functions::normalizeString(uniqid() . '-' . $filename[0] . '.png');
283 www 662
                        $unlink_source = true;
663
 
664
                        if($image->uploadImageRaw($tmp_filename, $target_path, $knowledgeAreaCategory->uuid, $filename, $unlink_source)) {
1 efrain 665
                            $knowledgeAreaContent->image = $filename;
666
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
667
                        }
668
                    }
669
 
670
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
671
                        $tmp_filename   = $files['attachment']['tmp_name'];
672
                        $filename       = Functions::normalizeString($files['attachment']['name']);
283 www 673
 
1 efrain 674
                        if ($knowledgeAreaContent->attachment) {
283 www 675
                            $image->getStorage()->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->attachment);
1 efrain 676
                        }
677
 
283 www 678
                        if ($image->getStorage()->putFile($target_path, $knowledgeAreaContent->uuid, $tmp_filename)) {
1 efrain 679
                            $knowledgeAreaContent->attachment = $filename;
680
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
681
                        }
682
                    }
683
 
684
 
685
                    $this->logger->info('Se edito el contenido ' . $knowledgeAreaContent->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
686
 
687
                    $data = [
688
                        'success'   => true,
689
                        'data'   => 'LABEL_RECORD_UPDATED'
690
                    ];
691
                } else {
692
                    $data = [
693
                        'success'   => false,
694
                        'data'      => $knowledgeAreaContentMapper->getError()
695
                    ];
696
                }
697
 
698
                return new JsonModel($data);
699
            } else {
700
                $messages = [];
701
                $form_messages = (array) $form->getMessages();
702
                foreach ($form_messages  as $fieldname => $field_messages) {
703
 
704
                    $messages[$fieldname] = array_values($field_messages);
705
                }
706
 
707
                return new JsonModel([
708
                    'success'   => false,
709
                    'data'   => $messages
710
                ]);
711
            }
712
        } else {
713
            $data = [
714
                'success' => false,
715
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
716
            ];
717
 
718
            return new JsonModel($data);
719
        }
720
 
721
        return new JsonModel($data);
722
    }
723
 
724
 
725
    public function viewAction()
726
    {
727
        $currentUserPlugin = $this->plugin('currentUserPlugin');
728
        $currentUser    = $currentUserPlugin->getUser();
729
 
730
        $request    = $this->getRequest();
731
        $id    = $this->params()->fromRoute('id');
732
 
733
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
734
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
735
        if (!$knowledgeAreaContent) {
736
            return new JsonModel([
737
                'success'   => false,
738
                'data'   => 'ERROR_RECORD_NOT_FOUND'
739
            ]);
740
        }
741
 
742
 
743
 
744
        $request = $this->getRequest();
745
        if ($request->isGet()) {
746
 
747
 
748
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
749
            $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOne($knowledgeAreaContent->category_id);
750
 
751
 
752
 
753
            $ok = false;
754
            if ($knowledgeAreaCategory->privacy == KnowledgeAreaCategory::PRIVACY_COMPANY) {
755
 
756
                $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
757
                $knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaContent->category_id, $currentUser->id);
758
 
759
 
760
                if ($knowledgeAreaCategoryUser) {
761
                    $ok = true;
762
                }
763
            }
764
            if ($knowledgeAreaCategory->privacy == KnowledgeAreaCategory::PRIVACY_PUBLIC) {
765
                $ok = true;
766
            }
767
 
768
            if (!$ok) {
769
                return new JsonModel([
770
                    'success'   => false,
771
                    'data'   => 'ERROR_KNOWLEDGE_AREA_YOU_DO_NOT_HAVE_PERMISSION'
772
                ]);
773
            }
774
 
775
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
776
            $contentReaction = $contentReactionMapper->fetchOneByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id);
777
 
778
 
283 www 779
            $storage = Storage::getInstance($this->config);
780
            $path = $storage->getPathKnowledgeArea();
1 efrain 781
 
782
                return new JsonModel([
783
                    'success' => true,
784
                    'data' => [
785
                        'category' => $knowledgeAreaCategory->name,
786
                        'title' => $knowledgeAreaContent->title,
787
                        'description' => $knowledgeAreaContent->description,
788
                        'link' => $knowledgeAreaContent->link,
283 www 789
                        'image' =>  $storage->getGenericImage($path, $knowledgeAreaContent->uuid,  $knowledgeAreaContent->image),
790
                        'attachment' =>  $knowledgeAreaContent->attachment ? $storage->getGenericFile($path, $knowledgeAreaContent->uuid,  $knowledgeAreaContent->attachment) : '',
1 efrain 791
                        'reaction' => $contentReaction ? $contentReaction->reaction : '',
242 efrain 792
                        'routeComments' => $this->url()->fromRoute('knowledge-area/comments', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
793
                        'routeCommentAdd' => $this->url()->fromRoute('knowledge-area/comments/add', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
794
                        'routeSaveReaction' => $this->url()->fromRoute('knowledge-area/save-reaction', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
795
                        'routeDeleteReaction' => $this->url()->fromRoute('knowledge-area/delete-reaction', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
796
                        'routeReactions' => $this->url()->fromRoute('knowledge-area/reactions', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
1 efrain 797
                    ]
798
                ]);
799
 
800
        } else {
801
            $data = [
802
                'success' => false,
803
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
804
            ];
805
 
806
            return new JsonModel($data);
807
        }
808
 
809
        return new JsonModel($data);
810
    }
242 efrain 811
 
812
    public function reactionsAction()
813
    {
814
        $id = $this->params()->fromRoute('id');
815
 
816
        $request = $this->getRequest();
817
        $request = $this->getRequest();
818
        if ($request->isGet()) {
819
 
820
            $currentUserPlugin = $this->plugin('currentUserPlugin');
821
            $currentUser = $currentUserPlugin->getUser();
822
 
823
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
824
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
825
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
826
                return new JsonModel([
827
                    'success'   => false,
828
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
829
                ]);
830
            }
831
 
832
 
833
 
834
            $userMapper = UserMapper::getInstance($this->adapter);
835
 
836
            $items = [];
837
 
283 www 838
            $storage = Storage::getInstance($this->config);
839
            $path = $storage->getPathKnowledgeArea();
840
 
242 efrain 841
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
842
            $records = $contentReactionMapper->fetchAllByKnowledgeAreaId($knowledgeAreaContent->id);
843
 
844
            foreach($records as $record)
845
            {
846
                $user = $userMapper->fetchOne($record->user_id);
847
                if($user && $user->status == User::STATUS_ACTIVE) {
848
 
849
                    array_push($items, [
850
                        'first_name' => $user->first_name,
851
                        'last_name' => $user->last_name,
852
                        'email' => $user->email,
283 www 853
                        'image' => $storage->getGenericImage($path, $user->uuid, $user->image),
242 efrain 854
                        'reaction' => $record->reaction,
855
                    ]);
856
                }
857
            }
858
 
859
            $response = [
860
                'success' => true,
861
                'data' => $items
862
            ];
863
 
864
            return new JsonModel($response);
865
 
866
 
867
 
868
 
869
        } else {
870
            $response = [
871
                'success' => false,
872
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
873
            ];
874
 
875
            return new JsonModel($response);
876
        }
877
    }
1 efrain 878
 
879
 
880
    public function addCommentAction()
881
    {
882
        $currentUserPlugin = $this->plugin('currentUserPlugin');
883
        $currentUser    = $currentUserPlugin->getUser();
884
 
885
        $id = $this->params()->fromRoute('id');
886
 
887
        $request = $this->getRequest();
888
        if ($request->isPost()) {
889
 
890
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
891
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
892
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
893
                return new JsonModel([
894
                    'success'   => false,
895
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
896
                ]);
897
            }
898
 
899
 
900
 
901
 
902
            $dataPost = $request->getPost()->toArray();
903
            $form = new CommentForm();
904
            $form->setData($dataPost);
905
 
906
            if ($form->isValid()) {
242 efrain 907
 
1 efrain 908
                $dataPost = (array) $form->getData();
909
 
910
                $comment = new Comment();
911
                $comment->network_id = $currentUser->network_id;
912
                $comment->comment = $dataPost['comment'];
913
                $comment->user_id = $currentUser->id;
914
                $comment->knowledge_area_id = $knowledgeAreaContent->id;
915
                $comment->relational = Comment::RELATIONAL_KNOWLEDGE_AREA;
916
 
917
                $commentMapper = CommentMapper::getInstance($this->adapter);
918
                $now = $commentMapper->getDatebaseNow();
919
 
920
                if ($commentMapper->insert($comment)) {
921
 
922
                    $total_comments = $commentMapper->fetchCountCommentByKnowledgeAreaId($comment->knowledge_area_id);
923
 
924
                    $knowledgeAreaContent->total_comments = $total_comments;
925
                    $knowledgeAreaContentMapper->update($knowledgeAreaContent);
926
 
927
                    $response = [
928
                        'success'   => true,
929
                        'data'   => $this->renderComment($comment->id, $now),
930
                        'total_comments' => $total_comments
931
                    ];
932
 
933
                    return new JsonModel($response);
934
                } else {
935
 
936
                    $response = [
937
                        'success'   => false,
938
                        'data'   => $commentMapper->getError()
939
                    ];
940
 
941
                    return new JsonModel($response);
942
                }
943
            } else {
944
                $message = '';;
945
                $form_messages = (array) $form->getMessages();
946
                foreach ($form_messages  as $fieldname => $field_messages) {
947
                    foreach ($field_messages as $key => $value) {
948
                        $message = $value;
949
                    }
950
                }
951
 
952
                $response = [
953
                    'success'   => false,
954
                    'data'   => $message
955
                ];
956
 
957
                return new JsonModel($response);
958
            }
959
        } else {
960
            $response = [
961
                'success' => false,
962
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
963
            ];
964
 
965
            return new JsonModel($response);
966
        }
967
    }
968
 
969
 
970
 
971
    public function deleteCommentAction()
972
    {
973
        $currentUserPlugin = $this->plugin('currentUserPlugin');
974
        $currentUser    = $currentUserPlugin->getUser();
975
 
976
        $request = $this->getRequest();
977
        if ($request->isPost()) {
978
 
979
            $id = $this->params()->fromRoute('id');
980
            $comment = $this->params()->fromRoute('comment');
981
 
982
 
983
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
984
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
985
 
986
 
987
 
988
            if ($knowledgeAreaContent && $knowledgeAreaContent->network_id == $currentUser->network_id) {
989
 
990
                $commentMapper = CommentMapper::getInstance($this->adapter);
991
                $comment = $commentMapper->fetchOneByUuid($comment);
992
 
993
 
994
                if ($comment && $comment->knowledge_area_id == $knowledgeAreaContent->id && $comment->user_id == $currentUser->id) {
995
 
996
                    $comment->status = Comment::STATUS_DELETED;
997
 
998
                    if ($commentMapper->update($comment)) {
999
 
1000
                        $total_comments = $commentMapper->fetchCountCommentByKnowledgeAreaId($knowledgeAreaContent->id);
1001
                        $knowledgeAreaContent->total_comments = $total_comments;
1002
                        $knowledgeAreaContentMapper->update($knowledgeAreaContent);
1003
 
1004
                        $response = [
1005
                            'success' => true,
1006
                            'data' => 'LABEL_COMMENT_WAS_DELETED',
1007
                            'total_comments' => $total_comments
1008
                        ];
1009
                    } else {
1010
                        $response = [
1011
                            'success' => false,
1012
                            'data' => $commentMapper->getError()
1013
                        ];
1014
                    }
1015
                } else {
1016
                    $response = [
1017
                        'success' => false,
1018
                        'data' => 'ERROR_COMMENT_NOT_FOUND'
1019
                    ];
1020
                }
1021
            } else {
1022
                $response = [
1023
                    'success' => false,
1024
                    'data' => 'ERROR_COMMENT_NOT_FOUND'
1025
                ];
1026
            }
1027
        } else {
1028
            $response = [
1029
                'success' => false,
1030
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1031
            ];
1032
        }
1033
 
1034
        return new JsonModel($response);
1035
    }
1036
 
1037
 
1038
 
1039
    public function saveReactionAction()
1040
    {
1041
 
1042
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1043
        $currentUser    = $currentUserPlugin->getUser();
1044
 
1045
        $id = $this->params()->fromRoute('id');
1046
        $reaction  = $this->params()->fromPost('reaction');
1047
 
1048
        $request = $this->getRequest();
1049
        if ($request->isPost()) {
1050
 
1051
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1052
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1053
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
1054
                return new JsonModel([
1055
                    'success'   => false,
1056
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
1057
                ]);
1058
            }
1059
 
1060
            $reactions = [
1061
                ContentReaction::REACTION_RECOMMENDED,
1062
                ContentReaction::REACTION_SUPPORT,
1063
                ContentReaction::REACTION_LOVE,
1064
                ContentReaction::REACTION_INTEREST,
1065
                ContentReaction::REACTION_FUN
1066
 
1067
            ];
1068
            if(!in_array($reaction, $reactions)) {
1069
                $response = [
1070
                    'success' => false,
1071
                    'data' => 'ERROR_REACTION_NOT_FOUND'
1072
                ];
1073
                return new JsonModel($response);
1074
            }
1075
 
1076
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
1077
            $contentReaction = $contentReactionMapper->fetchOneByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id);
1078
 
1079
            if ($contentReaction) {
1080
                $contentReaction->reaction = $reaction;
1081
 
1082
                $result = $contentReactionMapper->update($contentReaction);
1083
            } else {
1084
                $contentReaction = new ContentReaction();
1085
                $contentReaction->user_id = $currentUser->id;
1086
                $contentReaction->knowledge_area_id = $knowledgeAreaContent->id;
1087
                $contentReaction->relational = ContentReaction::RELATIONAL_KNOWLEDGE_AREA;
1088
                $contentReaction->reaction = $reaction;
1089
 
1090
                $result = $contentReactionMapper->insert($contentReaction);
1091
            }
1092
 
1093
 
1094
 
1095
            if ($result) {
1096
 
1097
                $reactions = $contentReactionMapper->fetchCountByKnowledgeAreaId($knowledgeAreaContent->id);
1098
                $response = [
1099
                    'success' => true,
1100
                    'data' => [
1101
                        'reactions' => $reactions
1102
                    ]
1103
                ];
1104
            } else {
1105
                $response = [
1106
                    'success' => false,
1107
                    'data' => $contentReactionMapper->getError()
1108
                ];
1109
            }
1110
            return new JsonModel($response);
1111
        }
1112
 
1113
        $response = [
1114
            'success' => false,
1115
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1116
        ];
1117
        return new JsonModel($response);
1118
    }
1119
 
1120
    public function deleteReactionAction()
1121
    {
1122
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1123
        $currentUser    = $currentUserPlugin->getUser();
1124
 
1125
        $id = $this->params()->fromRoute('id');
1126
 
1127
        $request = $this->getRequest();
1128
        if ($request->isPost()) {
1129
 
1130
 
1131
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1132
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1133
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
1134
                return new JsonModel([
1135
                    'success'   => false,
1136
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
1137
                ]);
1138
            }
1139
 
1140
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
1141
            $contentReaction = $contentReactionMapper->fetchOneByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id);
1142
 
1143
            if (!$contentReaction) {
1144
                $response = [
1145
                    'success' => false,
1146
                    'data' => 'ERROR_DUPLICATE_ACTION'
1147
                ];
1148
                return new JsonModel($response);
1149
            }
1150
 
1151
            if ($contentReactionMapper->deleteByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id)) {
1152
                $reactions = $contentReactionMapper->fetchCountByKnowledgeAreaId($knowledgeAreaContent->id);
1153
 
1154
                $response = [
1155
                    'success' => true,
1156
                    'data' => [
1157
                        'reactions' => $reactions
1158
                    ]
1159
                ];
1160
            } else {
1161
                $response = [
1162
                    'success' => false,
1163
                    'data' => $contentReactionMapper->getError()
1164
                ];
1165
            }
1166
            return new JsonModel($response);
1167
        }
1168
 
1169
        $response = [
1170
            'success' => false,
1171
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1172
        ];
1173
        return new JsonModel($response);
1174
    }
1175
 
1176
    public function commentsAction()
1177
    {
1178
        $id = $this->params()->fromRoute('id');
1179
 
1180
        $request = $this->getRequest();
1181
        if ($request->isGet()) {
1182
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1183
            $currentUser = $currentUserPlugin->getUser();
1184
 
1185
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1186
            $now = $knowledgeAreaContentMapper->getDatebaseNow();
1187
 
1188
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1189
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
1190
                return new JsonModel([
1191
                    'success'   => false,
1192
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
1193
                ]);
1194
            }
1195
 
1196
            $commentMapper = CommentMapper::getInstance($this->adapter);
1197
            $records = $commentMapper->fetchAllPublishedByKnowledgeAreaId($knowledgeAreaContent->id);
1198
 
1199
            $comments = [];
1200
            foreach ($records as $record) {
1201
                $comment = $this->renderComment($record->id, $now);
1202
                array_push($comments, $comment);
1203
            }
1204
 
1205
            $response = [
1206
                'success' => true,
1207
                'data' => $comments
1208
            ];
1209
 
1210
            return new JsonModel($response);
1211
        } else {
1212
 
1213
 
1214
 
1215
            $response = [
1216
                'success' => false,
1217
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1218
            ];
1219
 
1220
 
1221
            return new JsonModel($response);
1222
        }
1223
    }
1224
 
1225
 
1226
 
1227
 
1228
    private function renderComment($comment_id, $now)
1229
    {
1230
        $item = [];
1231
 
1232
        $commentMapper = CommentMapper::getInstance($this->adapter);
1233
        $record = $commentMapper->fetchOne($comment_id);
1234
 
1235
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1236
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOne($record->knowledge_area_id);
1237
 
283 www 1238
 
1239
 
1 efrain 1240
        if ($record) {
283 www 1241
            $storage = Storage::getInstance($this->config);
1242
 
1243
 
1 efrain 1244
            $userMapper = UserMapper::getInstance($this->adapter);
1245
 
1246
            $user = $userMapper->fetchOne($record->user_id);
1247
 
1248
            $item['unique'] = uniqid();
283 www 1249
            $item['user_image'] = $storage->getUserImage($user);
1 efrain 1250
            $item['user_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid]);
1251
            $item['user_name'] = $user->first_name . ' ' . $user->last_name;
1252
            $item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
1253
            $item['comment'] = $record->comment;
1254
            $item['link_delete'] = $this->url()->fromRoute('knowledge-area/comments/delete', ['id' => $knowledgeAreaContent->uuid, 'comment' => $record->uuid]);
1255
        }
1256
        return $item;
1257
    }
1258
}