mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
add duplicate method
This commit is contained in:
@ -9,6 +9,8 @@ use App\Models\Collection;
|
||||
use App\Entities\Configuracion\Maquina;
|
||||
|
||||
use App\Models\Configuracion\MaquinaModel;
|
||||
use App\Services\MaquinaService;
|
||||
use CodeIgniter\Validation\Validation;
|
||||
|
||||
class Maquinas extends \App\Controllers\BaseResourceController
|
||||
{
|
||||
@ -26,18 +28,19 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
protected static $viewPath = 'themes/vuexy/form/configuracion/maquinas/';
|
||||
|
||||
protected $indexRoute = 'maquinaList';
|
||||
|
||||
protected MaquinaService $maquinaService;
|
||||
protected Validation $validation;
|
||||
|
||||
public function initController(\CodeIgniter\HTTP\RequestInterface $request, \CodeIgniter\HTTP\ResponseInterface $response, \Psr\Log\LoggerInterface $logger)
|
||||
{
|
||||
$this->viewData['pageTitle'] = lang('Maquinas.moduleTitle');
|
||||
$this->viewData['usingSweetAlert'] = true;
|
||||
|
||||
$this->maquinaService = service('maquina');
|
||||
$this->validation = service('validation');
|
||||
// Se indica que este controlador trabaja con soft_delete
|
||||
$this->soft_delete = true;
|
||||
// Se indica el flag para los ficheros borrados
|
||||
$this->delete_flag = 1;
|
||||
|
||||
$this->viewData = ['usingServerSideDataTable' => true]; // JJO
|
||||
|
||||
// Breadcrumbs (IMN)
|
||||
@ -385,6 +388,19 @@ class Maquinas extends \App\Controllers\BaseResourceController
|
||||
];
|
||||
return $tipoOptions;
|
||||
}
|
||||
public function duplicate(int $maquina_id)
|
||||
{
|
||||
|
||||
$bodyData = $this->request->getPost();
|
||||
$validated = $this->validation->run($bodyData,'maquina_duplicate');
|
||||
if($validated){
|
||||
$this->maquinaService->setMaquina($maquina_id);
|
||||
$duplicated = $this->maquinaService->duplicate($bodyData['name']);
|
||||
return $this->response->setJSON(["data" => $duplicated]);
|
||||
}else{
|
||||
return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user