Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17047 Rev 17048
Línea 1... Línea 1...
1
<?php
1
<?php
2
 
-
 
3
declare(strict_types=1);
2
declare(strict_types=1);
Línea 4... Línea 3...
4
 
3
 
Línea 5... Línea 4...
5
namespace LeadersLinked\Controller;
4
namespace LeadersLinked\Controller;
Línea 24... Línea 23...
24
    /**
23
    /**
25
     *
24
     *
26
     * @var \Laminas\Db\Adapter\AdapterInterface
25
     * @var \Laminas\Db\Adapter\AdapterInterface
27
     */
26
     */
28
    private $adapter;
27
    private $adapter;
29
 
28
    
30
    /**
29
    /**
31
     *
30
     *
32
     * @var \LeadersLinked\Cache\CacheInterface
31
     * @var \LeadersLinked\Cache\CacheInterface
33
     */
32
     */
34
    private $cache;
33
    private $cache;
35
 
34
    
36
 
35
    
37
    /**
36
    /**
38
     *
37
     *
39
     * @var \Laminas\Log\LoggerInterface
38
     * @var \Laminas\Log\LoggerInterface
40
     */
39
     */
41
    private $logger;
40
    private $logger;
42
 
41
    
43
    /**
42
    /**
44
     *
43
     *
45
     * @var array
44
     * @var array
46
     */
45
     */
47
    private $config;
46
    private $config;
48
 
47
    
49
 
48
    
50
    /**
49
    /**
51
     *
50
     *
52
     * @var \Laminas\Mvc\I18n\Translator
51
     * @var \Laminas\Mvc\I18n\Translator
53
     */
52
     */
54
    private $translator;
53
    private $translator;
55
 
54
    
56
 
55
    
57
    /**
56
    /**
58
     *
57
     *
59
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
58
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
60
     * @param \LeadersLinked\Cache\CacheInterface $cache
59
     * @param \LeadersLinked\Cache\CacheInterface $cache
61
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
60
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
Línea 68... Línea 67...
68
        $this->cache        = $cache;
67
        $this->cache        = $cache;
69
        $this->logger       = $logger;
68
        $this->logger       = $logger;
70
        $this->config       = $config;
69
        $this->config       = $config;
71
        $this->translator   = $translator;
70
        $this->translator   = $translator;
72
    }
71
    }
73
 
72
    
74
    /**
-
 
75
     * Acción principal que maneja la lista de emojis del Daily Pulse
-
 
76
     * 
-
 
77
     * Esta acción tiene dos comportamientos:
-
 
78
     * 1. Si la petición es JSON (API): Retorna una lista paginada de emojis para DataTables
-
 
79
     * 2. Si la petición es HTML: Muestra el formulario de gestión de emojis
-
 
80
     * 
-
 
81
     * @return \Laminas\View\Model\JsonModel|\Laminas\View\Model\ViewModel
-
 
82
     */
-
 
83
    public function indexAction()
73
    public function indexAction()
84
    {
74
    {
85
        // Obtiene el plugin de red actual y la red
-
 
86
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
75
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
87
        $currentNetwork = $currentNetworkPlugin->getNetwork();
76
        $currentNetwork = $currentNetworkPlugin->getNetwork();
88
 
77
        
89
        // Obtiene el plugin de usuario actual, el usuario y la compañía
-
 
90
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
78
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
91
        $currentUser        = $currentUserPlugin->getUser();
79
        $currentUser        = $currentUserPlugin->getUser();
92
        $currentCompany     = $currentUserPlugin->getCompany();
80
        $currentCompany     = $currentUserPlugin->getCompany();
93
 
81
        
94
        // Obtiene la petición HTTP
-
 
95
        $request = $this->getRequest();
82
        $request = $this->getRequest();
96
        if ($request->isGet()) {
83
        if($request->isGet()) {
97
            // Verifica los headers de la petición
-
 
-
 
84
            
-
 
85
            
98
            $headers  = $request->getHeaders();
86
            $headers  = $request->getHeaders();
99
 
87
            
100
            // Verifica si la petición es JSON
-
 
101
            $isJson = false;
88
            $isJson = false;
102
            if ($headers->has('Accept')) {
89
            if($headers->has('Accept')) {
103
                $accept = $headers->get('Accept');
90
                $accept = $headers->get('Accept');
-
 
91
                
104
                $prioritized = $accept->getPrioritized();
92
                $prioritized = $accept->getPrioritized();
-
 
93
                
105
                foreach ($prioritized as $key => $value) {
94
                foreach($prioritized as $key => $value) {
106
                    $raw = trim($value->getRaw());
95
                    $raw = trim($value->getRaw());
-
 
96
                    
107
                    if (!$isJson) {
97
                    if(!$isJson) {
108
                        $isJson = strpos($raw, 'json');
98
                        $isJson = strpos($raw, 'json');
109
                    }
99
                    }
-
 
100
                    
110
                }
101
                }
111
            }
102
            }
112
 
103
            
113
            if ($isJson) {
104
            if($isJson) {
114
                // Si es una petición JSON, procesa los parámetros de DataTables
-
 
115
                $search = $this->params()->fromQuery('search', []);
105
                $search = $this->params()->fromQuery('search', []);
116
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
106
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
117
 
107
                
118
                // Obtiene parámetros de paginación
-
 
119
                $page               = intval($this->params()->fromQuery('start', 1), 10);
108
                $page               = intval($this->params()->fromQuery('start', 1), 10);
120
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
109
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
121
 
-
 
122
                // Obtiene parámetros de ordenamiento
-
 
123
                $order =  $this->params()->fromQuery('order', []);
110
                $order =  $this->params()->fromQuery('order', []);
124
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
111
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
125
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
112
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
126
 
113
                
127
                // Define los campos ordenables
-
 
128
                $fields =  ['name'];
114
                $fields =  ['name'];
129
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
115
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
130
 
116
                
131
                // Valida la dirección del ordenamiento
-
 
132
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
117
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
133
                    $order_direction = 'ASC';
118
                    $order_direction = 'ASC';
134
                }
119
                }
135
 
120
                
136
                // Obtiene los emojis paginados
-
 
137
                $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
121
                $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
138
                $paginator = $dailyPulseEmojiMapper->fetchAllDataTable($currentCompany->id, $search,  $page, $records_x_page, $order_field, $order_direction);
122
                $paginator = $dailyPulseEmojiMapper->fetchAllDataTable($currentCompany->id, $search,  $page, $records_x_page, $order_field, $order_direction);
Línea 139... Línea -...
139
 
-
 
140
                // Obtiene la instancia de Storage y la ruta para los emojis
123
 
141
                $storage = Storage::getInstance($this->config, $this->adapter);
124
                $storage = Storage::getInstance($this->config, $this->adapter);
142
                $path = $storage->getPathDailyPulse();
125
                $path = $storage->getPathDailyPulse();
143
 
-
 
144
                // Procesa los registros
126
                
145
                $items = [];
127
                $items = [];
146
                $records = $paginator->getCurrentItems();
128
                $records = $paginator->getCurrentItems();
147
                foreach ($records as $record) {
129
                foreach($records as $record)
148
                    // Determina el tipo de emoji
130
                {
-
 
131
                    switch($record->type)
149
                    switch ($record->type) {
132
                    {
150
                        case DailyPulseEmoji::TYPE_HOW_ARE_YOU_FEEL:
133
                        case DailyPulseEmoji::TYPE_HOW_ARE_YOU_FEEL : 
151
                            $type = 'LABEL_HOW_ARE_YOU_FEEL';
134
                            $type = 'LABEL_HOW_ARE_YOU_FEEL';
-
 
135
                            break;
152
                            break;
136
                     
153
                        case DailyPulseEmoji::TYPE_CLIMATE_ON_YOUR_ORGANIZATION:
137
                        case DailyPulseEmoji::TYPE_CLIMATE_ON_YOUR_ORGANIZATION :
154
                            $type = 'LABEL_CLIMATE_ON_YOUR_ORGANIZATION';
138
                            $type = 'LABEL_CLIMATE_ON_YOUR_ORGANIZATION';
-
 
139
                            break;
155
                            break;
140
                            
156
                        default:
141
                        default : 
157
                            $type = 'LABEL_UNKNOWN';
142
                            $type = 'LABEL_UNKNOWN';
-
 
143
                            break;
158
                            break;
144
                            
159
                    }
145
                    }
160
 
146
                    
161
                    // Determina el estado del emoji
147
                    switch($record->status) 
162
                    switch ($record->status) {
148
                    {
163
                        case DailyPulseEmoji::STATUS_ACTIVE:
149
                        case DailyPulseEmoji::STATUS_ACTIVE :
164
                            $status = 'LABEL_ACTIVE';
150
                            $status = 'LABEL_ACTIVE';
-
 
151
                            break;
165
                            break;
152
                            
166
                        case DailyPulseEmoji::STATUS_INACTIVE:
153
                        case DailyPulseEmoji::STATUS_INACTIVE :
167
                            $status = 'LABEL_INACTIVE';
154
                            $status = 'LABEL_INACTIVE';
-
 
155
                            break;
168
                            break;
156
                            
169
                        default:
157
                        default :
170
                            $status = 'LABEL_UNKNOWN';
158
                            $status = 'LABEL_UNKNOWN';
171
                            break;
159
                            break;
172
                    }
160
                    }
173
 
-
 
-
 
161
                    
-
 
162
                    
174
                    // Construye el item para la respuesta
163
                    
175
                    $item = [
164
                    $item = [
176
                        'name' => $record->name,
165
                        'name' => $record->name,
177
                        'details' => [
166
                        'details' => [
178
                            'type' => $type,
167
                            'type' => $type,
179
                            'status' => $status,
168
                            'status' => $status,
180
                            'order' => $record->order,
169
                            'order' => $record->order,
181
                            'points' => $record->points,
170
                            'points' => $record->points,
182
                        ],
171
                        ],    
183
                        'image' => $storage->getGenericImage($path, $record->uuid, $record->image),
172
                        'image' => $storage->getGenericImage($path, $record->uuid, $record->image),
184
                        'actions' => [
173
                        'actions' => [
185
                            'link_edit' => $this->url()->fromRoute('daily-pulse/emojis/edit', ['id' => $record->uuid]),
174
                            'link_edit' => $this->url()->fromRoute('daily-pulse/emojis/edit', ['id' => $record->uuid ]),
186
                            'link_delete' => $this->url()->fromRoute('daily-pulse/emojis/delete', ['id' => $record->uuid]),
175
                            'link_delete' => $this->url()->fromRoute('daily-pulse/emojis/delete', ['id' => $record->uuid ]),
187
                        ]
176
                        ]
188
                    ];
177
                    ];
189
 
178
                    
190
                    array_push($items, $item);
179
                    array_push($items, $item);
191
                }
180
                }
192
 
-
 
193
                // Retorna la respuesta JSON
181
                
194
                return new JsonModel([
182
                return new JsonModel([
195
                    'success' => true,
183
                    'success' => true,
196
                    'data' => [
184
                    'data' => [
197
                        'items' => $items,
185
                        'items' => $items,
198
                        'total' => $paginator->getTotalItemCount(),
186
                        'total' => $paginator->getTotalItemCount(),
199
                    ]
187
                    ]
200
                ]);
188
                ]);
201
            } else {
-
 
-
 
189
            } else  {
202
                // Si no es JSON, muestra la vista HTML
190
                
203
                $target_size = $this->config['leaderslinked.image_sizes.emoji'];
191
                $target_size = $this->config['leaderslinked.image_sizes.emoji'];
204
 
-
 
205
                // Crea los formularios
192
                
206
                $formAdd = new DailyPulseAddEmojiForm();
193
                $formAdd = new DailyPulseAddEmojiForm();
207
                $formEdit = new DailyPulseEditEmojiForm();
194
                $formEdit = new DailyPulseEditEmojiForm();
208
 
-
 
209
                // Configura la vista
195
                
210
                $this->layout()->setTemplate('layout/layout-backend');
196
                $this->layout()->setTemplate('layout/layout-backend');
211
                $viewModel = new ViewModel();
197
                $viewModel = new ViewModel();
212
                $viewModel->setTemplate('leaders-linked/daily-pulse/emojis');
198
                $viewModel->setTemplate('leaders-linked/daily-pulse/emojis');
213
                $viewModel->setVariables([
199
                $viewModel->setVariables([
214
                    'formAdd' => $formAdd,
200
                    'formAdd' => $formAdd,
215
                    'formEdit' => $formEdit,
201
                    'formEdit' => $formEdit,
216
                    'targetSize' => $target_size,
202
                    'targetSize' => $target_size,
217
                ]);
203
                ]);
218
                return $viewModel;
204
                return $viewModel ;
219
            }
205
            }
220
        } else {
-
 
221
            // Si no es GET, retorna error
206
        } else {
222
            return new JsonModel([
207
            return new JsonModel([
223
                'success' => false,
208
                'success' => false,
224
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
209
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
225
            ]);
210
            ]);;
226
        }
211
        }
227
    }
212
    }
228
 
213
    
229
 
214
    
230
 
215
    
231
    public function addAction()
216
    public function addAction()
232
    {
217
    {
233
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
218
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
234
        $currentUser        = $currentUserPlugin->getUser();
219
        $currentUser        = $currentUserPlugin->getUser();
235
        $currentCompany     = $currentUserPlugin->getCompany();
220
        $currentCompany     = $currentUserPlugin->getCompany();
236
 
221
        
Línea 237... Línea 222...
237
        $request            = $this->getRequest();
222
        $request            = $this->getRequest();
238
 
223
 
239
 
224
        
240
        if ($request->isPost()) {
225
        if($request->isPost()) {
241
            $form = new  DailyPulseAddEmojiForm();
226
            $form = new  DailyPulseAddEmojiForm();
242
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
227
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
243
            $dataPost['status'] = empty($dataPost['status'])  ? DailyPulseEmoji::STATUS_INACTIVE : $dataPost['status'];
228
            $dataPost['status'] = empty($dataPost['status'])  ? DailyPulseEmoji::STATUS_INACTIVE : $dataPost['status'];
244
 
229
            
245
 
230
            
246
            $form->setData($dataPost);
231
            $form->setData($dataPost);
247
 
232
            
248
            if ($form->isValid()) {
233
            if($form->isValid()) {
249
                $dataPost = (array) $form->getData();
234
                $dataPost = (array) $form->getData();
250
 
235
          
251
                $dailyPulseEmoji = new DailyPulseEmoji();
236
                $dailyPulseEmoji = new DailyPulseEmoji();
252
                $dailyPulseEmoji->company_id = $currentCompany->id;
237
                $dailyPulseEmoji->company_id = $currentCompany->id;
253
                $dailyPulseEmoji->name = $dataPost['name'];
238
                $dailyPulseEmoji->name = $dataPost['name'];
254
                $dailyPulseEmoji->order = $dataPost['order'];
239
                $dailyPulseEmoji->order = $dataPost['order'];
255
                $dailyPulseEmoji->points = $dataPost['points'];
240
                $dailyPulseEmoji->points = $dataPost['points'];
256
                $dailyPulseEmoji->status = $dataPost['status'];
241
                $dailyPulseEmoji->status = $dataPost['status'];
257
                $dailyPulseEmoji->type = $dataPost['type'];
242
                $dailyPulseEmoji->type = $dataPost['type'];
258
                $dailyPulseEmoji->image = '';
243
                $dailyPulseEmoji->image = '';
259
 
244
                
260
                $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
245
                $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
261
                if ($dailyPulseEmojiMapper->insert($dailyPulseEmoji)) {
246
                if($dailyPulseEmojiMapper->insert($dailyPulseEmoji)) {
262
 
247
                    
263
                    $dailyPulseEmoji = $dailyPulseEmojiMapper->fetchOne($dailyPulseEmoji->id);
248
                    $dailyPulseEmoji = $dailyPulseEmojiMapper->fetchOne($dailyPulseEmoji->id);
264
 
249
                    
265
                    $target_size = $this->config['leaderslinked.image_sizes.emoji'];
-
 
266
                    list($target_width, $target_height) = explode('x', $target_size);
250
                    $target_size = $this->config['leaderslinked.image_sizes.emoji'];
267
 
-
 
268
 
-
 
269
 
251
                    list($target_width, $target_height) = explode('x', $target_size);
270
                    $image = Image::getInstance($this->config);
252
                    
271
                    $storage = Storage::getInstance($this->config, $this->adapter);
253
                    $storageServices = Storage::getInstance($this->config, $this->adapter);
272
                    $target_path = $storage->getPathDailyPulse();
254
                    $target_path = $storageServices->getPathDailyPulse();
273
 
-
 
274
                    $files = $this->getRequest()->getFiles()->toArray();
255
                    
275
 
256
                    $files = $this->getRequest()->getFiles()->toArray();
276
 
257
                    
277
                    if (isset($files['image']) && empty($files['image']['error'])) {
-
 
278
                        $tmp_filename  = $files['image']['tmp_name'];
258
                    if(isset($files['image']) && empty($files['image']['error'])) {
279
                        $filename      = explode('.',  $files['image']['name']);
259
                        $tmp_filename = $files['image']['tmp_name'];
280
                        $filename       = Functions::normalizeStringFilename(uniqid() . '-' . $filename[0] . '.png');
260
                        $filename = Functions::normalizeStringFilename(uniqid() . '-' . basename($files['image']['name'], '.png') . '.png');
281
 
-
 
282
                        $crop_to_dimensions = true;
-
 
283
                        $unlink_source = true;
261
                        
284
 
262
                        // Procesar la imagen con StorageServices
285
                        if ($image->uploadProcessChangeSize($tmp_filename, $target_path, $dailyPulseEmoji->uuid, $filename, $target_width, $target_height, $crop_to_dimensions, $unlink_source)) {
263
                        if($storageServices->uploadImageCrop($tmp_filename, $target_path . DIRECTORY_SEPARATOR . $dailyPulseEmoji->uuid . DIRECTORY_SEPARATOR . $filename, $target_width, $target_height)) {
286
                            $dailyPulseEmoji->image = $filename;
264
                            $dailyPulseEmoji->image = $filename;
287
                            $dailyPulseEmojiMapper->update($dailyPulseEmoji);
265
                            $dailyPulseEmojiMapper->update($dailyPulseEmoji);
288
                        }
-
 
289
                    }
266
                        }
290
 
267
                    }
291
 
268
                    
292
                    $this->logger->info('Se agrego el emoji ' . $dailyPulseEmoji->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
269
                    $this->logger->info('Se agrego el emoji ' . $dailyPulseEmoji->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
293
 
270
                    
294
                    $data = [
271
                    $data = [
295
                        'success'   => true,
272
                        'success'   => true,
296
                        'data'   => 'LABEL_RECORD_ADDED'
273
                        'data'   => 'LABEL_RECORD_ADDED'
297
                    ];
274
                    ];
298
                } else {
275
                } else {
299
                    $data = [
276
                    $data = [
300
                        'success'   => false,
277
                        'success'   => false,
-
 
278
                        'data'      => $dailyPulseEmojiMapper->getError()
301
                        'data'      => $dailyPulseEmojiMapper->getError()
279
                    ];
302
                    ];
280
                    
303
                }
281
                }
-
 
282
                
304
 
283
                return new JsonModel($data);
305
                return new JsonModel($data);
284
                
306
            } else {
285
            } else {
307
                $messages = [];
286
                $messages = [];
-
 
287
                $form_messages = (array) $form->getMessages();
308
                $form_messages = (array) $form->getMessages();
288
                foreach($form_messages  as $fieldname => $field_messages)
309
                foreach ($form_messages  as $fieldname => $field_messages) {
289
                {
310
 
290
                    
311
                    $messages[$fieldname] = array_values($field_messages);
291
                    $messages[$fieldname] = array_values($field_messages);
312
                }
292
                }
313
 
293
                
314
                return new JsonModel([
294
                return new JsonModel([
315
                    'success'   => false,
295
                    'success'   => false,
316
                    'data'   => $messages
296
                    'data'   => $messages
-
 
297
                ]);
317
                ]);
298
            }
318
            }
299
            
319
        } else {
300
        } else {
320
            $data = [
301
            $data = [
321
                'success' => false,
302
                'success' => false,
322
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
303
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
323
            ];
304
            ];
324
 
305
            
325
            return new JsonModel($data);
306
            return new JsonModel($data);
326
        }
307
        }
327
 
308
        
328
        return new JsonModel($data);
309
        return new JsonModel($data);
329
    }
310
    }
330
 
311
    
331
    /**
312
    /**
332
     *
313
     *
333
     * Borrar un perfil excepto el público
314
     * Borrar un perfil excepto el público
334
     * @return \Laminas\View\Model\JsonModel
315
     * @return \Laminas\View\Model\JsonModel
335
     */
316
     */
336
    public function deleteAction()
317
    public function deleteAction()
337
    {
318
    {
338
        $currentUserPlugin = $this->plugin('currentUserPlugin');
319
        $currentUserPlugin = $this->plugin('currentUserPlugin');
339
        $currentUser    = $currentUserPlugin->getUser();
320
        $currentUser    = $currentUserPlugin->getUser();
340
        $currentCompany = $currentUserPlugin->getCompany();
321
        $currentCompany = $currentUserPlugin->getCompany();
341
 
322
        
Línea 342... Línea 323...
342
        $request        = $this->getRequest();
323
        $request        = $this->getRequest();
Línea 343... Línea 324...
343
        $id         = $this->params()->fromRoute('id');
324
        $id         = $this->params()->fromRoute('id');
344
 
325
 
345
 
326
        
346
 
327
 
347
        $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
328
        $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
348
        $dailyPulseEmoji = $dailyPulseEmojiMapper->fetchOneByUuid($id);
329
        $dailyPulseEmoji = $dailyPulseEmojiMapper->fetchOneByUuid($id);
349
        if (!$dailyPulseEmoji) {
330
        if(!$dailyPulseEmoji) {
350
            return new JsonModel([
331
            return new JsonModel([
351
                'success'   => false,
332
                'success'   => false,
352
                'data'   => 'ERROR_RECORD_NOT_FOUND'
333
                'data'   => 'ERROR_RECORD_NOT_FOUND'
353
            ]);
334
            ]);
354
        }
335
        }
355
 
336
        
356
        if ($dailyPulseEmoji->company_id != $currentCompany->id) {
337
        if($dailyPulseEmoji->company_id != $currentCompany->id) {
357
            return new JsonModel([
338
            return new JsonModel([
358
                'success'   => false,
339
                'success'   => false,
359
                'data'   => 'ERROR_UNAUTHORIZED'
340
                'data'   => 'ERROR_UNAUTHORIZED'
360
            ]);
341
            ]);
361
        }
342
        }
362
 
343
        
363
        if ($request->isPost()) {
344
        if($request->isPost()) {
364
 
345
            
365
            $result =  $dailyPulseEmojiMapper->delete($dailyPulseEmoji);
346
            $result =  $dailyPulseEmojiMapper->delete($dailyPulseEmoji);
366
            if ($result) {
347
            if($result) {
367
                $this->logger->info('Se borro el emoji : ' .  $dailyPulseEmoji->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
348
                $this->logger->info('Se borro el emoji : ' .  $dailyPulseEmoji->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
368
 
349
               
369
                if ($dailyPulseEmoji->image) {
350
                if($dailyPulseEmoji->image) {
370
 
351
                
371
                    $storage = Storage::getInstance($this->config, $this->adapter);
352
                    $storage = Storage::getInstance($this->config, $this->adapter);
372
                    $target_path = $storage->getPathDailyPulse();
353
                    $target_path = $storage->getPathDailyPulse();
373
                    $storage->deleteFile($target_path, $dailyPulseEmoji->uuid, $dailyPulseEmoji->image);
354
                    $storage->deleteFile($target_path, $dailyPulseEmoji->uuid, $dailyPulseEmoji->image);
374
                }
355
                }
375
 
356
                
376
                $data = [
357
                $data = [
377
                    'success' => true,
358
                    'success' => true,
378
                    'data' => 'LABEL_RECORD_DELETED'
359
                    'data' => 'LABEL_RECORD_DELETED'
379
                ];
360
                ];
380
            } else {
361
            } else {
381
 
362
                
382
                $data = [
363
                $data = [
383
                    'success'   => false,
364
                    'success'   => false,
384
                    'data'      => $dailyPulseEmojiMapper->getError()
365
                    'data'      => $dailyPulseEmojiMapper->getError()
-
 
366
                ];
385
                ];
367
                
386
 
368
                return new JsonModel($data);
387
                return new JsonModel($data);
369
            }
388
            }
370
            
389
        } else {
371
        } else {
390
            $data = [
372
            $data = [
391
                'success' => false,
373
                'success' => false,
392
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
374
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
393
            ];
375
            ];
394
 
376
            
395
            return new JsonModel($data);
377
            return new JsonModel($data);
396
        }
378
        }
397
 
379
        
398
        return new JsonModel($data);
380
        return new JsonModel($data);
399
    }
381
    }
400
 
382
    
401
 
383
    
402
    public function editAction()
384
    public function editAction()
403
    {
385
    {
404
        $currentUserPlugin = $this->plugin('currentUserPlugin');
386
        $currentUserPlugin = $this->plugin('currentUserPlugin');
405
        $currentUser    = $currentUserPlugin->getUser();
387
        $currentUser    = $currentUserPlugin->getUser();
Línea 406... Línea 388...
406
        $currentCompany = $currentUserPlugin->getCompany();
388
        $currentCompany = $currentUserPlugin->getCompany();
407
 
389
        
408
        $request    = $this->getRequest();
390
        $request    = $this->getRequest();
409
        $id    = $this->params()->fromRoute('id');
391
        $id    = $this->params()->fromRoute('id');
410
 
392
 
411
 
393
 
412
        $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
394
        $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
413
        $dailyPulseEmoji = $dailyPulseEmojiMapper->fetchOneByUuid($id);
395
        $dailyPulseEmoji = $dailyPulseEmojiMapper->fetchOneByUuid($id);
414
        if (!$dailyPulseEmoji) {
396
        if(!$dailyPulseEmoji) {
415
            return new JsonModel([
397
            return new JsonModel([
416
                'success'   => false,
398
                'success'   => false,
417
                'data'   => 'ERROR_RECORD_NOT_FOUND'
399
                'data'   => 'ERROR_RECORD_NOT_FOUND'
418
            ]);
400
            ]);
419
        }
401
        }
420
 
402
        
421
 
403
        
422
        if ($dailyPulseEmoji->company_id != $currentCompany->id) {
404
        if($dailyPulseEmoji->company_id != $currentCompany->id) {
423
            return new JsonModel([
405
            return new JsonModel([
424
                'success'   => false,
406
                'success'   => false,
425
                'data'   => 'ERROR_UNAUTHORIZED'
407
                'data'   => 'ERROR_UNAUTHORIZED'
426
            ]);
408
            ]);
427
        }
409
        }
428
 
410
        
429
        if ($request->isGet()) {
411
        if($request->isGet()) {
430
            $storage = Storage::getInstance($this->config, $this->adapter);
412
            $storage = Storage::getInstance($this->config, $this->adapter);
431
            $path = $storage->getPathDailyPulse();
413
            $path = $storage->getPathDailyPulse();
432
 
414
            
Línea 440... Línea 422...
440
                    'type' => $dailyPulseEmoji->type,
422
                    'type' => $dailyPulseEmoji->type,
441
                    'points' => $dailyPulseEmoji->points,
423
                    'points' => $dailyPulseEmoji->points,
442
                    'image' => $dailyPulseEmoji->image ? $storage->getGenericImage($path,  $dailyPulseEmoji->uuid, $dailyPulseEmoji->image) : '',
424
                    'image' => $dailyPulseEmoji->image ? $storage->getGenericImage($path,  $dailyPulseEmoji->uuid, $dailyPulseEmoji->image) : '',
443
                ]
425
                ]
444
            ];
426
            ];
445
 
427
            
446
            return new JsonModel($data);
428
            return new JsonModel($data);
-
 
429
        }
447
        } else if ($request->isPost()) {
430
        else if($request->isPost()) {
448
            $form = new  DailyPulseEditEmojiForm();
431
            $form = new  DailyPulseEditEmojiForm();
449
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
432
            $dataPost = array_merge($request->getPost()->toArray(), $request->getFiles()->toArray());
450
            $dataPost['status'] = empty($dataPost['status'])  ? DailyPulseEmoji::STATUS_INACTIVE : $dataPost['status'];
433
            $dataPost['status'] = empty($dataPost['status'])  ? DailyPulseEmoji::STATUS_INACTIVE : $dataPost['status'];
451
 
434
            
452
 
435
            
453
            $form->setData($dataPost);
436
            $form->setData($dataPost);
454
 
437
            
455
            if ($form->isValid()) {
438
            if($form->isValid()) {
456
                $dataPost = (array) $form->getData();
439
                $dataPost = (array) $form->getData();
457
 
440
                
458
                $dailyPulseEmoji->name = $dataPost['name'];
441
                $dailyPulseEmoji->name = $dataPost['name'];
459
                $dailyPulseEmoji->order = $dataPost['order'];
442
                $dailyPulseEmoji->order = $dataPost['order'];
460
                $dailyPulseEmoji->points = $dataPost['points'];
443
                $dailyPulseEmoji->points = $dataPost['points'];
461
                $dailyPulseEmoji->status = $dataPost['status'];
444
                $dailyPulseEmoji->status = $dataPost['status'];
462
                $dailyPulseEmoji->type = $dataPost['type'];
445
                $dailyPulseEmoji->type = $dataPost['type'];
463
 
446
                
464
                if ($dailyPulseEmojiMapper->update($dailyPulseEmoji)) {
447
                if($dailyPulseEmojiMapper->update($dailyPulseEmoji)) {
465
 
448
                    
466
 
449
                    
467
 
450
                    
468
                    $target_size = $this->config['leaderslinked.image_sizes.emoji'];
451
                    $target_size = $this->config['leaderslinked.image_sizes.emoji'];
469
                    list($target_width, $target_height) = explode('x', $target_size);
452
                    list($target_width, $target_height) = explode('x', $target_size);
470
 
453
                   
471
 
454
                    
472
 
455
                    
473
 
456
                    
474
                    $files = $this->getRequest()->getFiles()->toArray();
457
                    $files = $this->getRequest()->getFiles()->toArray();
475
                    if (isset($files['image']) && empty($files['image']['error'])) {
458
                    if(isset($files['image']) && empty($files['image']['error'])) {
476
 
459
                        
477
                        $image = Image::getInstance($this->config);
460
                        $image = Image::getInstance($this->config);
478
                        $storage = Storage::getInstance($this->config, $this->adapter);
461
                        $storage = Storage::getInstance($this->config, $this->adapter);
479
                        $target_path = $storage->getPathDailyPulse();
462
                        $target_path = $storage->getPathDailyPulse();
480
 
463
                        
481
                        $tmp_filename  = $files['image']['tmp_name'];
464
                        $tmp_filename  = $files['image']['tmp_name'];
482
                        $filename      = explode('.',  $files['image']['name']);
465
                        $filename      = explode('.',  $files['image']['name']);
483
                        $filename       = Functions::normalizeStringFilename(uniqid() . '-' . $filename[0] . '.png');
466
                        $filename       = Functions::normalizeStringFilename(uniqid() . '-' . $filename[0].'.png');
484
 
467
                        
485
                        $crop_to_dimensions = true;
468
                        $crop_to_dimensions = true;
486
                        $full_tmp_filename = $image->uploadProcessChangeSize($tmp_filename, $filename, $target_width, $target_height,  $crop_to_dimensions);
469
                        $full_tmp_filename = $image->uploadProcessChangeSize($tmp_filename, $filename, $target_width, $target_height,  $crop_to_dimensions);
487
 
470
                        
488
                        if ($full_tmp_filename) {
471
                        if($full_tmp_filename ) { 
489
                            if ($dailyPulseEmoji->image) {
472
                            if($dailyPulseEmoji->image) {
490
                                $storage->deleteFile($target_path, $dailyPulseEmoji->uuid, $dailyPulseEmoji->image);
473
                                $storage->deleteFile($target_path, $dailyPulseEmoji->uuid, $dailyPulseEmoji->image);
491
 
474
                                
492
                                $dailyPulseEmoji->image = $filename;
475
                                $dailyPulseEmoji->image = $filename;
493
                                $dailyPulseEmojiMapper->update($dailyPulseEmoji);
476
                                $dailyPulseEmojiMapper->update($dailyPulseEmoji);
494
                            }
477
                            }
495
 
478
                            
496
                            if ($storage->putFile($target_path, $dailyPulseEmoji->uuid, $full_tmp_filename)) {
479
                            if($storage->putFile($target_path, $dailyPulseEmoji->uuid, $full_tmp_filename)) {
497
 
480
                               
498
 
481
                    
499
 
482
                                
500
                                $dailyPulseEmoji->image = $filename;
483
                                $dailyPulseEmoji->image = $filename;
501
                                $dailyPulseEmojiMapper->update($dailyPulseEmoji);
484
                                $dailyPulseEmojiMapper->update($dailyPulseEmoji);
502
                            }
485
                            }
503
                        }
486
                        }
504
                    }
487
                    }
505
 
488
                    
506
 
489
                    
507
 
490
                    
508
                    $this->logger->info('Se edito el emoji' . $dailyPulseEmoji->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
491
                    $this->logger->info('Se edito el emoji' . $dailyPulseEmoji->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
509
 
492
                    
510
                    $data = [
493
                    $data = [
511
                        'success'   => true,
494
                        'success'   => true,
512
                        'data'   => 'LABEL_RECORD_UPDATED'
495
                        'data'   => 'LABEL_RECORD_UPDATED'
513
                    ];
496
                    ];
514
                } else {
497
                } else {
515
                    $data = [
498
                    $data = [
516
                        'success'   => false,
499
                        'success'   => false,
517
                        'data'      => $dailyPulseEmojiMapper->getError()
500
                        'data'      => $dailyPulseEmojiMapper->getError()
518
                    ];
501
                    ];
-
 
502
                    
519
                }
503
                }
520
 
504
                
521
                return new JsonModel($data);
505
                return new JsonModel($data);
-
 
506
                
522
            } else {
507
            } else {
523
                $messages = [];
508
                $messages = [];
524
                $form_messages = (array) $form->getMessages();
509
                $form_messages = (array) $form->getMessages();
525
                foreach ($form_messages  as $fieldname => $field_messages) {
510
                foreach($form_messages  as $fieldname => $field_messages)
-
 
511
                {
526
 
512
                    
527
                    $messages[$fieldname] = array_values($field_messages);
513
                    $messages[$fieldname] = array_values($field_messages);
528
                }
514
                }
529
 
515
                
530
                return new JsonModel([
516
                return new JsonModel([
531
                    'success'   => false,
517
                    'success'   => false,
532
                    'data'   => $messages
518
                    'data'   => $messages
533
                ]);
519
                ]);
534
            }
520
            }
535
        } else {
521
        } else {
536
            $data = [
522
            $data = [
537
                'success' => false,
523
                'success' => false,
538
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
524
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
539
            ];
525
            ];
540
 
526
            
541
            return new JsonModel($data);
527
            return new JsonModel($data);
542
        }
528
        }
543
 
529
        
544
        return new JsonModel($data);
530
        return new JsonModel($data);
545
    }
531
    }
-
 
532
    
-
 
533
    
546
}
534
}