Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7231 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 7231 Rev 7233
Línea 1... Línea 1...
1
<?php
1
<?php
2
/**
-
 
3
 * 
-
 
4
 * Controlador: Mis Perfiles 
-
 
5
 * 
-
 
6
 */
-
 
7
declare(strict_types=1);
2
declare(strict_types=1);
Línea 8... Línea 3...
8
 
3
 
Línea -... Línea 4...
-
 
4
namespace LeadersLinked\Controller;
-
 
5
 
9
namespace LeadersLinked\Controller;
6
use Laminas\Authentication\AuthenticationService;
10
 
7
use Laminas\Authentication\Result as AuthResult;
11
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Db\Adapter\AdapterInterface;
-
 
9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
12
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
10
use Laminas\Mvc\Controller\AbstractActionController;
13
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Mvc\I18n\Translator;
14
use Laminas\Log\LoggerInterface;
12
use Laminas\Log\LoggerInterface;
15
use Laminas\View\Model\ViewModel;
-
 
16
use Laminas\View\Model\JsonModel;
13
use Laminas\View\Model\ViewModel;
17
 
14
use Laminas\View\Model\JsonModel;
18
use LeadersLinked\Library\Functions;
-
 
19
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
-
 
20
 
15
use LeadersLinked\Model\HighPerformanceTeamsGroups;
21
use LeadersLinked\Library\Image;
16
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
22
use LeadersLinked\Form\MyGroups\CreateForm;
17
use LeadersLinked\Form\HighPerformanceTeamsGroupsForm;
23
use LeadersLinked\Model\Group;
-
 
24
use LeadersLinked\Mapper\GroupMapper;
-
 
25
use LeadersLinked\Form\MyGroup\AccessibilityForm;
-
 
26
use LeadersLinked\Form\MyGroup\CoverForm;
-
 
27
use LeadersLinked\Form\MyGroup\ExtendedForm;
-
 
28
use LeadersLinked\Form\MyGroup\GroupTypeForm;
-
 
29
use LeadersLinked\Form\MyGroup\ImageForm;
-
 
30
use LeadersLinked\Form\MyGroup\IndustryForm;
-
 
31
use LeadersLinked\Form\MyGroup\PrivacyForm;
-
 
32
use LeadersLinked\Form\MyGroup\WebsiteForm;
-
 
33
use LeadersLinked\Mapper\IndustryMapper;
18
use LeadersLinked\Library\Functions;
34
use LeadersLinked\Mapper\GroupTypeMapper;
19
use LeadersLinked\Mapper\UserMapper;
35
use LeadersLinked\Mapper\GroupMemberMapper;
-
 
Línea 36... Línea 20...
36
use LeadersLinked\Mapper\QueryMapper;
20
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
37
use LeadersLinked\Model\GroupMember;
21
use LeadersLinked\Mapper\CompanyMapper;
38
 
22
 
39
class HighPerformanceTeamsGroupsController extends AbstractActionController
23
class HighPerformanceTeamsGroupsController extends AbstractActionController
Línea 54... Línea 38...
54
    /**
38
    /**
55
     *
39
     *
56
     * @var  LoggerInterface
40
     * @var  LoggerInterface
57
     */
41
     */
58
    private $logger;
42
    private $logger;
59
 
-
 
Línea 60... Línea 43...
60
    
43
    
61
    /**
44
    /**
62
     *
45
     *
63
     * @var array
46
     * @var array
64
     */
47
     */
Línea -... Línea 48...
-
 
48
    private $config;
-
 
49
    
65
    private $config;
50
    
66
    
51
    
67
    /**
52
    /**
68
     *
53
     *
69
     * @param AdapterInterface $adapter
54
     * @param AdapterInterface $adapter
70
     * @param AbstractAdapter $cache
55
     * @param AbstractAdapter $cache
71
     * @param LoggerInterface $logger
56
     * @param LoggerInterface $logger
72
     * @param array $config
57
     * @param array $config
73
     */
58
     */
74
    public function __construct($adapter, $cache , $logger,  $config)
59
    public function __construct($adapter, $cache , $logger, $config)
75
    {
60
    {
76
        $this->adapter      = $adapter;
61
        $this->adapter      = $adapter;
77
        $this->cache        = $cache;
62
        $this->cache        = $cache;
-
 
63
        $this->logger       = $logger;
78
        $this->logger       = $logger;
64
        $this->config       = $config;
79
        $this->config       = $config;
65
        
Línea 80... Línea 66...
80
 
66
        
81
    }
67
    }
82
    
-
 
83
    /**
-
 
84
     * 
-
 
85
     * Generación del listado de perfiles
68
    
86
     * {@inheritDoc}
69
   
87
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
70
 
-
 
71
        
-
 
72
    public function indexAction()
88
     */
73
    {
89
    public function indexAction()
74
 
-
 
75
        
-
 
76
        $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 90... Línea 77...
90
    {
77
        $currentUser = $currentUserPlugin->getUser();
91
        $currentUserPlugin = $this->plugin('currentUserPlugin');
78
        $currentCompany = $currentUserPlugin->getCompany();
Línea 112... Línea 99...
112
                    
99
                    
113
                }
100
                }
Línea 114... Línea 101...
114
            }
101
            }
115
            
-
 
Línea -... Línea 102...
-
 
102
            
116
            if($isJson) {
103
            if($isJson) {
117
                $search = trim(filter_var($this->params()->fromQuery('search', ''), FILTER_SANITIZE_STRING));
-
 
118
                
104
                
119
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
105
               
120
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/view');
-
 
Línea 121... Línea -...
121
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/my-groups/edit');
-
 
Línea 122... Línea -...
122
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/my-groups/delete');
-
 
123
                
-
 
124
                
-
 
125
                $queryMapper = QueryMapper::getInstance($this->adapter);
106
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
126
                
-
 
127
                $select = $queryMapper->getSql()->select(GroupMapper::_TABLE);
107
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/edit');
128
                $select->columns(['id', 'uuid', 'name', 'privacy',  'image', 'status']);
-
 
129
                $select->where->equalTo('status', Group::STATUS_ACTIVE);
108
                $allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/delete');
130
                
-
 
Línea 131... Línea -...
131
                if($search) {
-
 
Línea -... Línea 109...
-
 
109
                
-
 
110
                
-
 
111
 
-
 
112
                $search = $this->params()->fromQuery('search', []);
-
 
113
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
-
 
114
                
-
 
115
                
-
 
116
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
Línea 132... Línea -...
132
                    $select->where->like('name', '%' . $search . '%');
-
 
133
                }
117
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
134
                $select->where->equalTo('user_id', $currentUser->id);
118
                $order =  $this->params()->fromQuery('order', []);
135
                $select->order('name ASC');
119
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
-
 
120
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
Línea -... Línea 121...
-
 
121
    
-
 
122
                $fields =  ['title', 'date'];
136
                
123
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
-
 
124
                
-
 
125
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
-
 
126
                    $order_direction = 'ASC';
137
                $records = $queryMapper->fetchAll($select);
127
                }
138
                
128
 
-
 
129
 
139
                
130
                
-
 
131
                $paginator = $highPerformanceTeamsGroupsMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction, $currentCompany->id);
140
                $values = [
132
               
141
                    Group::PRIVACY_IS_PRIVATE => 'LABEL_PRIVATE',
133
                $items = [];
142
                    Group::PRIVACY_IS_PUBLIC => 'LABEL_PUBLIC'
134
            
143
                ];
135
                $records = $paginator->getCurrentItems();
-
 
136
               
144
 
137
                foreach($records as $record)
145
                
138
                {
146
                $items = [];
139
 
Línea -... Línea 140...
-
 
140
                   
-
 
141
 
147
                foreach($records as $record)
142
                    $item = [
-
 
143
                        'title' => $record->title,
Línea 148... Línea 144...
148
                {
144
                        'description' => $record->description,
-
 
145
                        'status'=> $record->status,
149
                    
146
                        'actions' => [
150
                    $item = [
-
 
151
                        'name' => $record['name'],
147
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/edit', ['id' => $record->uuid]) : '',
152
                        'privacy' => $values[$record['privacy']],
-
 
153
                        'image' => $this->url()->fromRoute('storage', ['type' => 'group', 'code' => $record['uuid'], 'filename' => $record['image'] ]),
148
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/delete', ['id' => $record->uuid]) : '',
154
                        'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/view', ['id' => $record['uuid'] ])  : '',
149
                            'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view', ['id' => $record->uuid]) : '',
155
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/my-groups/edit', ['id' => $record['uuid'] ])  : '',
150
                        
156
                        'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/my-groups/delete', ['id' => $record['uuid'] ]) : '',
-
 
157
                        
-
 
158
                    ];
-
 
159
                    
-
 
160
                    array_push($items, $item);
-
 
161
                }
-
 
162
 
151
                        ]
163
                
-
 
164
                
-
 
165
                $response = [
-
 
166
                    'success' => true,
-
 
167
                    'data' => $items
-
 
168
                ];
-
 
169
                
-
 
170
                return new JsonModel($response);
-
 
171
                
-
 
172
                
152
 
173
            } else {
-
 
174
                $industries = [];
153
                    ];
175
                $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
176
                $records = $industryMapper->fetchAllActives();
154
                   
177
                foreach($records as $record)
-
 
178
                {
-
 
Línea -... Línea 155...
-
 
155
                    
-
 
156
                    array_push($items, $item);
179
                    $industries[$record->uuid] = $record->name;
157
                    
180
                }
158
                }
181
                
159
                 
182
                $groupTypes = [];
160
                return new JsonModel([
183
                $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
-
 
184
                $records = $groupTypeMapper->fetchAllActives();
-
 
185
                foreach($records as $record)
161
                    'success' => true,
186
                {
162
                    'data' => [
187
                    $groupTypes[$record->uuid] = $record->name;
163
                        'items' => $items,
188
                }
164
                        'total' => $paginator->getTotalItemCount(),
189
                
-
 
190
                $formAdd = new CreateForm($this->adapter);
165
                    ]
191
                
166
                ]);
192
                $this->layout()->setTemplate('layout/layout-backend');
167
                
193
                $viewModel = new ViewModel();
168
            } else  {
194
                $viewModel->setTemplate('leaders-linked/high-performance-teams-my-groups/index.phtml');
169
                $formAdd = new HighPerformanceTeamsGroupsForm();
195
                $viewModel->setVariables([
170
                $this->layout()->setTemplate('layout/layout-backend');
196
                    'industries' => $industries,
171
                $viewModel = new ViewModel();
197
                    'types' => $groupTypes,
172
                $viewModel->setTemplate('leaders-linked/high-performance-teams-groups/index.phtml');
198
                    'formAdd' => $formAdd
-
 
199
                ]);
-
 
200
                return $viewModel ;
-
 
201
            }
-
 
202
            
-
 
203
        } else {
173
                $viewModel->setVariables([
204
            return new JsonModel([
174
                    'formAdd' => $formAdd,                    
-
 
175
                ]);
-
 
176
                return $viewModel ;
-
 
177
            }
-
 
178
        } else {
205
                'success' => false,
179
            return new JsonModel([
206
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
207
            ]);
-
 
208
        }
180
                'success' => false,
209
    }
181
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
210
    
182
            ]);
Línea 211... Línea 183...
211
    /**
183
        }
Línea 212... Línea 184...
212
     * 
184
    }
213
     * Agregar un nuevo perfil
-
 
214
     * @return \Laminas\View\Model\JsonModel
-
 
215
     */
-
 
216
    public function addAction()
-
 
217
    {
-
 
218
        $request = $this->getRequest();
185
/*
-
 
186
    public function addAction()
-
 
187
    {
Línea 219... Línea 188...
219
        
188
      $currentUserPlugin = $this->plugin('currentUserPlugin');
220
        
-
 
221
        if($request->isPost()) {
-
 
222
            $form = new  CreateForm($this->adapter);
189
        $currentUser = $currentUserPlugin->getUser();
223
            $dataPost = $request->getPost()->toArray();
-
 
224
            
-
 
225
            $form->setData($dataPost);
-
 
226
            
-
 
227
            if($form->isValid()) {
190
        $currentCompany = $currentUserPlugin->getCompany();
228
                
-
 
229
                
-
 
230
                $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
Línea 231... Línea 191...
231
                $currentUser = $currentUserPlugin->getUser();
191
 
232
                
192
        $request = $this->getRequest();
Línea 233... Línea 193...
233
                $dataPost = (array) $form->getData();
193
        if($request->isPost()) {
234
 
-
 
235
                $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
236
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
-
 
237
                
-
 
238
                $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
-
 
239
                $groupType = $groupTypeMapper->fetchOneByUuid($dataPost['type_id']);
-
 
240
                
-
 
241
                
-
 
242
                $group = new Group();
-
 
243
                $group->name = $dataPost['name'];
-
 
244
                $group->industry_id = $industry->id;
194
            $form = new  HighPerformanceTeamsGroupsForm();
Línea 245... Línea 195...
245
                $group->type_id = $groupType->id;
195
            $dataPost = $request->getPost()->toArray();
246
                $group->user_id = $currentUser->id;
196
            
247
                
197
            $form->setData($dataPost);
248
                $groupMapper = GroupMapper::getInstance($this->adapter);
198
            
249
                $result = $groupMapper->insert($group );
199
            if($form->isValid()) {
250
                
200
                $dataPost = (array) $form->getData();
251
                if($result) {
201
                $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : HighPerformanceTeamsGroups::STATUS_INACTIVE;
252
                    
202
                $dataPost['company_id']=$currentCompany->id;
253
                    $groupMember = new GroupMember();
203
 
Línea 254... Línea 204...
254
                    $groupMember->group_id = $group->id;
204
                $hydrator = new ObjectPropertyHydrator();
Línea 255... Línea 205...
255
                    $groupMember->user_id = $group->user_id;
205
                $highPerformanceTeamsGroups = new HighPerformanceTeamsGroups();
Línea 287... Línea 237...
287
                return new JsonModel([
237
                return new JsonModel([
288
                    'success'   => false,
238
                    'success'   => false,
289
                    'data'   => $messages
239
                    'data'   => $messages
290
                ]);
240
                ]);
291
            }
241
            }
292
            
242
 
293
        } else {
243
        } else {
294
            $data = [
244
            $data = [
295
                'success' => false,
245
                'success' => false,
296
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
246
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
297
            ];
247
            ];
Línea 298... Línea 248...
298
            
248
            
299
            return new JsonModel($data);
249
            return new JsonModel($data);
Línea 300... Línea 250...
300
        }
250
        }
301
        
-
 
Línea 302... Línea 251...
302
        return new JsonModel($data);
251
        
303
    }
252
        return new JsonModel($data);
-
 
253
    
-
 
254
     
-
 
255
    }
304
    
256
 
-
 
257
 
305
    /**
258
 
306
     * 
259
     public function editAction(){
307
     * Borrar un perfil excepto el público
260
 
308
     * @return \Laminas\View\Model\JsonModel
-
 
309
     */
261
        $currentUserPlugin = $this->plugin('currentUserPlugin');
310
    public function deleteAction()
262
        $currentUser = $currentUserPlugin->getUser();
-
 
263
        $currentCompany = $currentUserPlugin->getCompany();
Línea 311... Línea 264...
311
    {
264
        $request = $this->getRequest();
312
        $request = $this->getRequest();
265
        $uuid = $this->params()->fromRoute('id');
313
        $id = $this->params()->fromRoute('id');
266
 
314
        
267
        
315
        if(!$id) {
268
        if(!$uuid) {
Línea 316... Línea 269...
316
            $data = [
269
            $data = [
317
                'success'   => false,
270
                'success'   => false,
318
                'data'   => 'ERROR_INVALID_PARAMETER'
-
 
319
            ];
-
 
320
            
-
 
321
            return new JsonModel($data);
-
 
322
        }
-
 
323
        
-
 
324
        
-
 
325
        
-
 
326
        $groupMapper =GroupMapper::getInstance($this->adapter);
-
 
327
        $group = $groupMapper->fetchOneByUuid($id);
-
 
328
        if(!$group) {
-
 
329
            $data = [
-
 
330
                'success'   => false,
-
 
331
                'data'   => 'ERROR_RECORD_NOT_FOUND'
-
 
332
            ];
-
 
333
            
-
 
334
            return new JsonModel($data);
-
 
335
        }
-
 
336
        
-
 
337
        $currentUser = $this->plugin('currentUserPlugin');
-
 
338
        if($currentUser->getUserId() != $group->user_id) {
-
 
339
            $response = [
-
 
340
                'success' => false,
-
 
Línea 341... Línea -...
341
                'data' => 'ERROR_UNAUTHORIZED'
-
 
342
            ];
-
 
343
            
-
 
344
            return new JsonModel($response);
-
 
345
        }
271
                'data'   => 'ERROR_INVALID_PARAMETER'
346
 
-
 
347
        
-
 
348
        if($request->isPost()) {
-
 
349
            $result = $groupMapper->delete($group);
-
 
350
            if($result) {
-
 
351
                $this->logger->info('Se borro el grupo : ' .  $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
-
 
352
                
-
 
353
                $data = [
-
 
354
                    'success' => true,
-
 
355
                    'data' => 'LABEL_RECORD_DELETED'
272
            ];
356
                ];
-
 
357
            } else {
-
 
358
                
-
 
359
                $data = [
-
 
360
                    'success'   => false,
273
            
361
                    'data'      => $groupMapper->getError()
274
            return new JsonModel($data);
362
                ];
275
        }
363
                
276
 
364
                return new JsonModel($data);
277
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
365
            }
-
 
366
            
-
 
367
        } else {
-
 
368
            $data = [
-
 
369
                'success' => false,
-
 
370
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
371
            ];
-
 
372
            
-
 
373
            return new JsonModel($data);
-
 
374
        }
-
 
375
        
-
 
376
        return new JsonModel($data);
-
 
377
    }
-
 
378
    
-
 
379
    /**
-
 
380
     * Presenta el perfil con las opciónes de edición de cada sección
-
 
381
     * @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
-
 
382
     */
-
 
383
    public function editAction()
-
 
384
    {
-
 
385
        $flashMessenger = $this->plugin('FlashMessenger');
-
 
386
        
-
 
387
        
-
 
388
        $request = $this->getRequest();
-
 
389
        $id = $this->params()->fromRoute('id');
-
 
390
        
-
 
391
        
-
 
392
        if(!$id) {
-
 
393
            $flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
-
 
394
            return $this->redirect()->toRoute('dashboard');
-
 
395
        }
-
 
396
        
-
 
397
        
-
 
398
        
-
 
399
        $groupMapper =GroupMapper::getInstance($this->adapter);
-
 
400
        $group = $groupMapper->fetchOneByUuid($id);
-
 
401
        if(!$group) {
-
 
402
            $flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
-
 
403
            return $this->redirect()->toRoute('dashboard');
-
 
404
        }
-
 
405
        
-
 
406
        $currentUser = $this->plugin('currentUserPlugin');
-
 
407
        if($currentUser->getUserId() != $group->user_id) {
-
 
408
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
-
 
409
            return $this->redirect()->toRoute('dashboard');
-
 
410
        }
-
 
411
        
-
 
412
        
-
 
413
        if($request->isGet()) {
-
 
414
            
-
 
415
            $accessibilities = [
-
 
416
                Group::ACCESSIBILITY_AUTO_JOIN => 'LABEL_AUTO_JOIN',
-
 
417
                Group::ACCESSIBILITY_REQUEST_TO_JOIN => 'LABEL_REQUEST_TO_JOIN',
-
 
418
                Group::ACCESSIBILITY_ADMIN_WILL_ADD => 'LABEL_ADMIN_WILL_ADD',
-
 
419
            ];
-
 
420
            
278
        $objectives = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($uuid);
421
            $accessibility = $accessibilities[$group->accessibility];
-
 
422
            
-
 
423
            $privacies = [
-
 
424
                Group::PRIVACY_IS_PRIVATE => 'LABEL_PRIVATE',
-
 
425
                Group::PRIVACY_IS_PUBLIC => 'LABEL_PUBLIC'
-
 
426
            ];
-
 
427
            
-
 
428
            $privacy = $privacies[$group->privacy];
-
 
429
            
-
 
430
            $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
431
            $record = $industryMapper->fetchOne($group->industry_id);
-
 
432
            
-
 
433
            $industry = $record->name;
-
 
434
            
-
 
435
            
-
 
436
            $industries = [];
-
 
437
            $records = $industryMapper->fetchAllActives();
-
 
438
            foreach($records as $record)
-
 
439
            {
-
 
440
                $industries[$record->uuid] = $record->name;
-
 
441
            }
-
 
442
            
-
 
443
            
-
 
444
            $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
-
 
445
            $record = $groupTypeMapper->fetchOne($group->type_id);
-
 
446
            
-
 
447
            $group_type = $record->name;
-
 
448
            
-
 
449
            $types = [];
-
 
Línea 450... Línea -...
450
            $records =  $groupTypeMapper->fetchAllActives();
-
 
451
            foreach($records as $record)
-
 
452
            {
-
 
453
                $types[$record->uuid] = $record->name;
-
 
454
            }
-
 
455
            
-
 
456
 
-
 
457
            
-
 
458
            $formExtended = new ExtendedForm();
-
 
459
            $formAccessibility = new AccessibilityForm();
-
 
460
            $formPrivacy = new PrivacyForm();
-
 
461
            $formType = new GroupTypeForm($this->adapter);
-
 
462
            $formIndustry = new IndustryForm($this->adapter);
-
 
463
            $formImage = new ImageForm($this->config);
-
 
464
            $formCover = new CoverForm($this->config);
-
 
465
            $formWebsite = new WebsiteForm();
-
 
466
            
-
 
467
 
-
 
468
            $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
-
 
469
            $total_members = $groupMemberMapper->fetchTotalByGroupId($group->id);
-
 
470
            
-
 
471
            $image_size_cover = $this->config['leaderslinked.image_sizes.group_cover_upload'];
-
 
472
            $image_size_profile = $this->config['leaderslinked.image_sizes.group_image_upload'];
-
 
473
            
-
 
474
 
-
 
475
            
-
 
476
            $this->layout()->setTemplate('layout/layout-backend');
-
 
477
            $viewModel = new ViewModel();
-
 
478
            $viewModel->setTemplate('leaders-linked/high-performance-teams-my-groups/edit.phtml');
-
 
479
            $viewModel->setVariables([
-
 
480
                'total_members'         => $total_members,
-
 
481
                'accessibility'         => $accessibility ,
-
 
482
                'privacy'               => $privacy,
-
 
483
                'industry'              => $industry,
-
 
484
                'group_id'              => $group->id,
-
 
485
                'group_type'            => $group_type,
-
 
486
                'group_uuid'            => $group->uuid,
-
 
487
                'name'                  => trim($group->name),
-
 
488
                'image'                 => $group->image,
-
 
489
                'cover'                 => $group->cover,
-
 
490
                'overview'              => $group->description,
-
 
491
                'website'               => $group->website,
-
 
492
                
-
 
493
                'formAccessibility'     => $formAccessibility,
-
 
494
                'formPrivacy'           => $formPrivacy,
-
 
495
                'formType'              => $formType,
-
 
496
                'formIndustry'          => $formIndustry,
-
 
497
                'formExtended'          => $formExtended,
-
 
498
                'formWebsite'           => $formWebsite,
-
 
499
                'formImage'             => $formImage,
-
 
500
                'formCover'             => $formCover,
-
 
501
                'image_size_cover'      => $image_size_cover,
-
 
502
                'image_size_profile'    => $image_size_profile,
-
 
503
                
-
 
504
                
-
 
505
                'industries'            => $industries,
-
 
506
                'types'                 => $types,
-
 
507
                'privacies'             => $privacies,
-
 
508
                'accessibilities'       => $accessibilities
-
 
509
            ]);
-
 
510
            return $viewModel ;
-
 
511
            
279
       
512
        } else {
280
        if (!$objectives) {
513
            $data = [
281
            $data = [
514
                'success' => false,
-
 
515
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
516
            ];
-
 
517
            
-
 
518
            return new JsonModel($data);
-
 
519
        }
-
 
520
        
-
 
521
        return new JsonModel($data);
-
 
522
    }
-
 
523
    
-
 
524
    
-
 
525
    /**
-
 
526
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
-
 
527
     * @return \Laminas\View\Model\JsonModel
-
 
528
     */
282
                'success' => false,
529
    public function extendedAction()
-
 
530
    {
-
 
531
        
-
 
532
        $user_group_id = $this->params()->fromRoute('id');
-
 
533
        $groupMapper =GroupMapper::getInstance($this->adapter);
-
 
534
        
-
 
535
        $group = $groupMapper->fetchOneByUuid($user_group_id);
283
                'data' => 'ERROR_RECORD_NOT_FOUND'
536
        if(!$group) {
-
 
537
            $response = [
-
 
538
                'success' => false,
-
 
539
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
540
            ];
-
 
541
            
-
 
542
            return new JsonModel($response);
284
            ];
543
            
285
 
544
        }
286
            return new JsonModel($data);
545
        
-
 
546
        $currentUser = $this->plugin('currentUserPlugin');
-
 
547
        if($currentUser->getUserId() != $group->user_id) {
287
        }
548
            $response = [
-
 
549
                'success' => false,
-
 
550
                'data' => 'ERROR_UNAUTHORIZED'
288
       
551
            ];
-
 
552
            
289
        if ($objectives->company_id != $currentCompany->id) {
553
            return new JsonModel($response);
-
 
554
        }
-
 
555
        
-
 
556
        
-
 
557
        
-
 
558
        $request = $this->getRequest();
-
 
559
        if($request->isGet()) {
-
 
560
            $data = [
-
 
561
                'success' => true,
-
 
562
                'data' => $group->description,
-
 
563
            ];
-
 
564
            
290
            return new JsonModel([
565
            return new JsonModel($data);
291
                'success' => false,
566
            
-
 
-
 
292
                'data' => 'ERROR_UNAUTHORIZED'
567
            
293
            ]);
Línea 568... Línea 294...
568
        } else if($request->isPost()) {
294
        } 
569
            
295
 
Línea 570... Línea 296...
570
            
296
        if($request->isPost()) {
571
            $form = new ExtendedForm();
297
            $form = new  HighPerformanceTeamsGroupsForm();
572
            $dataPost = $request->getPost()->toArray();
-
 
573
            
298
            $dataPost = $request->getPost()->toArray();
Línea -... Línea 299...
-
 
299
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : HighPerformanceTeamsGroups::STATUS_INACTIVE;
574
            $form->setData($dataPost);
300
            $form->setData($dataPost);
-
 
301
            
-
 
302
            if($form->isValid()) {
-
 
303
                $dataPost = (array) $form->getData();
-
 
304
                
-
 
305
                $hydrator = new ObjectPropertyHydrator();
-
 
306
                $hydrator->hydrate($dataPost, $objectives);
-
 
307
                $result = $highPerformanceTeamsGroupsMapper->update($objectives);
-
 
308
                
-
 
309
                if($result) {
-
 
310
                    $this->logger->info('Se actualizo el objetivo ' . $objectives->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
311
                    
Línea 575... Línea 312...
575
            
312
                    $data = [
576
            if($form->isValid()) {
-
 
577
                $dataPost = (array) $form->getData();
-
 
578
                
-
 
Línea 579... Línea 313...
579
                $hydrator = new ObjectPropertyHydrator();
313
                        'success' => true,
580
                $hydrator->hydrate($dataPost, $group);
314
                        'data' => 'LABEL_RECORD_UPDATED'
581
                
315
                    ];
582
                $groupMapper->updateExtended($group);
316
                } else {
Línea 599... Línea 333...
599
                return new JsonModel([
333
                return new JsonModel([
600
                    'success'   => false,
334
                    'success'   => false,
601
                    'data'   => $messages
335
                    'data'   => $messages
602
                ]);
336
                ]);
603
            }
337
            }
604
        }
-
 
605
        
-
 
606
        
-
 
607
        $data = [
-
 
608
            'success' => false,
-
 
609
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
610
        ];
-
 
611
        
-
 
612
        
-
 
613
        return new JsonModel($data);
-
 
614
    }
-
 
615
    
-
 
616
    
-
 
617
 
-
 
618
    public function imageAction()
-
 
619
    {
-
 
620
        $user_group_id    = $this->params()->fromRoute('id');
-
 
621
        $operation          = $this->params()->fromRoute('operation');
-
 
622
        
-
 
623
        $groupMapper =GroupMapper::getInstance($this->adapter);
-
 
624
        
-
 
625
        $group = $groupMapper->fetchOneByUuid($user_group_id);
-
 
626
        if(!$group) {
-
 
627
            $response = [
338
        }else if ($request->isGet()) {
628
                'success' => false,
-
 
629
                'data' => 'ERROR_INVALID_PARAMETER'
339
            $hydrator = new ObjectPropertyHydrator();
630
            ];
-
 
Línea -... Línea 340...
-
 
340
            
631
            
341
            $data = [
-
 
342
                'success' => true,
-
 
343
                'data' => $hydrator->extract($objectives)
Línea 632... Línea -...
632
            return new JsonModel($response);
-
 
633
            
-
 
634
        }
-
 
635
        
344
            ];
636
        $currentUser = $this->plugin('currentUserPlugin');
-
 
637
        $currentUser = $currentUser->getUser();
345
            
638
        
346
            return new JsonModel($data);
639
        if($currentUser->id != $group->user_id) {
347
        } else {
640
            $response = [
348
            $data = [
641
                'success' => false,
349
                'success' => false,
Línea 642... Línea 350...
642
                'data' => 'ERROR_UNAUTHORIZED'
350
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
643
            ];
351
            ];
Línea 644... Línea -...
644
            
-
 
645
            return new JsonModel($response);
-
 
646
        }
-
 
647
        
-
 
648
        
-
 
649
        
-
 
650
        $request = $this->getRequest();
-
 
651
        if($request->isPost()) {
-
 
652
            $target_path = $this->config['leaderslinked.fullpath.group'] . DIRECTORY_SEPARATOR . $group->uuid;
-
 
653
 
-
 
654
            
-
 
655
            if($operation == 'delete') {
-
 
656
                $this->logger->info('Se borro el image del grupo : ' .  $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
-
 
657
                if($group->image) {
-
 
658
                    if(!Image::delete($target_path, $group->image)) {
-
 
659
                        return new JsonModel([
-
 
660
                            'success'   => false,
-
 
661
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
662
                        ]);
-
 
663
                    }
-
 
664
                }
-
 
665
                
352
            
666
                
-
 
667
                $group->image = '';
-
 
668
                if(!$groupMapper->updateImage($group)) {
-
 
669
                    return new JsonModel([
-
 
670
                        'success'   => false,
-
 
671
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
672
                    ]);
-
 
673
                }
-
 
674
                
-
 
675
            } else {
-
 
Línea 676... Línea -...
676
                $form = new ImageForm($this->config);
-
 
677
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
-
 
678
                
-
 
679
                $form->setData($data);
-
 
680
                
-
 
681
                if($form->isValid()) {
-
 
682
                    
-
 
683
                    $files = $request->getFiles()->toArray();
-
 
684
                    if(!empty($files['image']['error'])) {
-
 
685
                        
-
 
686
                        return new JsonModel([
-
 
687
                            'success'   => false,
353
            return new JsonModel($data);
688
                            'data'   =>  'ERROR_UPLOAD_FILE'
-
 
689
                        ]);
-
 
690
                        
-
 
691
                        
-
 
692
                    }
-
 
693
                    
-
 
694
                    if($group->image) {
-
 
695
                        if(!Image::delete($target_path, $group->image)) {
-
 
696
                            return new JsonModel([
-
 
Línea 697... Línea -...
697
                                'success'   => false,
-
 
698
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
699
                            ]);
-
 
700
                        }
-
 
701
                    }
-
 
702
 
-
 
703
                    
-
 
704
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.group_image_size']);
-
 
705
                    $source             = $files['image']['tmp_name'];
-
 
706
                    $target_filename    = 'group-image-' . uniqid() . '.png';
-
 
707
                    $crop_to_dimensions = true;
-
 
708
                    
-
 
709
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
-
 
710
                        return new JsonModel([
-
 
711
                            'success'   => false,
-
 
712
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
713
                        ]);
-
 
714
                    }
-
 
715
                    
-
 
716
                    $group->image = $target_filename;
-
 
Línea 717... Línea -...
717
                    if(!$groupMapper->updateImage($group)) {
-
 
718
                        return new JsonModel([
-
 
719
                            'success'   => false,
-
 
720
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
721
                        ]);
-
 
722
                    }
-
 
723
 
-
 
724
                    $this->logger->info('Se actualizo el image del grupo : ' . $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
-
 
725
                    
-
 
726
                } else {
-
 
727
                    $messages = [];
-
 
728
                    $form_messages = (array) $form->getMessages();
-
 
729
                    foreach($form_messages  as $fieldname => $field_messages)
-
 
730
                    {
-
 
731
                        $messages[$fieldname] = array_values($field_messages);
-
 
732
                    }
-
 
733
                    
-
 
734
                    return new JsonModel([
-
 
735
                        'success'   => false,
-
 
736
                        'data'   => $messages
-
 
737
                    ]);
-
 
738
                }
-
 
739
            }
-
 
740
            return new JsonModel([
-
 
741
                'success'   => true,
-
 
742
                'data' => $this->url()->fromRoute('storage', ['type' => 'group', 'code' => $group->uuid, 'filename' => $group->image])
-
 
743
                
-
 
744
            ]);
-
 
745
        }
-
 
746
        
-
 
747
        
-
 
748
        $data = [
-
 
749
            'success' => false,
-
 
Línea 750... Línea -...
750
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
751
        ];
-
 
752
        
-
 
753
        
-
 
754
        return new JsonModel($data);
-
 
755
    }
-
 
756
    
-
 
757
 
-
 
758
    public function coverAction()
-
 
759
    {
-
 
760
        $user_group_id  = $this->params()->fromRoute('id');
-
 
761
        $operation      = $this->params()->fromRoute('operation');
-
 
762
        
-
 
763
        $groupMapper = GroupMapper::getInstance($this->adapter);
-
 
764
        
-
 
765
        $group = $groupMapper->fetchOneByUuid($user_group_id);
-
 
766
        if(!$group) {
-
 
767
            $response = [
-
 
768
                'success' => false,
-
 
769
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
770
            ];
-
 
771
            
-
 
772
            return new JsonModel($response);
-
 
773
            
-
 
774
        }
-
 
775
        
-
 
776
        $currentUser = $this->plugin('currentUserPlugin');
-
 
777
        if($currentUser->getUserId() != $group->user_id) {
-
 
778
            $response = [
-
 
779
                'success' => false,
-
 
780
                'data' => 'ERROR_UNAUTHORIZED'
-
 
781
            ];
-
 
782
            
-
 
783
            return new JsonModel($response);
-
 
784
        }
-
 
785
        
-
 
786
        
-
 
787
        
-
 
788
        $request = $this->getRequest();
-
 
789
        if($request->isPost()) {
-
 
790
            $target_path = $this->config['leaderslinked.fullpath.group'] . DIRECTORY_SEPARATOR . $group->uuid;
-
 
791
            
-
 
792
            
-
 
793
            if($operation == 'delete') {
-
 
794
                if($group->cover) {
-
 
795
                    if(!Image::delete($target_path, $group->cover)) {
-
 
796
                        return new JsonModel([
-
 
797
                            'success'   => false,
-
 
798
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
799
                        ]);
-
 
800
                    }
-
 
801
                }
-
 
802
                
-
 
803
                $this->logger->info('Se borro el cover del grupo : ' . $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
-
 
804
                
-
 
805
                $group->cover = '';
-
 
806
                if(!$groupMapper->updateCover($group)) {
-
 
807
                    return new JsonModel([
-
 
808
                        'success'   => false,
-
 
809
                        'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
810
                    ]);
-
 
811
                }
-
 
812
                
-
 
813
            } else {
-
 
814
                $form = new CoverForm($this->config);
-
 
815
                $data 	= array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
-
 
816
                
-
 
817
                $form->setData($data);
-
 
818
                
-
 
819
                if($form->isValid()) {
-
 
820
                    
-
 
821
                    $files = $request->getFiles()->toArray();
-
 
822
                    if(!empty($files['cover']['error'])) {
-
 
823
                        
-
 
824
                        return new JsonModel([
-
 
825
                            'success'   => false,
-
 
826
                            'data'   =>  'ERROR_UPLOAD_FILE'
-
 
827
                        ]);
-
 
828
                        
-
 
829
                        
-
 
830
                    }
-
 
831
                    
-
 
Línea 832... Línea -...
832
                    if($group->cover) {
-
 
833
                        if(!Image::delete($target_path, $group->cover)) {
-
 
834
                            return new JsonModel([
-
 
835
                                'success'   => false,
-
 
836
                                'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
837
                            ]);
-
 
838
                        }
354
        }
839
                    }
-
 
840
 
355
        
841
                    list( $target_width, $target_height ) = explode('x', $this->config['leaderslinked.image_sizes.group_cover_size']);
-
 
842
                    $source             = $files['cover']['tmp_name'];
-
 
843
                    $target_filename    = 'group-cover-' . uniqid() . '.png';
-
 
844
                    $crop_to_dimensions = false;
-
 
845
                    
-
 
846
                    if(!Image::uploadImage($source, $target_path, $target_filename, $target_width, $target_height, $crop_to_dimensions)) {
356
        return new JsonModel($data);
847
                        return new JsonModel([
-
 
848
                            'success'   => false,
357
                
849
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
850
                        ]);
-
 
851
                    }
-
 
852
                    
-
 
853
                    
-
 
854
                    
-
 
855
                    $group->cover = $target_filename;
358
    }
856
                    if(!$groupMapper->updateCover($group)) {
-
 
857
                        return new JsonModel([
359
 
858
                            'success'   => false,
-
 
859
                            'data'   =>  'ERROR_THERE_WAS_AN_ERROR'
-
 
860
                        ]);
-
 
861
                    }
-
 
862
                    
-
 
863
                    $this->logger->info('Se actualizo el cover del grupo :  ' . $group->name, ['user_id' => $group->user_id, 'ip' => Functions::getUserIP()]);
-
 
864
                    
-
 
865
                } else {
-
 
866
                    $messages = [];
360
 
867
                    $form_messages = (array) $form->getMessages();
-
 
868
                    foreach($form_messages  as $fieldname => $field_messages)
-
 
869
                    {
-
 
870
                        $messages[$fieldname] = array_values($field_messages);
-
 
871
                    }
-
 
872
                    
-
 
873
                    return new JsonModel([
-
 
874
                        'success'   => false,
-
 
875
                        'data'   => $messages
-
 
876
                    ]);
-
 
877
                }
-
 
878
            }
-
 
879
            return new JsonModel([
-
 
880
                'success'   => true,
-
 
881
                'data' => $this->url()->fromRoute('storage', ['type' => 'group-cover', 'code' => $group->uuid, 'filename' => $group->cover])
-
 
882
                
-
 
Línea 883... Línea -...
883
            ]);
-
 
884
        }
-
 
885
        
361
 
886
        
-
 
887
        $data = [
-
 
888
            'success' => false,
-
 
889
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
362
 
890
        ];
363
    public function deleteAction(){
891
        
364
        $currentUserPlugin = $this->plugin('currentUserPlugin');
892
        
365
        $currentCompany = $currentUserPlugin->getCompany();
893
        return new JsonModel($data);
366
        $currentUser = $currentUserPlugin->getUser();
894
    }
367
 
895
    
368
        $request = $this->getRequest();
896
    public function industryAction()
369
        $uuid = $this->params()->fromRoute('id');
-
 
370
        
897
    {
371
 
-
 
372
        if (!$uuid) {
898
        $id = $this->params()->fromRoute('id');
373
            $data = [
899
        if(!$id) {
374
                'success' => false,
-
 
375
                'data' => 'ERROR_INVALID_PARAMETER'
900
            $response = [
376
            ];
901
                'success' => false,
377
 
902
                'data' => 'ERROR_INVALID_PARAMETER'
378
            return new JsonModel($data);
903
            ];
379
        }
904
            
380
 
905
            return new JsonModel($response);
381
       
906
        }
382
 
907
        
383
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
908
        $groupMapper = GroupMapper::getInstance($this->adapter);
384
        $objectives = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($uuid);
909
        $group = $groupMapper->fetchOneByUuid($id);
-
 
910
        if(!$group) {
-
 
911
            $response = [
385
       
912
                'success' => false,
386
        if (!$objectives) {
913
                'data' => 'ERROR_RECORD_NOT_FOUND'
387
            $data = [
914
            ];
388
                'success' => false,
915
            
389
                'data' => 'ERROR_RECORD_NOT_FOUND'
916
            return new JsonModel($response);
-
 
917
        }
-
 
918
        
390
            ];
919
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
920
        $currentUser = $currentUserPlugin->getUser();
-
 
921
        if($currentUser->id != $group->user_id) {
391
 
922
            $response = [
-
 
923
                'success' => false,
392
            return new JsonModel($data);
924
                'data' => 'ERROR_UNAUTHORIZED'
-
 
925
            ];
-
 
926
            
-
 
927
            return new JsonModel($response);
-
 
928
        }
-
 
929
        
-
 
930
        
-
 
931
        
-
 
932
        $request = $this->getRequest();
-
 
933
        if($request->isGet()) {
-
 
934
            $industryMapper = IndustryMapper::getInstance($this->adapter);
-
 
935
            $industry = $industryMapper->fetchOne($group->industry_id);
-
 
936
            
-
 
937
            
-
 
938
            
-
 
939
            $data = [
-
 
940
                'success' => true,
-
 
941
                'data' => $industry->uuid,
-
 
942
            ];
-
 
943
            
-
 
944
            return new JsonModel($data);
-
 
945
            
-
 
946
            
-
 
Línea 947... Línea -...
947
        } else if($request->isPost()) {
-
 
948
            
-
 
949
            
-
 
950
            $form = new IndustryForm($this->adapter);
-
 
951
            $dataPost = $request->getPost()->toArray();
-
 
952
            
-
 
953
            $form->setData($dataPost);
-
 
954
            
-
 
Línea -... Línea 393...
-
 
393
        }
-
 
394
       
-
 
395
        if ($objectives->company_id != $currentCompany->id) {
955
            if($form->isValid()) {
396
            return new JsonModel([
956
                $dataPost = (array) $form->getData();
397
                'success' => false,
957
 
398
                'data' => 'ERROR_UNAUTHORIZED'
958
                $industryMapper = IndustryMapper::getInstance($this->adapter);
399
            ]);
959
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
-
 
960
                
400
        } 
961
                $group->industry_id = $industry->id;
-
 
962
                $groupMapper->updateIndustry($group);
401
    
-
 
402
        if ($request->isPost()) {
963
                
403
 
964
                $this->logger->info('Se actualizo la industria del grupo : ' . $group->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
404
 
965
                
-
 
966
 
-
 
967
                
405
            $result = $highPerformanceTeamsGroupsMapper->delete($objectives->id);
968
                return new JsonModel([
406
            if ($result) {
969
                    'success'   => true,
407
                $this->logger->info('Se borro el objetivo con el titulo ' . $objectives->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
970
                    'data' =>  $industry->name,
408
 
971
                    
-
 
972
                ]);
-
 
973
                
-
 
974
            } else {
409
                $data = [
975
                $messages = [];
-
 
976
                $form_messages = (array) $form->getMessages();
-
 
977
                foreach($form_messages  as $fieldname => $field_messages)
-
 
978
                {
-
 
979
                    $messages[$fieldname] = array_values($field_messages);
-
 
980
                }
-
 
981
                
-
 
982
                return new JsonModel([
-
 
983
                    'success'   => false,
-
 
984
                    'data'   => $messages
-
 
985
                ]);
-
 
986
            }
-
 
987
        }
-
 
988
        
-
 
989
        
-
 
990
        $data = [
-
 
991
            'success' => false,
-
 
992
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
993
        ];
-
 
994
        
-
 
995
        
-
 
996
        return new JsonModel($data);
-
 
997
    }
-
 
998
    
-
 
999
    public function websiteAction()
-
 
1000
    {
-
 
1001
        $id = $this->params()->fromRoute('id');
-
 
1002
        if(!$id) {
-
 
1003
            $response = [
-
 
1004
                'success' => false,
-
 
1005
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
1006
            ];
-
 
1007
            
-
 
1008
            return new JsonModel($response);
-
 
1009
        }
-
 
1010
        
-
 
1011
        $groupMapper = GroupMapper::getInstance($this->adapter);
-
 
1012
        $group = $groupMapper->fetchOneByUuid($id);
-
 
1013
        if(!$group) {
-
 
1014
            $response = [
-
 
1015
                'success' => false,
-
 
1016
                'data' => 'ERROR_RECORD_NOT_FOUND'
410
                    'success' => true,
1017
            ];
-
 
1018
            
-
 
1019
            return new JsonModel($response);
-
 
1020
        }
-
 
1021
        
-
 
1022
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1023
        $currentUser = $currentUserPlugin->getUser();
-
 
1024
        if($currentUser->id != $group->user_id) {
411
                    'data' => 'LABEL_RECORD_DELETED'
1025
            $response = [
412
                ];
1026
                'success' => false,
413
            } else {
1027
                'data' => 'ERROR_UNAUTHORIZED'
414
 
1028
            ];
415
                $data = [
1029
            
416
                    'success' => false,
1030
            return new JsonModel($response);
-
 
1031
        }
-
 
1032
        
-
 
1033
        
-
 
1034
        $request = $this->getRequest();
-
 
1035
        if($request->isGet()) {
-
 
1036
            $data = [
-
 
1037
                'success' => true,
-
 
1038
                'data' => $group->website,
-
 
1039
            ];
-
 
1040
            
-
 
1041
            return new JsonModel($data);
-
 
1042
            
-
 
1043
            
-
 
1044
        } else if($request->isPost()) {
-
 
1045
            
-
 
1046
            
-
 
1047
            $form = new WebsiteForm();
-
 
1048
            $dataPost = $request->getPost()->toArray();
-
 
1049
            
-
 
1050
            $form->setData($dataPost);
-
 
1051
            
-
 
1052
            if($form->isValid()) {
-
 
1053
                $dataPost = (array) $form->getData();
-
 
1054
                
-
 
1055
                $hydrator = new ObjectPropertyHydrator();
-
 
1056
                $hydrator->hydrate($dataPost, $group);
-
 
1057
                
-
 
1058
                $groupMapper->updateWebsite($group);
-
 
1059
                
-
 
1060
                $this->logger->info('Se actualizo el website de la empresa ' . $group->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
1061
                
-
 
1062
                return new JsonModel([
-
 
1063
                    'success'   => true,
-
 
1064
                    'data' => $group->website,
-
 
1065
                ]);
-
 
1066
                
-
 
1067
            } else {
-
 
1068
                $messages = [];
417
                    'data' => $highPerformanceTeamsGroupsMapper->getError()
1069
                $form_messages = (array) $form->getMessages();
-
 
1070
                foreach($form_messages  as $fieldname => $field_messages)
418
                ];
1071
                {
-
 
1072
                    $messages[$fieldname] = array_values($field_messages);
-
 
1073
                }
-
 
1074
                
-
 
1075
                return new JsonModel([
-
 
1076
                    'success'   => false,
-
 
1077
                    'data'   => $messages
419
 
1078
                ]);
420
                return new JsonModel($data);
Línea 1079... Línea -...
1079
            }
-
 
1080
        }
-
 
1081
        
-
 
1082
        
-
 
1083
        $data = [
-
 
1084
            'success' => false,
-
 
1085
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
1086
        ];
-
 
1087
        
-
 
1088
        
-
 
1089
        return new JsonModel($data);
-
 
1090
    }
421
            }
1091
    
-
 
1092
    public function accessibilityAction()
-
 
1093
    {
-
 
1094
        $id = $this->params()->fromRoute('id');
-
 
1095
        if(!$id) {
-
 
1096
            $response = [
-
 
1097
                'success' => false,
-
 
1098
                'data' => 'ERROR_INVALID_PARAMETER'
422
        } else {
1099
            ];
423
            $data = [
1100
            
-
 
1101
            return new JsonModel($response);
-
 
1102
        }
424
                'success' => false,
1103
        
425
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1104
        $groupMapper = GroupMapper::getInstance($this->adapter);
-
 
1105
        $group = $groupMapper->fetchOneByUuid($id);
-
 
1106
        if(!$group) {
-
 
1107
            $response = [
-
 
1108
                'success' => false,
-
 
1109
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
1110
            ];
426
            ];
1111
            
-
 
1112
            return new JsonModel($response);
427
 
1113
        }
-
 
1114
        
428
            return new JsonModel($data);
1115
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1116
        $currentUser = $currentUserPlugin->getUser();
-
 
1117
        if($currentUser->id != $group->user_id) {
-
 
1118
            $response = [
-
 
1119
                'success' => false,
-
 
1120
                'data' => 'ERROR_UNAUTHORIZED'
-
 
1121
            ];
-
 
1122
            
-
 
1123
            return new JsonModel($response);
-
 
1124
        }
-
 
1125
        
-
 
1126
        
-
 
1127
        $request = $this->getRequest();
-
 
1128
        if($request->isGet()) {
-
 
1129
            $data = [
-
 
1130
                'success' => true,
-
 
1131
                'data' => $group->accessibility,
-
 
1132
            ];
-
 
1133
            
429
        }
Línea 1134... Línea -...
1134
            return new JsonModel($data);
-
 
1135
            
-
 
1136
            
-
 
1137
        } else if($request->isPost()) {
-
 
1138
            
-
 
1139
            
-
 
1140
            $form = new AccessibilityForm();
-
 
1141
            $dataPost = $request->getPost()->toArray();
-
 
1142
            
-
 
1143
            $form->setData($dataPost);
-
 
1144
            
-
 
1145
            if($form->isValid()) {
-
 
1146
                $dataPost = (array) $form->getData();
-
 
1147
 
-
 
1148
                $hydrator = new ObjectPropertyHydrator();
-
 
1149
                $hydrator->hydrate($dataPost, $group);
-
 
1150
                
-
 
1151
                $groupMapper->updateAccessibility($group);
-
 
1152
                
-
 
1153
                 $values = [
-
 
1154
                    Group::ACCESSIBILITY_AUTO_JOIN => 'LABEL_AUTO_JOIN',
-
 
1155
                    Group::ACCESSIBILITY_REQUEST_TO_JOIN => 'LABEL_REQUEST_TO_JOIN',
-
 
1156
                    Group::ACCESSIBILITY_ADMIN_WILL_ADD => 'LABEL_ADMIN_WILL_ADD',
-
 
1157
                ];
-
 
1158
                
-
 
1159
                $this->logger->info('Se actualizo el accesibilidad de la empresa ' . $group->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
1160
                
-
 
1161
                return new JsonModel([
-
 
1162
                    'success'   => true,
-
 
1163
                    'data' => $values[$group->accessibility]
-
 
1164
                 ]);
-
 
1165
                
-
 
1166
            } else {
-
 
1167
                $messages = [];
-
 
1168
                $form_messages = (array) $form->getMessages();
-
 
1169
                foreach($form_messages  as $fieldname => $field_messages)
-
 
1170
                {
-
 
1171
                    $messages[$fieldname] = array_values($field_messages);
-
 
1172
                }
-
 
1173
                
-
 
1174
                return new JsonModel([
-
 
1175
                    'success'   => false,
-
 
1176
                    'data'   => $messages
430
 
1177
                ]);
-
 
1178
            }
-
 
1179
        }
-
 
1180
        
431
        return new JsonModel($data);
1181
        
432
    }
1182
        $data = [
433
    
1183
            'success' => false,
434
    
1184
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
435
 
1185
        ];
436
    public function reportAction() {
1186
        
437
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1187
        
438
        $currentUser = $currentUserPlugin->getUser();
-
 
439
        $currentCompany = $currentUserPlugin->getCompany();
-
 
440
 
-
 
441
        $request = $this->getRequest();
Línea 1188... Línea -...
1188
        return new JsonModel($data);
-
 
1189
    }
-
 
1190
    
442
        $uuid = $this->params()->fromRoute('id');
1191
    public function privacyAction()
443
 
1192
    {
444
 
1193
        $id = $this->params()->fromRoute('id');
445
        if (!$uuid) {
1194
        if(!$id) {
446
            $data = [
1195
            $response = [
447
                'success' => false,
1196
                'success' => false,
448
                'data' => 'ERROR_INVALID_PARAMETER'
1197
                'data' => 'ERROR_INVALID_PARAMETER'
449
            ];
1198
            ];
450
 
1199
            
-
 
1200
            return new JsonModel($response);
-
 
1201
        }
451
            return new JsonModel($data);
1202
        
452
        }
1203
        $groupMapper = GroupMapper::getInstance($this->adapter);
453
 
1204
        $group = $groupMapper->fetchOneByUuid($id);
454
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
1205
        if(!$group) {
455
        $recordsObjectives = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($uuid);
1206
            $response = [
-
 
1207
                'success' => false,
-
 
1208
                'data' => 'ERROR_RECORD_NOT_FOUND'
456
        
1209
            ];
-
 
-
 
457
        if (!$recordsObjectives) {
-
 
458
            $data = [
Línea 1210... Línea -...
1210
            
-
 
1211
            return new JsonModel($response);
-
 
1212
        }
-
 
1213
        
-
 
1214
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
1215
        $currentUser = $currentUserPlugin->getUser();
-
 
1216
        if($currentUser->id != $group->user_id) {
-
 
1217
            $response = [
-
 
1218
                'success' => false,
-
 
1219
                'data' => 'ERROR_UNAUTHORIZED'
-
 
1220
            ];
-
 
1221
            
-
 
1222
            return new JsonModel($response);
-
 
1223
        }
-
 
1224
        
459
                'success' => false,
1225
        
-
 
1226
        $request = $this->getRequest();
-
 
1227
        if($request->isGet()) {
-
 
1228
            $data = [
-
 
1229
                'success' => true,
460
                'data' => 'Objetivo ERROR_RECORD_NOT_FOUND'
1230
                'data' => $group->privacy,
-
 
1231
            ];
461
            ];
1232
            
-
 
1233
            return new JsonModel($data);
-
 
1234
            
-
 
1235
            
-
 
1236
        } else if($request->isPost()) {
-
 
1237
            
-
 
1238
            
-
 
1239
            $form = new PrivacyForm();
-
 
1240
            $dataPost = $request->getPost()->toArray();
-
 
Línea 1241... Línea 462...
1241
            
462
 
Línea 1242... Línea -...
1242
            $form->setData($dataPost);
-
 
1243
            
-
 
1244
            if($form->isValid()) {
463
            return new JsonModel($data);
1245
                $dataPost = (array) $form->getData();
-
 
Línea -... Línea 464...
-
 
464
        }
1246
                
465
       
-
 
466
        if ($recordsObjectives->company_id != $currentCompany->id) {
1247
                $hydrator = new ObjectPropertyHydrator();
467
            return new JsonModel([
1248
                $hydrator->hydrate($dataPost, $group);
468
                'success' => false,
1249
                
469
                'data' => 'ERROR_UNAUTHORIZED'
-
 
470
            ]);
1250
                $groupMapper->updatePrivacy($group);
471
        } 
1251
                
472
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
1252
                $values = [
473
        $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($recordsObjectives->id);
Línea 1253... Línea -...
1253
                    Group::PRIVACY_IS_PRIVATE => 'LABEL_PRIVATE',
-
 
1254
                    Group::PRIVACY_IS_PUBLIC => 'LABEL_PUBLIC'
-
 
-
 
474
        
-
 
475
        $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
-
 
476
        $userMapper = UserMapper::getInstance($this->adapter);
1255
                ];
477
        $PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
1256
                
-
 
1257
 
478
 
1258
                $this->logger->info('Se actualizo la privacidad de la empresa ' . $group->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
1259
                
-
 
1260
                return new JsonModel([
-
 
1261
                    'success'   => true,
479
            foreach($recordsGoals as $record2){
1262
                    'data' => $values[$group->privacy]
-
 
1263
                ]);
-
 
1264
                
-
 
1265
            } else {
-
 
1266
                $messages = [];
-
 
1267
                $form_messages = (array) $form->getMessages();
-
 
1268
                foreach($form_messages  as $fieldname => $field_messages)
-
 
1269
                {
-
 
1270
                    $messages[$fieldname] = array_values($field_messages);
-
 
1271
                }
-
 
1272
                
-
 
1273
                return new JsonModel([
-
 
1274
                    'success'   => false,
-
 
1275
                    'data'   => $messages
-
 
1276
                ]);
480
                
1277
            }
481
                $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record2->id);
1278
        }
482
                
1279
        
-
 
1280
        
-
 
1281
        $data = [
483
    
1282
            'success' => false,
-
 
1283
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
1284
        ];
-
 
1285
        
484
                foreach($recordsTask as $record3){
1286
        
-
 
1287
        return new JsonModel($data);
-
 
1288
    }
485
                    $recordsTaskMembers =  $PlanningObjectivesAndGoalsTaskMemberMapper->fetchAll($record3->id);
1289
    
-
 
1290
    
486
                    $usersName=[];
1291
    
-
 
1292
    public function typeAction()
-
 
1293
    {
-
 
1294
        $id = $this->params()->fromRoute('id');
-
 
1295
        if(!$id) {
-
 
1296
            $response = [
-
 
1297
                'success' => false,
-
 
1298
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
1299
            ];
-
 
1300
            
-
 
1301
            return new JsonModel($response);
487
                    foreach($recordsTaskMembers as $record4){
-
 
488
                        $datosUser = $userMapper->fetchOne($record4->user_id);
Línea 1302... Línea -...
1302
        }
-
 
1303
        
-
 
1304
        $groupMapper = GroupMapper::getInstance($this->adapter);
489
                        $usersName[$record4->id]=$datosUser->first_name.' '.$datosUser->last_name;
Línea 1305... Línea -...
1305
        $group = $groupMapper->fetchOneByUuid($id);
-
 
1306
        if(!$group) {
490
                    }
1307
            $response = [
491
                    $record3->who=$usersName;
1308
                'success' => false,
-
 
1309
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
1310
            ];
492
                }
-
 
493
                
-
 
494
 
1311
            
495
               
1312
            return new JsonModel($response);
496
 
1313
        }
497
                $record2->task = $recordsTask;
1314
        
498
            }
1315
        $currentUserPlugin = $this->plugin('currentUserPlugin');
499
           $items=[
1316
        $currentUser = $currentUserPlugin->getUser();
500
            'objetives' => [
1317
        if($currentUser->id != $group->user_id) {
-
 
1318
            $response = [
-
 
1319
                'success' => false,
-
 
1320
                'data' => 'ERROR_UNAUTHORIZED'
-
 
1321
            ];
-
 
1322
            
-
 
1323
            return new JsonModel($response);
-
 
1324
        }
-
 
1325
        
-
 
1326
        
-
 
1327
        
-
 
1328
        $request = $this->getRequest();
-
 
1329
        if($request->isGet()) {
-
 
1330
            
-
 
1331
            $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
-
 
1332
            $groupType = $groupTypeMapper->fetchOne($group->type_id);
-
 
1333
            
-
 
1334
            $data = [
-
 
1335
                'success' => true,
-
 
1336
                'data' => $groupType->uuid,
-
 
1337
            ];
-
 
1338
            
-
 
1339
            return new JsonModel($data);
-
 
1340
            
-
 
1341
            
-
 
1342
        } else if($request->isPost()) {
-
 
1343
            
-
 
1344
            
-
 
1345
            $form = new GroupTypeForm($this->adapter);
-
 
1346
            $dataPost = $request->getPost()->toArray();
-
 
1347
            
-
 
1348
            $form->setData($dataPost);
-
 
1349
            
-
 
1350
            if($form->isValid()) {
-
 
1351
                $dataPost = (array) $form->getData();
-
 
1352
                
-
 
1353
                $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
-
 
1354
                $groupType = $groupTypeMapper->fetchOneByUuid($dataPost['type_id']);
-
 
1355
                
-
 
1356
                $group->type_id = $groupType->id;
-
 
1357
                $groupMapper->updateGroupType($group);
-
 
1358
                
-
 
1359
                $this->logger->info('Se actualizo el tipo del grupo : ' . $group->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
1360
                
501
                'title'=>$recordsObjectives->title,
1361
                $groupTypeMapper = GroupTypeMapper::getInstance($this->adapter);
-
 
1362
                $groupType = $groupTypeMapper->fetchOne($group->type_id);
502
                'description' =>$recordsObjectives->description,
1363
                
-
 
1364
                return new JsonModel([
-
 
1365
                    'success'   => true,
-
 
1366
                    'data' =>  $groupType->name,
-
 
1367
                    
-
 
1368
                ]);
-
 
1369
                
503
                'date'=>$recordsObjectives->date,
1370
            } else {
504
                'status'=>$recordsObjectives->status,
1371
                $messages = [];
-
 
1372
                $form_messages = (array) $form->getMessages();
-
 
1373
                foreach($form_messages  as $fieldname => $field_messages)
-
 
1374
                {
-
 
1375
                    $messages[$fieldname] = array_values($field_messages);
505
                'goals'=>$recordsGoals
1376
                }
-
 
1377
                
-
 
1378
                return new JsonModel([
506
            ]
1379
                    'success'   => false,
507
            ];