Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 312 Rev 323
Línea 11... Línea 11...
11
 
11
 
12
use LeadersLinked\Library\Functions;
12
use LeadersLinked\Library\Functions;
13
use LeadersLinked\Model\HabitSkillRegister;
13
use LeadersLinked\Model\HabitSkillRegister;
14
use LeadersLinked\Mapper\HabitSkillRegisterMapper;
14
use LeadersLinked\Mapper\HabitSkillRegisterMapper;
-
 
15
use LeadersLinked\Form\Habit\HabitSkillRegisterForm;
Línea 15... Línea 16...
15
use LeadersLinked\Form\Habit\HabitSkillRegisterForm;
16
use LeadersLinked\Mapper\HabitSkillMapper;
16
 
17
 
17
 
18
 
Línea 78... Línea 79...
78
        $request = $this->getRequest();
79
        $request = $this->getRequest();
79
        if($request->isGet()) {
80
        if($request->isGet()) {
80
            $currentUserPlugin = $this->plugin('currentUserPlugin');
81
            $currentUserPlugin = $this->plugin('currentUserPlugin');
81
            $currentUser = $currentUserPlugin->getUser();
82
            $currentUser = $currentUserPlugin->getUser();
Línea -... Línea 83...
-
 
83
            
-
 
84
            $id = $this->params()->fromRoute('id');
-
 
85
            
-
 
86
            $habitSkillMapper = HabitSkillMapper::getInstance($this->adapter);
-
 
87
            $habitSkill = $habitSkillMapper->fetchOneByUuid($id);
-
 
88
            
-
 
89
            if(!$habitSkill) {
-
 
90
                return new JsonModel([
-
 
91
                    'success' => false,
-
 
92
                    'data' => 'ERROR_HABIT_NOT_FOUND'
-
 
93
                ]);;
-
 
94
                
-
 
95
                
-
 
96
            }
-
 
97
            
-
 
98
            if($currentUser->id != $habitSkill->user_id) {
-
 
99
                return new JsonModel([
-
 
100
                    'success' => false,
-
 
101
                    'data' => 'ERROR_HABIT_YOU_DO_NOT_HAVE_ACCESS_TO_THIS'
-
 
102
                ]);;
-
 
103
            }
-
 
104
            
82
            
105
            
83
            $acl = $this->getEvent()->getViewModel()->getVariable('acl');
106
            $acl = $this->getEvent()->getViewModel()->getVariable('acl');
84
            $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/add');
107
            $allowAdd = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/add');
85
            $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/edit');
108
            $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/edit');
Línea 86... Línea 109...
86
            $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/delete');
109
            $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/delete');
87
            
110
            
Línea 93... Línea 116...
93
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
116
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
94
                $order              =  $this->params()->fromQuery('order', []);
117
                $order              =  $this->params()->fromQuery('order', []);
95
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
118
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
96
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
119
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
Línea 97... Línea 120...
97
    
120
    
98
                $fields =  ['name'];
121
                $fields =  ['date'];
Línea 99... Línea 122...
99
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
122
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'date';
100
                
123
                
101
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
124
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
Línea 102... Línea 125...
102
                    $order_direction = 'ASC';
125
                    $order_direction = 'DESC';
103
                }
126
                }
Línea 104... Línea 127...
104
    
127
    
105
                $habitSkillRegisterMapper = HabitSkillRegisterMapper::getInstance($this->adapter);
128
                $habitSkillRegisterMapper = HabitSkillRegisterMapper::getInstance($this->adapter);
106
                $paginator = $habitSkillRegisterMapper->fetchAllDataTable($currentUser->id, $search,  $page, $records_x_page, $order_field, $order_direction);
129
                $paginator = $habitSkillRegisterMapper->fetchAllDataTable($currentUser->id, $habitSkill->id, $search,  $page, $records_x_page, $order_field, $order_direction);
107
                
130
                
108
                $items = [];
131
                $items = [];
109
                $records = $paginator->getCurrentItems();
132
                $records = $paginator->getCurrentItems();
110
                foreach($records as $record)
133
                foreach($records as $record)
111
                {
134
                {
112
                    $item = [
135
                    $item = [
113
                        'id' => $record->id,
136
                        'id' => $record->id,
114
                        'name' => $record->name,
137
                        'date' => $record->date,
115
                        'description' => $record->description,
138
                        'quantitative_value' => $record->quantitative_value,
116
                        'intelligence' => $record->intelligence,
139
                        'qualitative_description' => $record->qualitative_description,
117
                        'actions' => [
140
                        'actions' => [
-
 
141
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('habits/skills/registers/edit', ['id' => $habitSkill->uuid, 'register' => $record->uuid ], ['force_canonical' => true]) : '',
Línea 118... Línea 142...
118
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('habits/skills/edit', ['id' => $record->uuid ], ['force_canonical' => true]) : '',
142
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('habits/skills/registers/delete', ['id' => $habitSkill->uuid, 'register' =>$record->uuid ],  ['force_canonical' => true]) : '',
119
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('habits/skills/delete', ['id' =>$record->uuid ],  ['force_canonical' => true]) : '',
143
                        ] 
Línea 120... Línea 144...
120
                        ] 
144
                    ];
121
                    ];
145
   
122
                    
146
                    
123
                    array_push($items, $item);
147
                    array_push($items, $item);
124
                }
148
                }
125
                
149
                
126
                return new JsonModel([
150
                return new JsonModel([
127
                    'success' => true,
151
                    'success' => true,
Línea 128... Línea 152...
128
                    'data' => [
152
                    'data' => [
Línea 158... Línea 182...
158
                
182
                
159
                
183
                
Línea -... Línea 184...
-
 
184
                $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
185
                $currentUser = $currentUserPlugin->getUser();
-
 
186
                
-
 
187
                $id = $this->params()->fromRoute('id');
-
 
188
                
-
 
189
                $habitSkillMapper = HabitSkillMapper::getInstance($this->adapter);
-
 
190
                $habitSkill = $habitSkillMapper->fetchOneByUuid($id);
-
 
191
                
-
 
192
                if(!$habitSkill) {
-
 
193
                    return new JsonModel([
-
 
194
                        'success' => false,
-
 
195
                        'data' => 'ERROR_HABIT_NOT_FOUND'
-
 
196
                    ]);;
-
 
197
                    
-
 
198
                    
-
 
199
                }
-
 
200
                
-
 
201
                if($currentUser->id != $habitSkill->user_id) {
-
 
202
                    return new JsonModel([
-
 
203
                        'success' => false,
-
 
204
                        'data' => 'ERROR_HABIT_YOU_DO_NOT_HAVE_ACCESS_TO_THIS'
160
                $currentUserPlugin = $this->plugin('currentUserPlugin');
205
                    ]);;
Línea 161... Línea 206...
161
                $currentUser = $currentUserPlugin->getUser();
206
                }
162
                
207
                
163
                $dataPost = (array) $form->getData();
208
                $dataPost = (array) $form->getData();
Línea 164... Línea 209...
164
 
209
 
165
 
210
 
-
 
211
                $habitSkillRegister = new HabitSkillRegister();
Línea 166... Línea 212...
166
                $habitSkillRegister = new HabitSkillRegister();
212
                $hydrator = new \LeadersLinked\Hydrator\ObjectPropertyHydrator();
167
                $hydrator = new \LeadersLinked\Hydrator\ObjectPropertyHydrator();
213
                $hydrator->hydrate($dataPost, $habitSkillRegister);
Línea 168... Línea 214...
168
                $hydrator->hydrate($dataPost, $habitSkillRegister);
214
                
169
                
215
                $habitSkillRegister->network_id = $currentUser->network_id;
Línea 170... Línea 216...
170
                $habitSkillRegister->network_id = $currentUser->network_id;
216
                $habitSkillRegister->user_id    = $currentUser->id;
Línea 171... Línea 217...
171
                $habitSkillRegister->user_id    = $currentUser->id;
217
                $habitSkillRegister->skill_id   = $habitSkill->id;
172
                
218
                
173
                $habitSkillRegisterMapper = HabitSkillRegisterMapper::getInstance($this->adapter);
219
                $habitSkillRegisterMapper = HabitSkillRegisterMapper::getInstance($this->adapter);
Línea 174... Línea 220...
174
                $result = $habitSkillRegisterMapper->insert($habitSkillRegister );
220
                $result = $habitSkillRegisterMapper->insert($habitSkillRegister );
175
                
221
                
176
                if($result) {
222
                if($result) {
177
                    $this->logger->info('Se agrego el valor : ' . $habitSkillRegister->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
223
                    $this->logger->info('Se agrego el registro : ' . $habitSkill->name . ' - ' . $habitSkillRegister->date, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
178
                    
224
                    
179
    
225
    
-
 
226
                    $habitSkillRegister = $habitSkillRegisterMapper->fetchOne($habitSkillRegister->id);
180
                    $habitSkillRegister = $habitSkillRegisterMapper->fetchOne($habitSkillRegister->id);
227
                    
181
                    
-
 
182
                    $acl            = $this->getEvent()->getViewModel()->getVariable('acl');
228
                    $acl            = $this->getEvent()->getViewModel()->getVariable('acl');
183
                    $allowEdit      = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/edit');
229
                    $allowEdit      = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/edit');
184
                    $allowDelete    = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/delete');
230
                    $allowDelete    = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/delete');
185
                    
231
                    
-
 
232
                    $data = [
186
                    $data = [
233
                        'success'   => true,
187
                        'success'   => true,
234
                        'message'   => 'LABEL_RECORD_ADDED',
188
                        'message'   => 'LABEL_RECORD_ADDED',
235
                        'data'      => [
189
                        'data'      => [
236
                            'id' => $habitSkillRegister->uuid,
190
                            'id' => $habitSkillRegister->uuid,
237
                            'date' => $habitSkillRegister->date,
Línea 234... Línea 281...
234
    {
281
    {
235
        $currentUserPlugin = $this->plugin('currentUserPlugin');
282
        $currentUserPlugin = $this->plugin('currentUserPlugin');
236
        $currentUser = $currentUserPlugin->getUser();
283
        $currentUser = $currentUserPlugin->getUser();
Línea 237... Línea 284...
237
        
284
        
238
        
285
        
-
 
286
        $request    = $this->getRequest();
Línea -... Línea 287...
-
 
287
        $id         = $this->params()->fromRoute('id');
-
 
288
        $register   = $this->params()->fromRoute('register');
Línea 239... Línea 289...
239
        $request = $this->getRequest();
289
        
240
        $id = $this->params()->fromRoute('id');
290
        $habitSkillMapper = HabitSkillMapper::getInstance($this->adapter);
241
        
291
        $habitSkill = $habitSkillMapper->fetchOneByUuid($id);
242
        
292
        
243
        if(!$id) {
293
        if(!$habitSkill) {
-
 
294
            return new JsonModel([
Línea 244... Línea 295...
244
            return new JsonModel([
295
                'success' => false,
Línea -... Línea 296...
-
 
296
                'data' => 'ERROR_HABIT_NOT_FOUND'
-
 
297
            ]);;
-
 
298
            
-
 
299
            
-
 
300
        }
-
 
301
        
-
 
302
        if($currentUser->id != $habitSkill->user_id) {
Línea 245... Línea 303...
245
                'success'   => false,
303
            return new JsonModel([
246
                'data'   => 'ERROR_INVALID_PARAMETER'
304
                'success' => false,
247
            ]);
305
                'data' => 'ERROR_HABIT_YOU_DO_NOT_HAVE_ACCESS_TO_THIS'
248
            
306
            ]);
249
        }
307
        }
250
        
308
        
251
        
309
        
Línea 252... Línea 310...
252
        
310
        
Línea 253... Línea 311...
253
        $habitSkillRegisterMapper = HabitSkillRegisterMapper::getInstance($this->adapter);
311
        $habitSkillRegisterMapper = HabitSkillRegisterMapper::getInstance($this->adapter);
254
        $habitSkillRegister = $habitSkillRegisterMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
312
        $habitSkillRegister = $habitSkillRegisterMapper->fetchOneByUuidAndNetworkId($register, $currentUser->network_id);
255
        if(!$habitSkillRegister) {
313
        if(!$habitSkillRegister) {
256
            return new JsonModel([
314
            return new JsonModel([
257
                'success'   => false,
315
                'success'   => false,
258
                'data'   => 'ERROR_RECORD_NOT_FOUND'
316
                'data'   => 'ERROR_RECORD_NOT_FOUND'
Línea 259... Línea 317...
259
            ]);
317
            ]);
Línea 260... Línea 318...
260
            
318
            
261
            
-
 
262
        }
-
 
263
        
-
 
264
        
-
 
265
        if($currentUser->id != $habitSkillRegister->user_id) {
-
 
266
            return new JsonModel([
319
            
267
                'success'   => false,
-
 
268
                'data'   => 'ERROR_UNAUTHORIZED'
-
 
269
            ]);
-
 
270
            
-
 
271
        }
-
 
272
        
-
 
273
        if($request->isGet()) {
-
 
274
            
-
 
275
            list($hour, $minute) = explode(':', $habitSkillRegister->monday_time);
320
        }
276
            $monday_time = $hour . ':' . $minute;
-
 
277
            
-
 
278
            
-
 
279
            list($hour, $minute) = explode(':', $habitSkillRegister->tuesday_time);
-
 
280
            $tuesday_time = $hour . ':' . $minute;
-
 
281
            
321
        
282
            list($hour, $minute) = explode(':', $habitSkillRegister->wednesday_time);
-
 
283
            $wednesday_time = $hour . ':' . $minute;
-
 
Línea 284... Línea 322...
284
            
322
 
285
            list($hour, $minute) = explode(':', $habitSkillRegister->thursday_time);
323
        if($currentUser->id != $habitSkillRegister->user_id) {
286
            $thursday_time = $hour . ':' . $minute;
324
            return new JsonModel([
287
            
-
 
288
            list($hour, $minute) = explode(':', $habitSkillRegister->friday_time);
-
 
289
            $friday_time = $hour . ':' . $minute;
325
                'success'   => false,
290
            
326
                'data'   => 'ERROR_UNAUTHORIZED'
291
            list($hour, $minute) = explode(':', $habitSkillRegister->saturday_time);
-
 
292
            $saturday_time = $hour . ':' . $minute;
-
 
293
            
-
 
294
            list($hour, $minute) = explode(':', $habitSkillRegister->sunday_time);
327
            ]);
295
            $sunday_time = $hour . ':' . $minute;
-
 
296
            
-
 
297
            
-
 
298
            return new JsonModel([
-
 
299
                'success'   => true,
-
 
300
                'data'   => [
-
 
301
                    'name'                      => $habitSkillRegister->name,
-
 
302
                    'description'               => $habitSkillRegister->description,
328
            
303
                    'monday_active' 			=> $habitSkillRegister->monday_active,
-
 
304
                    'tuesday_active' 			=> $habitSkillRegister->tuesday_active,
329
        }
305
                    'wednesday_active' 			=> $habitSkillRegister->wednesday_active,
-
 
306
                    'thursday_active' 			=> $habitSkillRegister->thursday_active,
330
        
307
                    'friday_active' 			=> $habitSkillRegister->friday_active,
331
        if($request->isGet()) {
308
                    'saturday_active' 			=> $habitSkillRegister->saturday_active,
332
            $acl            = $this->getEvent()->getViewModel()->getVariable('acl');
309
                    'sunday_active' 			=> $habitSkillRegister->sunday_active,
333
            $allowEdit      = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/edit');
310
                    'monday_time' 				=> $monday_time,
334
            $allowDelete    = $acl->isAllowed($currentUser->usertype_id, 'habits/skills/registers/delete');
311
                    'tuesday_time' 				=> $tuesday_time,
335
            
312
                    'wednesday_time' 			=> $wednesday_time,
336
            return new JsonModel([
Línea 313... Línea 337...
313
                    'thursday_time' 			=> $thursday_time,
337
                'success'   => true,
Línea -... Línea 338...
-
 
338
                'data'   => [
-
 
339
                    'date' => $habitSkillRegister->date,
314
                    'friday_time' 				=> $friday_time,
340
                    'quantitative_value' => $habitSkillRegister->quantitative_value,
Línea 315... Línea 341...
315
                    'saturday_time' 			=> $saturday_time,
341
                    'qualitative_description' => $habitSkillRegister->qualitative_description,
Línea 316... Línea 342...
316
                    'sunday_time' 				=> $sunday_time,
342
                    'actions' => [
317
                    'quantitative_value' 		=> $habitSkillRegister->quantitative_value,
343
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('habits/skills/registers/edit', ['id' => $habitSkill->uuid, 'register' => $habitSkillRegister->uuid ], ['force_canonical' => true]) : '',
Línea -... Línea 344...
-
 
344
                        'link_delete' => $allowDelete ? $this->url()->fromRoute('habits/skills/registers/delete', ['id' => $habitSkill->uuid, 'register' => $habitSkillRegister->uuid ],  ['force_canonical' => true]) : '',
-
 
345
                    ]
Línea 318... Línea 346...
318
                    'qualitative_description' 	=> $habitSkillRegister->qualitative_description,
346
                ]
Línea 319... Línea 347...
319
                    'notification_10min_before' => $habitSkillRegister->notification_10min_before,
347
            ]);
320
                    'notification_30min_before' => $habitSkillRegister->notification_30min_before,
348
        } else if($request->isPost()) {
Línea 321... Línea 349...
321
                    'intelligence' 				=> $habitSkillRegister->intelligence,
349
            $form = new  HabitSkillRegisterForm($this->adapter);
322
                ]
350
            $dataPost = $request->getPost()->toArray();
323
            ]);
351
 
Línea 324... Línea 352...
324
        } else if($request->isPost()) {
352
            $form->setData($dataPost);
325
            $form = new  HabitSkillRegisterForm($this->adapter);
353
            
326
            $dataPost = $request->getPost()->toArray();
354
         
327
 
355
            
328
            $form->setData($dataPost);
356
            if($form->isValid()) {
329
            
357
                
330
            if($form->isValid()) {
358
                $dataPost = (array) $form->getData();
331
                
-
 
332
                $dataPost = (array) $form->getData();
359
                
333
                
360
                $hydrator = new \LeadersLinked\Hydrator\ObjectPropertyHydrator();
334
                $hydrator = new \LeadersLinked\Hydrator\ObjectPropertyHydrator();
361
                $hydrator->hydrate($dataPost, $habitSkillRegister);
335
                $hydrator->hydrate($dataPost, $habitSkillRegister);
362
                
-
 
363
 
336
                
364
          
337
 
365
                
Línea 338... Línea 366...
338
                
366
                
339
                $result = $habitSkillRegisterMapper->update($habitSkillRegister);
367
                $result = $habitSkillRegisterMapper->update($habitSkillRegister);