Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 1 Rev 15355
Línea 59... Línea 59...
59
        
59
        
Línea 60... Línea 60...
60
    }
60
    }
61
    
61
    
-
 
62
    public function indexAction()
-
 
63
    {
-
 
64
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
65
        $company = $currentUserPlugin->getCompany();
62
    public function indexAction()
66
        
Línea 63... Línea 67...
63
    {
67
        
64
        $request = $this->getRequest();
68
        $request = $this->getRequest();
Línea 84... Línea 88...
84
                    
88
                    
85
                }
89
                }
Línea 86... Línea 90...
86
            }
90
            }
-
 
91
            
-
 
92
            if($isJson) {
-
 
93
               
87
            
94
 
88
            if($isJson) {
95
                
Línea 89... Línea 96...
89
                $search = $this->params()->fromQuery('search', []);
96
                $search = $this->params()->fromQuery('search', []);
90
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
97
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
Línea 100... Línea 107...
100
                
107
                
101
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
108
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
102
                    $order_direction = 'ASC';
109
                    $order_direction = 'ASC';
Línea 103... Línea 110...
103
                }
110
                }
-
 
111
    
-
 
112
                $pushTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
-
 
113
                
-
 
114
                
-
 
115
                if($company) {
-
 
116
                    $paginator = $pushTemplateMapper->fetchAllDataTableByCompanyId($search, $company->id, $page, $records_x_page, $order_field, $order_direction);
104
    
117
                    
-
 
118
                } else {
Línea 105... Línea 119...
105
                $emailTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
119
                    $paginator = $pushTemplateMapper->fetchAllDataTableForDefault($search, $page, $records_x_page, $order_field, $order_direction);
106
                $paginator = $emailTemplateMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction);
120
                }
107
                
121
                
108
                $items = [];
122
                $items = [];
Línea 126... Línea 140...
126
                        
140
                        
Línea 127... Línea 141...
127
                    }
141
                    }
128
                    
142
                    
129
                    
143
                    
130
                    $item = [
144
                    $item = [
131
                        'id' => $record->id,
145
                        'id' => $record->code,
132
                        'title' => $record->title,
146
                        'title' => $record->title,
133
                        'status' => $record->status,
147
                        'status' => $record->status,
Línea 146... Línea 160...
146
                        'items' => $items,
160
                        'items' => $items,
147
                        'total' => $paginator->getTotalItemCount(),
161
                        'total' => $paginator->getTotalItemCount(),
148
                    ]
162
                    ]
149
                ]);
163
                ]);
150
            } else  {
164
            } else  {
-
 
165
 
151
                $form = new PushTemplateForm($this->adapter);
166
                $form = new PushTemplateForm($this->adapter);
Línea 152... Línea 167...
152
                
167
                
153
                $this->layout()->setTemplate('layout/layout-backend');
168
                $this->layout()->setTemplate('layout/layout-backend');
154
                $viewModel = new ViewModel();
169
                $viewModel = new ViewModel();
Línea 182... Línea 197...
182
            ];
197
            ];
Línea 183... Línea 198...
183
            
198
            
184
            return new JsonModel($data);
199
            return new JsonModel($data);
Línea 185... Línea 200...
185
        }
200
        }
186
 
201
 
187
        $emailTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
202
        $pushTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
188
        $emailTemplate = $emailTemplateMapper->fetchOne($id);
203
        $emailTemplate = $pushTemplateMapper->fetchOne($id);
189
        if(!$emailTemplate) {
204
        if(!$emailTemplate) {
190
            $data = [
205
            $data = [
191
                'success'   => false,
206
                'success'   => false,
Línea 205... Línea 220...
205
            if($form->isValid()) {
220
            if($form->isValid()) {
206
                $dataPost = (array) $form->getData();
221
                $dataPost = (array) $form->getData();
Línea 207... Línea 222...
207
                
222
                
208
                $hydrator = new ObjectPropertyHydrator();
223
                $hydrator = new ObjectPropertyHydrator();
209
                $hydrator->hydrate($dataPost, $emailTemplate);
224
                $hydrator->hydrate($dataPost, $emailTemplate);
Línea 210... Línea 225...
210
                $result = $emailTemplateMapper->update($emailTemplate);
225
                $result = $pushTemplateMapper->update($emailTemplate);
211
                
226
                
Línea 212... Línea 227...
212
                if($result) {
227
                if($result) {
Línea 217... Línea 232...
217
                        'data' => 'LABEL_RECORD_UPDATED'
232
                        'data' => 'LABEL_RECORD_UPDATED'
218
                    ];
233
                    ];
219
                } else {
234
                } else {
220
                    $data = [
235
                    $data = [
221
                        'success'   => false,
236
                        'success'   => false,
222
                        'data'      => $emailTemplateMapper->getError()
237
                        'data'      => $pushTemplateMapper->getError()
223
                    ];
238
                    ];
224
                }
239
                }
Línea 225... Línea 240...
225
                
240
                
Línea 250... Línea 265...
250
        } else {
265
        } else {
251
            $data = [
266
            $data = [
252
                'success' => false,
267
                'success' => false,
253
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
268
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
254
            ];
269
            ];
-
 
270
            
-
 
271
            return new JsonModel($data);
-
 
272
        }
-
 
273
        
-
 
274
        return new JsonModel($data);
-
 
275
    }
-
 
276
    
-
 
277
    public function importAction() {
-
 
278
        $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
279
        $currentUser = $currentUserPlugin->getUser();
-
 
280
        $currentCompany = $currentUserPlugin->getCompany();
-
 
281
        
-
 
282
        if (!$currentCompany) {
-
 
283
            $data = [
-
 
284
                'success' => false,
-
 
285
                'data' => 'ERROR_UNAUTHORIZED'
-
 
286
            ];
-
 
287
            
-
 
288
            return new JsonModel($data);
-
 
289
        }
-
 
290
        
-
 
291
        $request = $this->getRequest();
-
 
292
        
-
 
293
        if ($request->isPost()) {
-
 
294
            
-
 
295
            $pushTemplateMapper = PushTemplateMapper::getInstance($this->adapter);
-
 
296
            $pushTemplatesDefault = $pushTemplateMapper->fetchAllDefault();
-
 
297
            
-
 
298
            $new_records = 0;
-
 
299
            foreach ($pushTemplatesDefault as $pushTemplateDefault) {
-
 
300
                
-
 
301
                if ($pushTemplateDefault->status == PushTemplate::STATUS_INACTIVE) {
-
 
302
                    continue;
-
 
303
                }
-
 
304
                
-
 
305
                $pushTemplate = $pushTemplateMapper->fetchOneByCodeAndCompanyId($pushTemplateDefault->code, $currentCompany->id);
-
 
306
                if(!$pushTemplate) {
-
 
307
                    
-
 
308
                    $pushTemplate = new PushTemplate();
-
 
309
                    $pushTemplate->push_template_default_id = $pushTemplateDefault->id;
-
 
310
                    $pushTemplate->code  = $pushTemplateDefault->code;
-
 
311
                    $pushTemplate->title = $pushTemplateDefault->title;
-
 
312
                    $pushTemplate->body = $pushTemplateDefault->body;
-
 
313
                    $pushTemplate->status = $pushTemplateDefault->status;
-
 
314
                    $pushTemplate->type = $pushTemplateDefault->type;
-
 
315
                    $pushTemplate->network_id = $currentUser->network_id;
-
 
316
                    $pushTemplate->company_id = $currentCompany->id;
-
 
317
                    
-
 
318
                    if ($pushTemplateMapper->insert($pushTemplate)) {
-
 
319
                        $new_records++;
-
 
320
                    } else {
-
 
321
                        $data = [
-
 
322
                            'success' => false,
-
 
323
                            'data' => $pushTemplateMapper->getError()
-
 
324
                        ];
-
 
325
                        
-
 
326
                        return new JsonModel($data);
-
 
327
                    }
-
 
328
                    
-
 
329
                }
-
 
330
            }
-
 
331
            
-
 
332
            if ($new_records) {
-
 
333
                
-
 
334
                if (1 == $new_records) {
-
 
335
                    $data = [
-
 
336
                        'success' => true,
-
 
337
                        'data' => 'LABEL_1_PUSH_TEMPLATE_IMPORTED'
-
 
338
                    ];
-
 
339
                    
-
 
340
                    return new JsonModel($data);
-
 
341
                } else {
-
 
342
                    $data = [
-
 
343
                        'success' => true,
-
 
344
                        'data' => $new_records . ' LABEL_MULTI_PUSH_TEMPLATES_IMPORTED'
-
 
345
                    ];
-
 
346
                    
-
 
347
                    return new JsonModel($data);
-
 
348
                }
-
 
349
            } else {
-
 
350
                $data = [
-
 
351
                    'success' => true,
-
 
352
                    'data' => 'LABEL_NO_PUSH_TEMPLATE_IMPORTED'
-
 
353
                ];
-
 
354
                
-
 
355
                return new JsonModel($data);
-
 
356
            }
-
 
357
        } else {
-
 
358
            $data = [
-
 
359
                'success' => false,
-
 
360
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
361
            ];
Línea 255... Línea 362...
255
            
362
            
256
            return new JsonModel($data);
363
            return new JsonModel($data);
Línea 257... Línea 364...
257
        }
364
        }