Proyectos de Subversion LeadersLinked - Services

Rev

Rev 333 | Rev 560 | 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
 
333 www 200
                $storage = Storage::getInstance($this->config, $this->adapter);
283 www 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);
334 www 358
                    $storage = Storage::getInstance($this->config, $this->adapter);
283 www 359
 
334 www 360
 
361
                    $target_path = $storage->getPathKnowledgeArea();
362
 
1 efrain 363
 
364
 
365
                    $files = $this->getRequest()->getFiles()->toArray();
366
 
367
 
368
                    if (isset($files['image']) && empty($files['image']['error'])) {
369
                        $tmp_filename  = $files['image']['tmp_name'];
370
                        $filename      = explode('.',  $files['image']['name']);
371
                        $filename       = Functions::normalizeString(uniqid() . '-' . $filename[0] . '.png');
334 www 372
 
373
 
374
                        $full_tmp_filename = $image->uploadProcessWithOutChangeSize($tmp_filename, $filename);
375
 
376
                        if($full_tmp_filename) {
377
                            if($storage->putFile($target_path, $knowledgeAreaCategory->uuid,  $full_tmp_filename)) {
378
                                $knowledgeAreaContent->image = $filename;
379
                                $knowledgeAreaContentMapper->update($knowledgeAreaContent);
380
                            }
381
                        }
1 efrain 382
 
334 www 383
 
1 efrain 384
                    }
385
 
386
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
387
                        $tmp_filename   = $files['attachment']['tmp_name'];
388
                        $filename       = Functions::normalizeString($files['attachment']['name']);
283 www 389
 
390
 
391
                        if($image->getStorage()->putFile($target_path, $knowledgeAreaCategory->uuid, $filename)) {
1 efrain 392
                            $knowledgeAreaContent->attachment = $filename;
393
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
394
                        }
395
                    }
396
 
397
 
398
                    $this->logger->info('Se agrego el contenido ' . $knowledgeAreaContent->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
399
 
400
                    $data = [
401
                        'success'   => true,
402
                        'data'   => 'LABEL_RECORD_ADDED'
403
                    ];
404
                } else {
405
                    $data = [
406
                        'success'   => false,
407
                        'data'      => $knowledgeAreaContentMapper->getError()
408
                    ];
409
                }
410
 
411
                return new JsonModel($data);
412
            } else {
413
                $messages = [];
414
                $form_messages = (array) $form->getMessages();
415
                foreach ($form_messages  as $fieldname => $field_messages) {
416
 
417
                    $messages[$fieldname] = array_values($field_messages);
418
                }
419
 
420
                return new JsonModel([
421
                    'success'   => false,
422
                    'data'   => $messages
423
                ]);
424
            }
425
        } else {
426
            $data = [
427
                'success' => false,
428
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
429
            ];
430
 
431
            return new JsonModel($data);
432
        }
433
 
434
        return new JsonModel($data);
435
    }
436
 
437
    public function deleteAction()
438
    {
439
        $currentUserPlugin = $this->plugin('currentUserPlugin');
440
        $currentUser    = $currentUserPlugin->getUser();
441
 
442
 
443
        $request    = $this->getRequest();
444
        $id         = $this->params()->fromRoute('id');
445
 
446
 
447
 
448
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
449
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
450
        if (!$knowledgeAreaContent) {
451
            return new JsonModel([
452
                'success'   => false,
453
                'data'   => 'ERROR_RECORD_NOT_FOUND'
454
            ]);
455
        }
456
 
457
 
458
 
459
        $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
460
        $knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaContent->category_id, $currentUser->id);
461
 
462
        $ok = false;
463
        if ($knowledgeAreaCategoryUser) {
464
 
465
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_EDITOR) {
466
                $ok = $knowledgeAreaContent->user_id == $currentUser->id;
467
            }
468
 
469
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR) {
470
                $ok = true;
471
            }
472
        }
473
 
474
        if (!$ok) {
475
            return new JsonModel([
476
                'success'   => false,
477
                'data'   => 'ERROR_KNOWLEDGE_AREA_YOU_DO_NOT_HAVE_PERMISSION'
478
            ]);
479
        }
480
 
481
        if ($request->isPost()) {
482
 
483
            $result =  $knowledgeAreaContentMapper->delete($knowledgeAreaContent);
484
            if ($result) {
485
                $this->logger->info('Se borro el cotenido : ' .  $knowledgeAreaContent->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
486
 
283 www 487
 
333 www 488
                $storage = Storage::getInstance($this->config, $this->adapter);
283 www 489
                $target_path = $storage->getPathKnowledgeArea();
490
 
491
 
492
                if($knowledgeAreaContent->attachment) {
493
                    $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->attachment);
494
                }
495
 
496
 
497
 
1 efrain 498
                if ($knowledgeAreaContent->image) {
283 www 499
                    $storage->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->image);
1 efrain 500
                }
501
 
502
                $data = [
503
                    'success' => true,
504
                    'data' => 'LABEL_RECORD_DELETED'
505
                ];
506
            } else {
507
 
508
                $data = [
509
                    'success'   => false,
510
                    'data'      => $knowledgeAreaContentMapper->getError()
511
                ];
512
 
513
                return new JsonModel($data);
514
            }
515
        } else {
516
            $data = [
517
                'success' => false,
518
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
519
            ];
520
 
521
            return new JsonModel($data);
522
        }
523
 
524
        return new JsonModel($data);
525
    }
526
 
527
 
528
    public function editAction()
529
    {
530
        $currentUserPlugin = $this->plugin('currentUserPlugin');
531
        $currentUser    = $currentUserPlugin->getUser();
532
 
533
        $request    = $this->getRequest();
534
        $id    = $this->params()->fromRoute('id');
535
 
536
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
537
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
538
        if (!$knowledgeAreaContent) {
539
            return new JsonModel([
540
                'success'   => false,
541
                'data'   => 'ERROR_RECORD_NOT_FOUND'
542
            ]);
543
        }
544
 
545
 
546
 
547
        $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
548
        $knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaContent->category_id, $currentUser->id);
549
 
550
        $ok = false;
551
        if ($knowledgeAreaCategoryUser) {
552
 
553
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_EDITOR) {
554
                $ok = $knowledgeAreaContent->user_id == $currentUser->id;
555
            }
556
 
557
            if ($knowledgeAreaCategoryUser->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR) {
558
                $ok = true;
559
            }
560
        }
561
 
562
        if (!$ok) {
563
            return new JsonModel([
564
                'success'   => false,
565
                'data'   => 'ERROR_KNOWLEDGE_AREA_YOU_DO_NOT_HAVE_PERMISSION'
566
            ]);
567
        }
568
 
569
        if ($request->isGet()) {
570
 
571
 
572
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
573
            $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOne($knowledgeAreaContent->category_id);
574
 
575
 
576
 
577
            $data = [
578
                'success' => true,
579
                'data' => [
580
                    'category_id' => $knowledgeAreaCategory->uuid,
581
                    'title' => $knowledgeAreaContent->title,
582
                    'description' => $knowledgeAreaContent->description,
583
                    'link' => $knowledgeAreaContent->link,
584
                ]
585
            ];
586
 
587
            return new JsonModel($data);
588
        } else if ($request->isPost()) {
589
            $category_with_edition_ids = [];
590
            $category_ids = [];
591
 
592
 
593
            $categories = [];
594
 
595
 
596
            $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
597
            $records =  $knowledgeAreaCategoryUserMapper->fetchAllByUserId($currentUser->id);
598
            foreach ($records as $record) {
599
                if ($record->role == KnowledgeAreaCategoryUser::ROLE_ADMINISTRATOR || $record->role == KnowledgeAreaCategoryUser::ROLE_USER) {
600
 
601
                    array_push($category_with_edition_ids, $record->category_id);
602
                }
603
 
604
                array_push($category_ids, $record->category_id);
605
            }
606
 
607
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
608
 
609
            if ($category_ids) {
610
                $records =  $knowledgeAreaCategoryMapper->fetchAllByIds($category_ids);
611
                foreach ($records as $record) {
612
                    if ($record->status == KnowledgeAreaCategory::STATUS_ACTIVE) {
613
 
614
                        $categories[$record->id] = [
615
                            'uuid' => $record->uuid,
616
                            'name' => $record->name,
617
                        ];
618
                    }
619
                }
620
            }
621
 
622
 
623
 
624
            $categories = array_values($categories);
625
            usort($categories, function ($a, $b) {
626
                return $a['name'] <=> $b['name'];
627
            });
628
 
629
 
630
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
631
            $form = new KnowledgeAreaEditForm($this->adapter, $category_with_edition_ids);
632
            $form->setData($dataPost);
633
 
634
            if ($form->isValid()) {
635
                $dataPost = (array) $form->getData();
636
 
637
 
638
                $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
639
                $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOneByUuid($dataPost['category_id']);
640
 
641
 
642
 
643
                $knowledgeAreaContent->category_id = $knowledgeAreaCategory->id;
644
                $knowledgeAreaContent->title = $dataPost['title'];
645
                $knowledgeAreaContent->description = $dataPost['description'];
646
 
647
 
648
                if ($knowledgeAreaContentMapper->update($knowledgeAreaContent)) {
649
 
283 www 650
                    //$target_size = $this->config['leaderslinked.image_sizes.knowledge_area'];
651
                    //list($target_width, $target_height) = explode('x', $target_size);
1 efrain 652
 
653
 
283 www 654
                    $image = Image::getInstance($this->config);
334 www 655
                    $storage = Storage::getInstance($this->config, $this->adapter);
283 www 656
                    $target_path = $image->getStorage()->getPathKnowledgeArea();
1 efrain 657
 
658
                    $files = $this->getRequest()->getFiles()->toArray();
659
 
660
 
661
                    if (isset($files['image']) && empty($files['image']['error'])) {
662
 
283 www 663
 
1 efrain 664
                        if ($knowledgeAreaContent->image) {
283 www 665
                            $image->getStorage()->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->image);
1 efrain 666
                        }
667
 
283 www 668
 
1 efrain 669
                        $tmp_filename  = $files['image']['tmp_name'];
670
                        $filename      = explode('.',  $files['image']['name']);
671
                        $filename       = Functions::normalizeString(uniqid() . '-' . $filename[0] . '.png');
334 www 672
 
283 www 673
 
334 www 674
                        $full_tmp_filename = $image->uploadProcessWithOutChangeSize($tmp_filename, $filename);
675
 
676
                        if($full_tmp_filename) {
677
                            if($storage->putFile($target_path, $knowledgeAreaCategory->uuid,  $full_tmp_filename)) {
678
                                $knowledgeAreaContent->image = $filename;
679
                                $knowledgeAreaContentMapper->update($knowledgeAreaContent);
680
                            }
1 efrain 681
                        }
334 www 682
 
1 efrain 683
                    }
684
 
685
                    if (isset($files['attachment']) && empty($files['attachment']['error'])) {
686
                        $tmp_filename   = $files['attachment']['tmp_name'];
687
                        $filename       = Functions::normalizeString($files['attachment']['name']);
283 www 688
 
1 efrain 689
                        if ($knowledgeAreaContent->attachment) {
283 www 690
                            $image->getStorage()->deleteFile($target_path, $knowledgeAreaContent->uuid, $knowledgeAreaContent->attachment);
1 efrain 691
                        }
692
 
283 www 693
                        if ($image->getStorage()->putFile($target_path, $knowledgeAreaContent->uuid, $tmp_filename)) {
1 efrain 694
                            $knowledgeAreaContent->attachment = $filename;
695
                            $knowledgeAreaContentMapper->update($knowledgeAreaContent);
696
                        }
697
                    }
698
 
699
 
700
                    $this->logger->info('Se edito el contenido ' . $knowledgeAreaContent->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
701
 
702
                    $data = [
703
                        'success'   => true,
704
                        'data'   => 'LABEL_RECORD_UPDATED'
705
                    ];
706
                } else {
707
                    $data = [
708
                        'success'   => false,
709
                        'data'      => $knowledgeAreaContentMapper->getError()
710
                    ];
711
                }
712
 
713
                return new JsonModel($data);
714
            } else {
715
                $messages = [];
716
                $form_messages = (array) $form->getMessages();
717
                foreach ($form_messages  as $fieldname => $field_messages) {
718
 
719
                    $messages[$fieldname] = array_values($field_messages);
720
                }
721
 
722
                return new JsonModel([
723
                    'success'   => false,
724
                    'data'   => $messages
725
                ]);
726
            }
727
        } else {
728
            $data = [
729
                'success' => false,
730
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
731
            ];
732
 
733
            return new JsonModel($data);
734
        }
735
 
736
        return new JsonModel($data);
737
    }
738
 
739
 
740
    public function viewAction()
741
    {
742
        $currentUserPlugin = $this->plugin('currentUserPlugin');
743
        $currentUser    = $currentUserPlugin->getUser();
744
 
745
        $request    = $this->getRequest();
746
        $id    = $this->params()->fromRoute('id');
747
 
748
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
749
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
750
        if (!$knowledgeAreaContent) {
751
            return new JsonModel([
752
                'success'   => false,
753
                'data'   => 'ERROR_RECORD_NOT_FOUND'
754
            ]);
755
        }
756
 
757
 
758
 
759
        $request = $this->getRequest();
760
        if ($request->isGet()) {
761
 
762
 
763
            $knowledgeAreaCategoryMapper = KnowledgeAreaCategoryMapper::getInstance($this->adapter);
764
            $knowledgeAreaCategory = $knowledgeAreaCategoryMapper->fetchOne($knowledgeAreaContent->category_id);
765
 
766
 
767
 
768
            $ok = false;
769
            if ($knowledgeAreaCategory->privacy == KnowledgeAreaCategory::PRIVACY_COMPANY) {
770
 
771
                $knowledgeAreaCategoryUserMapper = KnowledgeAreaCategoryUserMapper::getInstance($this->adapter);
772
                $knowledgeAreaCategoryUser = $knowledgeAreaCategoryUserMapper->fetchOneByCategoryIdAndUserId($knowledgeAreaContent->category_id, $currentUser->id);
773
 
774
 
775
                if ($knowledgeAreaCategoryUser) {
776
                    $ok = true;
777
                }
778
            }
779
            if ($knowledgeAreaCategory->privacy == KnowledgeAreaCategory::PRIVACY_PUBLIC) {
780
                $ok = true;
781
            }
782
 
783
            if (!$ok) {
784
                return new JsonModel([
785
                    'success'   => false,
786
                    'data'   => 'ERROR_KNOWLEDGE_AREA_YOU_DO_NOT_HAVE_PERMISSION'
787
                ]);
788
            }
789
 
790
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
791
            $contentReaction = $contentReactionMapper->fetchOneByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id);
792
 
793
 
333 www 794
            $storage = Storage::getInstance($this->config, $this->adapter);
283 www 795
            $path = $storage->getPathKnowledgeArea();
1 efrain 796
 
797
                return new JsonModel([
798
                    'success' => true,
799
                    'data' => [
800
                        'category' => $knowledgeAreaCategory->name,
801
                        'title' => $knowledgeAreaContent->title,
802
                        'description' => $knowledgeAreaContent->description,
803
                        'link' => $knowledgeAreaContent->link,
283 www 804
                        'image' =>  $storage->getGenericImage($path, $knowledgeAreaContent->uuid,  $knowledgeAreaContent->image),
805
                        'attachment' =>  $knowledgeAreaContent->attachment ? $storage->getGenericFile($path, $knowledgeAreaContent->uuid,  $knowledgeAreaContent->attachment) : '',
1 efrain 806
                        'reaction' => $contentReaction ? $contentReaction->reaction : '',
242 efrain 807
                        'routeComments' => $this->url()->fromRoute('knowledge-area/comments', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
808
                        'routeCommentAdd' => $this->url()->fromRoute('knowledge-area/comments/add', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
809
                        'routeSaveReaction' => $this->url()->fromRoute('knowledge-area/save-reaction', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
810
                        'routeDeleteReaction' => $this->url()->fromRoute('knowledge-area/delete-reaction', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
811
                        'routeReactions' => $this->url()->fromRoute('knowledge-area/reactions', ['id' => $knowledgeAreaContent->uuid],['force_canonical' => true]),
1 efrain 812
                    ]
813
                ]);
814
 
815
        } else {
816
            $data = [
817
                'success' => false,
818
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
819
            ];
820
 
821
            return new JsonModel($data);
822
        }
823
 
824
        return new JsonModel($data);
825
    }
242 efrain 826
 
827
    public function reactionsAction()
828
    {
829
        $id = $this->params()->fromRoute('id');
830
 
831
        $request = $this->getRequest();
832
        $request = $this->getRequest();
833
        if ($request->isGet()) {
834
 
835
            $currentUserPlugin = $this->plugin('currentUserPlugin');
836
            $currentUser = $currentUserPlugin->getUser();
837
 
838
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
839
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
840
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
841
                return new JsonModel([
842
                    'success'   => false,
843
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
844
                ]);
845
            }
846
 
847
 
848
 
849
            $userMapper = UserMapper::getInstance($this->adapter);
850
 
851
            $items = [];
852
 
333 www 853
            $storage = Storage::getInstance($this->config, $this->adapter);
283 www 854
            $path = $storage->getPathKnowledgeArea();
855
 
242 efrain 856
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
857
            $records = $contentReactionMapper->fetchAllByKnowledgeAreaId($knowledgeAreaContent->id);
858
 
859
            foreach($records as $record)
860
            {
861
                $user = $userMapper->fetchOne($record->user_id);
862
                if($user && $user->status == User::STATUS_ACTIVE) {
863
 
864
                    array_push($items, [
865
                        'first_name' => $user->first_name,
866
                        'last_name' => $user->last_name,
867
                        'email' => $user->email,
283 www 868
                        'image' => $storage->getGenericImage($path, $user->uuid, $user->image),
242 efrain 869
                        'reaction' => $record->reaction,
870
                    ]);
871
                }
872
            }
873
 
874
            $response = [
875
                'success' => true,
876
                'data' => $items
877
            ];
878
 
879
            return new JsonModel($response);
880
 
881
 
882
 
883
 
884
        } else {
885
            $response = [
886
                'success' => false,
887
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
888
            ];
889
 
890
            return new JsonModel($response);
891
        }
892
    }
1 efrain 893
 
894
 
895
    public function addCommentAction()
896
    {
897
        $currentUserPlugin = $this->plugin('currentUserPlugin');
898
        $currentUser    = $currentUserPlugin->getUser();
899
 
900
        $id = $this->params()->fromRoute('id');
901
 
902
        $request = $this->getRequest();
903
        if ($request->isPost()) {
904
 
905
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
906
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
907
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
908
                return new JsonModel([
909
                    'success'   => false,
910
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
911
                ]);
912
            }
913
 
914
 
915
 
916
 
917
            $dataPost = $request->getPost()->toArray();
918
            $form = new CommentForm();
919
            $form->setData($dataPost);
920
 
921
            if ($form->isValid()) {
242 efrain 922
 
1 efrain 923
                $dataPost = (array) $form->getData();
924
 
925
                $comment = new Comment();
926
                $comment->network_id = $currentUser->network_id;
927
                $comment->comment = $dataPost['comment'];
928
                $comment->user_id = $currentUser->id;
929
                $comment->knowledge_area_id = $knowledgeAreaContent->id;
930
                $comment->relational = Comment::RELATIONAL_KNOWLEDGE_AREA;
931
 
932
                $commentMapper = CommentMapper::getInstance($this->adapter);
933
                $now = $commentMapper->getDatebaseNow();
934
 
935
                if ($commentMapper->insert($comment)) {
936
 
937
                    $total_comments = $commentMapper->fetchCountCommentByKnowledgeAreaId($comment->knowledge_area_id);
938
 
939
                    $knowledgeAreaContent->total_comments = $total_comments;
940
                    $knowledgeAreaContentMapper->update($knowledgeAreaContent);
941
 
942
                    $response = [
943
                        'success'   => true,
944
                        'data'   => $this->renderComment($comment->id, $now),
945
                        'total_comments' => $total_comments
946
                    ];
947
 
948
                    return new JsonModel($response);
949
                } else {
950
 
951
                    $response = [
952
                        'success'   => false,
953
                        'data'   => $commentMapper->getError()
954
                    ];
955
 
956
                    return new JsonModel($response);
957
                }
958
            } else {
959
                $message = '';;
960
                $form_messages = (array) $form->getMessages();
961
                foreach ($form_messages  as $fieldname => $field_messages) {
962
                    foreach ($field_messages as $key => $value) {
963
                        $message = $value;
964
                    }
965
                }
966
 
967
                $response = [
968
                    'success'   => false,
969
                    'data'   => $message
970
                ];
971
 
972
                return new JsonModel($response);
973
            }
974
        } else {
975
            $response = [
976
                'success' => false,
977
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
978
            ];
979
 
980
            return new JsonModel($response);
981
        }
982
    }
983
 
984
 
985
 
986
    public function deleteCommentAction()
987
    {
988
        $currentUserPlugin = $this->plugin('currentUserPlugin');
989
        $currentUser    = $currentUserPlugin->getUser();
990
 
991
        $request = $this->getRequest();
992
        if ($request->isPost()) {
993
 
994
            $id = $this->params()->fromRoute('id');
995
            $comment = $this->params()->fromRoute('comment');
996
 
997
 
998
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
999
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1000
 
1001
 
1002
 
1003
            if ($knowledgeAreaContent && $knowledgeAreaContent->network_id == $currentUser->network_id) {
1004
 
1005
                $commentMapper = CommentMapper::getInstance($this->adapter);
1006
                $comment = $commentMapper->fetchOneByUuid($comment);
1007
 
1008
 
1009
                if ($comment && $comment->knowledge_area_id == $knowledgeAreaContent->id && $comment->user_id == $currentUser->id) {
1010
 
1011
                    $comment->status = Comment::STATUS_DELETED;
1012
 
1013
                    if ($commentMapper->update($comment)) {
1014
 
1015
                        $total_comments = $commentMapper->fetchCountCommentByKnowledgeAreaId($knowledgeAreaContent->id);
1016
                        $knowledgeAreaContent->total_comments = $total_comments;
1017
                        $knowledgeAreaContentMapper->update($knowledgeAreaContent);
1018
 
1019
                        $response = [
1020
                            'success' => true,
1021
                            'data' => 'LABEL_COMMENT_WAS_DELETED',
1022
                            'total_comments' => $total_comments
1023
                        ];
1024
                    } else {
1025
                        $response = [
1026
                            'success' => false,
1027
                            'data' => $commentMapper->getError()
1028
                        ];
1029
                    }
1030
                } else {
1031
                    $response = [
1032
                        'success' => false,
1033
                        'data' => 'ERROR_COMMENT_NOT_FOUND'
1034
                    ];
1035
                }
1036
            } else {
1037
                $response = [
1038
                    'success' => false,
1039
                    'data' => 'ERROR_COMMENT_NOT_FOUND'
1040
                ];
1041
            }
1042
        } else {
1043
            $response = [
1044
                'success' => false,
1045
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1046
            ];
1047
        }
1048
 
1049
        return new JsonModel($response);
1050
    }
1051
 
1052
 
1053
 
1054
    public function saveReactionAction()
1055
    {
1056
 
1057
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1058
        $currentUser    = $currentUserPlugin->getUser();
1059
 
1060
        $id = $this->params()->fromRoute('id');
1061
        $reaction  = $this->params()->fromPost('reaction');
1062
 
1063
        $request = $this->getRequest();
1064
        if ($request->isPost()) {
1065
 
1066
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1067
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1068
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
1069
                return new JsonModel([
1070
                    'success'   => false,
1071
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
1072
                ]);
1073
            }
1074
 
1075
            $reactions = [
1076
                ContentReaction::REACTION_RECOMMENDED,
1077
                ContentReaction::REACTION_SUPPORT,
1078
                ContentReaction::REACTION_LOVE,
1079
                ContentReaction::REACTION_INTEREST,
1080
                ContentReaction::REACTION_FUN
1081
 
1082
            ];
1083
            if(!in_array($reaction, $reactions)) {
1084
                $response = [
1085
                    'success' => false,
1086
                    'data' => 'ERROR_REACTION_NOT_FOUND'
1087
                ];
1088
                return new JsonModel($response);
1089
            }
1090
 
1091
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
1092
            $contentReaction = $contentReactionMapper->fetchOneByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id);
1093
 
1094
            if ($contentReaction) {
1095
                $contentReaction->reaction = $reaction;
1096
 
1097
                $result = $contentReactionMapper->update($contentReaction);
1098
            } else {
1099
                $contentReaction = new ContentReaction();
1100
                $contentReaction->user_id = $currentUser->id;
1101
                $contentReaction->knowledge_area_id = $knowledgeAreaContent->id;
1102
                $contentReaction->relational = ContentReaction::RELATIONAL_KNOWLEDGE_AREA;
1103
                $contentReaction->reaction = $reaction;
1104
 
1105
                $result = $contentReactionMapper->insert($contentReaction);
1106
            }
1107
 
1108
 
1109
 
1110
            if ($result) {
1111
 
1112
                $reactions = $contentReactionMapper->fetchCountByKnowledgeAreaId($knowledgeAreaContent->id);
1113
                $response = [
1114
                    'success' => true,
1115
                    'data' => [
1116
                        'reactions' => $reactions
1117
                    ]
1118
                ];
1119
            } else {
1120
                $response = [
1121
                    'success' => false,
1122
                    'data' => $contentReactionMapper->getError()
1123
                ];
1124
            }
1125
            return new JsonModel($response);
1126
        }
1127
 
1128
        $response = [
1129
            'success' => false,
1130
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1131
        ];
1132
        return new JsonModel($response);
1133
    }
1134
 
1135
    public function deleteReactionAction()
1136
    {
1137
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1138
        $currentUser    = $currentUserPlugin->getUser();
1139
 
1140
        $id = $this->params()->fromRoute('id');
1141
 
1142
        $request = $this->getRequest();
1143
        if ($request->isPost()) {
1144
 
1145
 
1146
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1147
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1148
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
1149
                return new JsonModel([
1150
                    'success'   => false,
1151
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
1152
                ]);
1153
            }
1154
 
1155
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
1156
            $contentReaction = $contentReactionMapper->fetchOneByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id);
1157
 
1158
            if (!$contentReaction) {
1159
                $response = [
1160
                    'success' => false,
1161
                    'data' => 'ERROR_DUPLICATE_ACTION'
1162
                ];
1163
                return new JsonModel($response);
1164
            }
1165
 
1166
            if ($contentReactionMapper->deleteByKnowledgeAreaIdAndUserId($knowledgeAreaContent->id, $currentUser->id)) {
1167
                $reactions = $contentReactionMapper->fetchCountByKnowledgeAreaId($knowledgeAreaContent->id);
1168
 
1169
                $response = [
1170
                    'success' => true,
1171
                    'data' => [
1172
                        'reactions' => $reactions
1173
                    ]
1174
                ];
1175
            } else {
1176
                $response = [
1177
                    'success' => false,
1178
                    'data' => $contentReactionMapper->getError()
1179
                ];
1180
            }
1181
            return new JsonModel($response);
1182
        }
1183
 
1184
        $response = [
1185
            'success' => false,
1186
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1187
        ];
1188
        return new JsonModel($response);
1189
    }
1190
 
1191
    public function commentsAction()
1192
    {
1193
        $id = $this->params()->fromRoute('id');
1194
 
1195
        $request = $this->getRequest();
1196
        if ($request->isGet()) {
1197
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1198
            $currentUser = $currentUserPlugin->getUser();
1199
 
1200
            $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1201
            $now = $knowledgeAreaContentMapper->getDatebaseNow();
1202
 
1203
            $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOneByUuid($id);
1204
            if (!$knowledgeAreaContent || $knowledgeAreaContent->network_id != $currentUser->network_id) {
1205
                return new JsonModel([
1206
                    'success'   => false,
1207
                    'data'   => 'ERROR_RECORD_NOT_FOUND'
1208
                ]);
1209
            }
1210
 
1211
            $commentMapper = CommentMapper::getInstance($this->adapter);
1212
            $records = $commentMapper->fetchAllPublishedByKnowledgeAreaId($knowledgeAreaContent->id);
1213
 
1214
            $comments = [];
1215
            foreach ($records as $record) {
1216
                $comment = $this->renderComment($record->id, $now);
1217
                array_push($comments, $comment);
1218
            }
1219
 
1220
            $response = [
1221
                'success' => true,
1222
                'data' => $comments
1223
            ];
1224
 
1225
            return new JsonModel($response);
1226
        } else {
1227
 
1228
 
1229
 
1230
            $response = [
1231
                'success' => false,
1232
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1233
            ];
1234
 
1235
 
1236
            return new JsonModel($response);
1237
        }
1238
    }
1239
 
1240
 
1241
 
1242
 
1243
    private function renderComment($comment_id, $now)
1244
    {
1245
        $item = [];
1246
 
1247
        $commentMapper = CommentMapper::getInstance($this->adapter);
1248
        $record = $commentMapper->fetchOne($comment_id);
1249
 
1250
        $knowledgeAreaContentMapper = KnowledgeAreaContentMapper::getInstance($this->adapter);
1251
        $knowledgeAreaContent = $knowledgeAreaContentMapper->fetchOne($record->knowledge_area_id);
1252
 
283 www 1253
 
1254
 
1 efrain 1255
        if ($record) {
333 www 1256
            $storage = Storage::getInstance($this->config, $this->adapter);
283 www 1257
 
1258
 
1 efrain 1259
            $userMapper = UserMapper::getInstance($this->adapter);
1260
 
1261
            $user = $userMapper->fetchOne($record->user_id);
1262
 
1263
            $item['unique'] = uniqid();
283 www 1264
            $item['user_image'] = $storage->getUserImage($user);
1 efrain 1265
            $item['user_url'] = $this->url()->fromRoute('profile/view', ['id' => $user->uuid]);
1266
            $item['user_name'] = $user->first_name . ' ' . $user->last_name;
1267
            $item['time_elapsed'] = Functions::timeAgo($record->added_on, $now);
1268
            $item['comment'] = $record->comment;
1269
            $item['link_delete'] = $this->url()->fromRoute('knowledge-area/comments/delete', ['id' => $knowledgeAreaContent->uuid, 'comment' => $record->uuid]);
1270
        }
1271
        return $item;
1272
    }
1273
}