Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 2219 Rev 2624
Línea 56... Línea 56...
56
            'success' => false,
56
            'success' => false,
57
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
57
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
58
        ]);
58
        ]);
59
    }
59
    }
Línea -... Línea 60...
-
 
60
 
-
 
61
}        $request = $this->getRequest();
-
 
62
        if($request->isPost()) {
-
 
63
            $form = new  PlanningObjectivesAndGoalsForm();
-
 
64
            $dataPost = $request->getPost()->toArray();
-
 
65
            
-
 
66
            $form->setData($dataPost);
-
 
67
            
-
 
68
            if($form->isValid()) {
-
 
69
                $dataPost = (array) $form->getData();
-
 
70
                $dataPost['status']='a';
-
 
71
                $dataPost['id_company']=$currentCompany;
-
 
72
 
-
 
73
                $hydrator = new ObjectPropertyHydrator();
-
 
74
                $planningObjectivesAndGoals = new PlanningObjectivesAndGoals();
-
 
75
                $hydrator->hydrate($dataPost, $planningObjectivesAndGoals);
-
 
76
                
-
 
77
                $PlanningObjectivesAndGoalsMapper = PlanningObjectivesAndGoalsMapper::getInstance($this->adapter);
-
 
78
                $result = $PlanningObjectivesAndGoalsMapper->insert($PlanningObjectivesAndGoals);
-
 
79
                
-
 
80
                if($result) {
-
 
81
                    $this->logger->info('Se agrego el objetivo ' . $PlanningObjectivesAndGoals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
82
                    
-
 
83
                    $data = [
-
 
84
                        'success'   => true,
-
 
85
                        'data'   => 'LABEL_RECORD_ADDED'
-
 
86
                    ];
-
 
87
                } else {
-
 
88
                    $data = [
-
 
89
                        'success'   => false,
-
 
90
                        'data'      => $PlanningObjectivesAndGoalsMapper->getError()
-
 
91
                    ];
-
 
92
                    
-
 
93
                }
-
 
94
                
-
 
95
                return new JsonModel($data);
-
 
96
                
-
 
97
            } else {
-
 
98
                $messages = [];
-
 
99
                $form_messages = (array) $form->getMessages();
-
 
100
                foreach($form_messages  as $fieldname => $field_messages)
-
 
101
                {
-
 
102
                    
-
 
103
                    $messages[$fieldname] = array_values($field_messages);
-
 
104
                }
-
 
105
                
-
 
106
                return new JsonModel([
-
 
107
                    'success'   => false,
-
 
108
                    'data'   => $messages
-
 
109
                ]);
-
 
110
            }
-
 
111
 
-
 
112
        } else {
-
 
113
            $data = [
-
 
114
                'success' => false,
-
 
115
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
116
            ];
-
 
117
            
-
 
118
            return new JsonModel($data);
-
 
119
        }
-
 
120
        
-
 
121
        return new JsonModel($data);
-
 
122
    
-
 
123
     
-
 
124
    }
-
 
125
 
-
 
126
 
-
 
127
 
-
 
128
     public function editAction(){
-
 
129
 
-
 
130
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
131
        $currentUser = $currentUserPlugin->getUser();
-
 
132
        $currentCompany = $currentUserPlugin->getCompany();
-
 
133
        
-
 
134
        
-
 
135
        $request = $this->getRequest();
-
 
136
        $uuid = $this->params()->fromRoute('id');
-
 
137
 
-
 
138
        
-
 
139
        if(!$uuid) {
-
 
140
            $data = [
-
 
141
                'success'   => false,
-
 
142
                'data'   => 'ERROR_INVALID_PARAMETER'
-
 
143
            ];
-
 
144
            
-
 
145
            return new JsonModel($data);
-
 
146
        }
-
 
147
 
-
 
148
        
-
 
149
 
-
 
150
        $PlanningObjectivesAndGoalsMapper = PlanningObjectivesAndGoalsMapper::getInstance($this->adapter);
-
 
151
        $objective = $PlanningObjectivesAndGoalsMapper->fetchOneByUuid($uuid);
-
 
152
       
-
 
153
        if (!$objective) {
-
 
154
            $data = [
-
 
155
                'success' => false,
-
 
156
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
157
            ];
-
 
158
 
-
 
159
            return new JsonModel($data);
-
 
160
        }
-
 
161
       
-
 
162
        if ($objective->id_company != $currentCompany->id) {
-
 
163
            return new JsonModel([
-
 
164
                'success' => false,
-
 
165
                'data' => 'ERROR_UNAUTHORIZED'
-
 
166
            ]);
-
 
167
        } 
-
 
168
 
-
 
169
        if($request->isPost()) {
-
 
170
            $form = new  PlanningObjectivesAndGoalsForm();
-
 
171
            $dataPost = $request->getPost()->toArray();
-
 
172
            
-
 
173
            $form->setData($dataPost);
-
 
174
            
-
 
175
            if($form->isValid()) {
-
 
176
                $dataPost = (array) $form->getData();
-
 
177
                
-
 
178
                $hydrator = new ObjectPropertyHydrator();
-
 
179
                $hydrator->hydrate($dataPost, $objective);
-
 
180
                $result = $PlanningObjectivesAndGoalsMapper->update($objectivesMapper);
-
 
181
                
-
 
182
                if($result) {
-
 
183
                    $this->logger->info('Se actualizo el objetivo ' . $objectivesMapper->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
184
                    
-
 
185
                    $data = [
-
 
186
                        'success' => true,
-
 
187
                        'data' => 'LABEL_RECORD_UPDATED'
-
 
188
                    ];
-
 
189
                } else {
-
 
190
                    $data = [
-
 
191
                        'success'   => false,
-
 
192
                        'data'      => $PlanningObjectivesAndGoalsMapper->getError()
-
 
193
                    ];
-
 
194
                }
-
 
195
                
-
 
196
                return new JsonModel($data);
-
 
197
                
-
 
198
            } else {
-
 
199
                $messages = [];
-
 
200
                $form_messages = (array) $form->getMessages();
-
 
201
                foreach($form_messages  as $fieldname => $field_messages)
-
 
202
                {
-
 
203
                    $messages[$fieldname] = array_values($field_messages);
-
 
204
                }
-
 
205
                
-
 
206
                return new JsonModel([
-
 
207
                    'success'   => false,
-
 
208
                    'data'   => $messages
-
 
209
                ]);
-
 
210
            }
-
 
211
        }else if ($request->isGet()) {
-
 
212
            $hydrator = new ObjectPropertyHydrator();
-
 
213
            
-
 
214
            $data = [
-
 
215
                'success' => true,
-
 
216
                'data' => $hydrator->extract($objectivesMapper)
-
 
217
            ];
-
 
218
            
-
 
219
            return new JsonModel($data);
-
 
220
        } else {
-
 
221
            $data = [
-
 
222
                'success' => false,
-
 
223
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
224
            ];
-
 
225
            
-
 
226
            return new JsonModel($data);
-
 
227
        }
-
 
228
        
-
 
229
        return new JsonModel($data);
-
 
230
                
-
 
231
    }
-
 
232
 
-
 
233
 
-
 
234
 
-
 
235
 
-
 
236
    public function deleteAction(){
-
 
237
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
238
        $currentCompany = $currentUserPlugin->getCompany()->id;
-
 
239
        $currentUser = $currentUserPlugin->getUser();
-
 
240
 
-
 
241
        $request = $this->getRequest();
-
 
242
        $uuid = $this->params()->fromRoute('id');
-
 
243
        
-
 
244
 
-
 
245
        if (!$uuid) {
-
 
246
            $data = [
-
 
247
                'success' => false,
-
 
248
                'data' => 'ERROR_INVALID_PARAMETER'
-
 
249
            ];
-
 
250
 
-
 
251
            return new JsonModel($data);
-
 
252
        }
-
 
253
 
-
 
254
       
-
 
255
 
-
 
256
        $PlanningObjectivesAndGoalsMapper = PlanningObjectivesAndGoalsMapper::getInstance($this->adapter);
-
 
257
        $objectivesMapper = $PlanningObjectivesAndGoalsMapper->fetchOneByUuid($uuid);
-
 
258
       
-
 
259
        if (!$objectivesMapper) {
-
 
260
            $data = [
-
 
261
                'success' => false,
-
 
262
                'data' => 'ERROR_RECORD_NOT_FOUND'
-
 
263
            ];
-
 
264
 
-
 
265
            return new JsonModel($data);
-
 
266
        }
-
 
267
       
-
 
268
        if ($objectivesMapper->id_company != $currentCompany) {
-
 
269
            return new JsonModel([
-
 
270
                'success' => false,
-
 
271
                'data' => 'ERROR_UNAUTHORIZED'
-
 
272
            ]);
-
 
273
        } 
-
 
274
    
-
 
275
        if ($request->isPost()) {
-
 
276
 
-
 
277
 
-
 
278
            $result = $PlanningObjectivesAndGoalsMapper->delete($objectivesMapper->id);
-
 
279
            if ($result) {
-
 
280
                $this->logger->info('Se borro el objetivo con el titulo ' . $objectivesMapper->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
-
 
281
 
-
 
282
                $data = [
-
 
283
                    'success' => true,
-
 
284
                    'data' => 'LABEL_RECORD_DELETED'
-
 
285
                ];
-
 
286
            } else {
-
 
287
 
-
 
288
                $data = [
-
 
289
                    'success' => false,
-
 
290
                    'data' => $PlanningObjectivesAndGoalsMapper->getError()
-
 
291
                ];
-
 
292
 
-
 
293
                return new JsonModel($data);
-
 
294
            }
-
 
295
        } else {
-
 
296
            $data = [
-
 
297
                'success' => false,
-
 
298
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
299
            ];
-
 
300
 
-
 
301
            return new JsonModel($data);
-
 
302
        }
-
 
303
 
-
 
304
        return new JsonModel($data);
-
 
305
    }
-
 
306
    
-
 
307
    
60
 
308
   
61
}
309
}