Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17044 Rev 17047
Línea 69... Línea 69...
69
        $this->logger       = $logger;
69
        $this->logger       = $logger;
70
        $this->config       = $config;
70
        $this->config       = $config;
71
        $this->translator   = $translator;
71
        $this->translator   = $translator;
72
    }
72
    }
Línea -... Línea 73...
-
 
73
 
-
 
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
73
 
82
     */
74
    public function indexAction()
83
    public function indexAction()
-
 
84
    {
75
    {
85
        // Obtiene el plugin de red actual y la red
76
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
86
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
Línea -... Línea 87...
-
 
87
        $currentNetwork = $currentNetworkPlugin->getNetwork();
77
        $currentNetwork = $currentNetworkPlugin->getNetwork();
88
 
78
 
89
        // Obtiene el plugin de usuario actual, el usuario y la compañía
79
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
90
        $currentUserPlugin  = $this->plugin('currentUserPlugin');
Línea -... Línea 91...
-
 
91
        $currentUser        = $currentUserPlugin->getUser();
80
        $currentUser        = $currentUserPlugin->getUser();
92
        $currentCompany     = $currentUserPlugin->getCompany();
81
        $currentCompany     = $currentUserPlugin->getCompany();
93
 
82
 
-
 
83
        $request = $this->getRequest();
-
 
-
 
94
        // Obtiene la petición HTTP
84
        if ($request->isGet()) {
95
        $request = $this->getRequest();
Línea -... Línea 96...
-
 
96
        if ($request->isGet()) {
85
 
97
            // Verifica los headers de la petición
86
 
98
            $headers  = $request->getHeaders();
87
            $headers  = $request->getHeaders();
99
 
88
 
-
 
89
            $isJson = false;
100
            // Verifica si la petición es JSON
90
            if ($headers->has('Accept')) {
-
 
91
                $accept = $headers->get('Accept');
101
            $isJson = false;
92
 
102
            if ($headers->has('Accept')) {
93
                $prioritized = $accept->getPrioritized();
-
 
94
 
103
                $accept = $headers->get('Accept');
95
                foreach ($prioritized as $key => $value) {
104
                $prioritized = $accept->getPrioritized();
96
                    $raw = trim($value->getRaw());
105
                foreach ($prioritized as $key => $value) {
97
 
106
                    $raw = trim($value->getRaw());
98
                    if (!$isJson) {
107
                    if (!$isJson) {
Línea 99... Línea 108...
99
                        $isJson = strpos($raw, 'json');
108
                        $isJson = strpos($raw, 'json');
-
 
109
                    }
100
                    }
110
                }
101
                }
111
            }
Línea -... Línea 112...
-
 
112
 
102
            }
113
            if ($isJson) {
103
 
114
                // Si es una petición JSON, procesa los parámetros de DataTables
-
 
115
                $search = $this->params()->fromQuery('search', []);
-
 
116
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
104
            if ($isJson) {
117
 
105
                $search = $this->params()->fromQuery('search', []);
118
                // Obtiene parámetros de paginación
106
                $search = empty($search['value']) ? '' :  Functions::sanitizeFilterString($search['value']);
119
                $page               = intval($this->params()->fromQuery('start', 1), 10);
Línea -... Línea 120...
-
 
120
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
107
 
121
 
108
                $page               = intval($this->params()->fromQuery('start', 1), 10);
122
                // Obtiene parámetros de ordenamiento
Línea -... Línea 123...
-
 
123
                $order =  $this->params()->fromQuery('order', []);
109
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
124
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
110
                $order =  $this->params()->fromQuery('order', []);
125
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
111
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
126
 
Línea -... Línea 127...
-
 
127
                // Define los campos ordenables
112
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(Functions::sanitizeFilterString($order[0]['dir']));
128
                $fields =  ['name'];
113
 
129
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
Línea -... Línea 130...
-
 
130
 
114
                $fields =  ['name'];
131
                // Valida la dirección del ordenamiento
115
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
132
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
Línea -... Línea 133...
-
 
133
                    $order_direction = 'ASC';
116
 
134
                }
117
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
135
 
118
                    $order_direction = 'ASC';
136
                // Obtiene los emojis paginados
-
 
137
                $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
119
                }
138
                $paginator = $dailyPulseEmojiMapper->fetchAllDataTable($currentCompany->id, $search,  $page, $records_x_page, $order_field, $order_direction);
120
 
139
 
121
                $dailyPulseEmojiMapper = DailyPulseEmojiMapper::getInstance($this->adapter);
140
                // Obtiene la instancia de Storage y la ruta para los emojis
122
                $paginator = $dailyPulseEmojiMapper->fetchAllDataTable($currentCompany->id, $search,  $page, $records_x_page, $order_field, $order_direction);
141
                $storage = Storage::getInstance($this->config, $this->adapter);
123
 
-
 
124
                $storage = Storage::getInstance($this->config, $this->adapter);
142
                $path = $storage->getPathDailyPulse();
125
                $path = $storage->getPathDailyPulse();
143
 
126
 
144
                // Procesa los registros
127
                $items = [];
-
 
128
                $records = $paginator->getCurrentItems();
145
                $items = [];
129
                foreach ($records as $record) {
146
                $records = $paginator->getCurrentItems();
130
                    switch ($record->type) {
147
                foreach ($records as $record) {
131
                        case DailyPulseEmoji::TYPE_HOW_ARE_YOU_FEEL:
148
                    // Determina el tipo de emoji
Línea -... Línea 149...
-
 
149
                    switch ($record->type) {
132
                            $type = 'LABEL_HOW_ARE_YOU_FEEL';
150
                        case DailyPulseEmoji::TYPE_HOW_ARE_YOU_FEEL:
133
                            break;
151
                            $type = 'LABEL_HOW_ARE_YOU_FEEL';
134
 
152
                            break;
135
                        case DailyPulseEmoji::TYPE_CLIMATE_ON_YOUR_ORGANIZATION:
153
                        case DailyPulseEmoji::TYPE_CLIMATE_ON_YOUR_ORGANIZATION:
136
                            $type = 'LABEL_CLIMATE_ON_YOUR_ORGANIZATION';
-
 
137
                            break;
154
                            $type = 'LABEL_CLIMATE_ON_YOUR_ORGANIZATION';
138
 
155
                            break;
139
                        default:
156
                        default:
140
                            $type = 'LABEL_UNKNOWN';
-
 
141
                            break;
157
                            $type = 'LABEL_UNKNOWN';
142
                    }
158
                            break;
143
 
159
                    }
144
                    switch ($record->status) {
160
 
Línea 145... Línea -...
145
                        case DailyPulseEmoji::STATUS_ACTIVE:
-
 
146
                            $status = 'LABEL_ACTIVE';
-
 
-
 
161
                    // Determina el estado del emoji
147
                            break;
162
                    switch ($record->status) {
148
 
163
                        case DailyPulseEmoji::STATUS_ACTIVE:
149
                        case DailyPulseEmoji::STATUS_INACTIVE:
164
                            $status = 'LABEL_ACTIVE';
150
                            $status = 'LABEL_INACTIVE';
165
                            break;
151
                            break;
166
                        case DailyPulseEmoji::STATUS_INACTIVE:
Línea 173... Línea 188...
173
                    ];
188
                    ];
Línea 174... Línea 189...
174
 
189
 
175
                    array_push($items, $item);
190
                    array_push($items, $item);
Línea -... Línea 191...
-
 
191
                }
176
                }
192
 
177
 
193
                // Retorna la respuesta JSON
178
                return new JsonModel([
194
                return new JsonModel([
179
                    'success' => true,
195
                    'success' => true,
180
                    'data' => [
196
                    'data' => [
181
                        'items' => $items,
197
                        'items' => $items,
182
                        'total' => $paginator->getTotalItemCount(),
198
                        'total' => $paginator->getTotalItemCount(),
183
                    ]
199
                    ]
184
                ]);
-
 
-
 
200
                ]);
185
            } else {
201
            } else {
Línea -... Línea 202...
-
 
202
                // Si no es JSON, muestra la vista HTML
186
 
203
                $target_size = $this->config['leaderslinked.image_sizes.emoji'];
187
                $target_size = $this->config['leaderslinked.image_sizes.emoji'];
204
 
Línea -... Línea 205...
-
 
205
                // Crea los formularios
188
 
206
                $formAdd = new DailyPulseAddEmojiForm();
189
                $formAdd = new DailyPulseAddEmojiForm();
207
                $formEdit = new DailyPulseEditEmojiForm();
190
                $formEdit = new DailyPulseEditEmojiForm();
208
 
191
 
209
                // Configura la vista
192
                $this->layout()->setTemplate('layout/layout-backend');
210
                $this->layout()->setTemplate('layout/layout-backend');
Línea 198... Línea 216...
198
                    'targetSize' => $target_size,
216
                    'targetSize' => $target_size,
199
                ]);
217
                ]);
200
                return $viewModel;
218
                return $viewModel;
201
            }
219
            }
202
        } else {
220
        } else {
-
 
221
            // Si no es GET, retorna error
203
            return new JsonModel([
222
            return new JsonModel([
204
                'success' => false,
223
                'success' => false,
205
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
224
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
206
            ]);;
225
            ]);
207
        }
226
        }
208
    }
227
    }