Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 6069 | Rev 6258 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

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