Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 17251 Rev 17253
Línea 71... Línea 71...
71
        $this->translator   = $translator;
71
        $this->translator   = $translator;
72
    }
72
    }
Línea 73... Línea 73...
73
 
73
 
74
    public function indexAction()
74
    public function indexAction()
75
    {
-
 
-
 
75
    {
76
        // Obtiene el plugin del usuario actual y la compañía
76
 
77
        $currentUserPlugin = $this->plugin('currentUserPlugin');
77
        $currentUserPlugin = $this->plugin('currentUserPlugin');
78
        $currentUser = $currentUserPlugin->getUser();
78
        $currentUser = $currentUserPlugin->getUser();
Línea 79... Línea -...
79
        $currentCompany = $currentUserPlugin->getCompany();
-
 
80
 
79
        $currentCompany = $currentUserPlugin->getCompany();
81
        // Obtiene la solicitud actual
-
 
82
        $request = $this->getRequest();
-
 
Línea -... Línea 80...
-
 
80
 
83
        // Verifica si la solicitud es de tipo GET
81
        $request = $this->getRequest();
84
        if ($request->isGet()) {
82
 
Línea 85... Línea -...
85
 
-
 
86
            // Obtiene los encabezados de la solicitud
83
 
-
 
84
        if ($request->isGet()) {
87
            $headers  = $request->getHeaders();
85
            $headers  = $request->getHeaders();
88
 
86
 
Línea 89... Línea 87...
89
            // Determina si la respuesta debe ser JSON
87
            $isJson = false;
Línea 100... Línea 98...
100
                        $isJson = strpos($raw, 'json');
98
                        $isJson = strpos($raw, 'json');
101
                    }
99
                    }
102
                }
100
                }
103
            }
101
            }
Línea 104... Línea -...
104
 
-
 
-
 
102
 
105
            // Si la respuesta debe ser JSON
103
 
106
            if ($isJson) {
-
 
107
                // Obtiene y sanitiza los parámetros de la consulta
104
            if ($isJson) {
108
                $search = $this->params()->fromQuery('search');
105
                $search = $this->params()->fromQuery('search');
Línea 109... Línea 106...
109
                $search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
106
                $search = empty($search['value']) ? '' : Functions::sanitizeFilterString($search['value']);
110
 
107
 
111
                $page               = intval($this->params()->fromQuery('start', 1), 10);
108
                $page               = intval($this->params()->fromQuery('start', 1), 10);
112
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
109
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
113
                $order =  $this->params()->fromQuery('order', []);
110
                $order =  $this->params()->fromQuery('order', []);
Línea 114... Línea -...
114
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
-
 
115
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
111
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
116
 
112
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
Línea 117... Línea 113...
117
                // Define los campos de ordenación
113
 
118
                $fields =  ['name'];
114
                $fields =  ['name'];
119
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
115
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
Línea 120... Línea -...
120
 
-
 
121
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
116
 
122
                    $order_direction = 'ASC';
117
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
Línea 123... Línea -...
123
                }
-
 
124
 
118
                    $order_direction = 'ASC';
125
                // Obtiene el mapeador de categorías de medios y los datos paginados
119
                }
126
                $mediaCategoryMapper = MediaCategoryMapper::getInstance($this->adapter);
120
 
127
                $paginator = $mediaCategoryMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
121
                $mediaCategoryMapper = MediaCategoryMapper::getInstance($this->adapter);
128
 
122
                $paginator = $mediaCategoryMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
Línea 139... Línea 133...
139
                    ];
133
                    ];
Línea 140... Línea 134...
140
 
134
 
141
                    array_push($items, $item);
135
                    array_push($items, $item);
Línea 142... Línea -...
142
                }
-
 
143
 
136
                }
144
                // Devuelve un modelo JSON con los datos
137
 
145
                return new JsonModel([
138
                return new JsonModel([
146
                    'success' => true,
139
                    'success' => true,
147
                    'data' => [
140
                    'data' => [
148
                        'items' => $items,
141
                        'items' => $items,
149
                        'total' => $paginator->getTotalItemCount(),
142
                        'total' => $paginator->getTotalItemCount(),
150
                    ]
143
                    ]
151
                ]);
-
 
152
            } else {
144
                ]);
153
                // Si no es JSON, devuelve el formulario y la vista
-
 
154
                $form = new CategoryForm();
145
            } else {
155
 
146
                $form = new CategoryForm();
156
                $this->layout()->setTemplate('layout/layout-backend');
147
                $this->layout()->setTemplate('layout/layout-backend');
157
                $viewModel = new ViewModel();
148
                $viewModel = new ViewModel();
158
                $viewModel->setTemplate('leaders-linked/media/categories.phtml');
149
                $viewModel->setTemplate('leaders-linked/media/categories.phtml');
159
                $viewModel->setVariable('form', $form);
150
                $viewModel->setVariable('form', $form);
160
                return $viewModel;
151
                return $viewModel;
161
            }
-
 
162
        } else {
152
            }
163
            // Si la solicitud no es GET, devuelve un error
153
        } else {
164
            return new JsonModel([
154
            return new JsonModel([
165
                'success' => false,
155
                'success' => false,
166
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
156
                'data' => 'ERROR_METHOD_NOT_ALLOWED'