cambios de legacytables3

This commit is contained in:
Jaime Jiménez
2023-05-16 12:59:12 +02:00
parent ea0c714550
commit 5a0b82dcbb
58 changed files with 2955 additions and 468 deletions

View File

@ -30,14 +30,13 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
$this->viewData['usingClientSideDataTable'] = true;
$this->viewData['pageSubTitle'] = lang('Basic.global.ManageAllRecords', [lang('Tarifaacabado.tarifaacabado')]);
parent::index();
}
public function add() {
$session = session();
$requestMethod = $this->request->getMethod();
@ -46,8 +45,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData['user_created_id'] = $session->id_user;
$sanitizedData['user_update_id'] = $session->id_user;
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -100,6 +100,8 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
} // end function add()
public function edit($requestedId = null) {
$session = session();
if ($requestedId == null) :
return $this->redirect2listView();
@ -119,9 +121,9 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
$nullIfEmpty = true; // !(phpversion() >= '8.1');
$postData = $this->request->getPost();
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData = $this->sanitized($postData, $nullIfEmpty);
$sanitizedData['user_update_id'] = $session->id_user;
$noException = true;
if ($successfulResult = $this->canValidate()) : // if ($successfulResult = $this->validate($this->formValidationRules) ) :
@ -223,5 +225,80 @@ class Tarifaacabado extends \App\Controllers\GoBaseController {
return $this->failUnauthorized('Invalid request', 403);
}
}
public function delete($requestedId, bool $deletePermanently = false) {
if (is_string($requestedId)) :
if (is_numeric($requestedId)) :
$id = filter_var($requestedId, FILTER_SANITIZE_NUMBER_INT);
else:
$onlyAlphaNumeric = true;
$fromGetRequest = true;
$idSanitization = goSanitize($requestedId, $onlyAlphaNumeric, $fromGetRequest); // filter_var(trim($requestedId), FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$id = $idSanitization[0];
endif;
else:
$id = intval($requestedId);
endif;
if (empty($id) || $id === 0) :
$error = 'Invalid identifier provided to delete the object.';
endif;
$rawResult = null;
if (!isset($error)) :
try {
if ($deletePermanently) :
if (is_numeric($id)) :
$rawResult = $this->primaryModel->delete($id);
else:
$rawResult = $this->primaryModel->where($this->primaryModel->getPrimaryKeyName(), $id)->delete();
endif;
else:
$datetime = (new \CodeIgniter\I18n\Time("now"));
$rawResult = $this->primaryModel->where('id',$id)
->set(['deleted_at' => $datetime->format('Y-m-d H:i:s')])
->update();
endif;
} catch (\Exception $e) {
log_message('error', "Exception: Error deleting object named '".(static::$singularObjectName ?? 'unknown')."' with $id :\r\n".$e->getMessage());
}
endif;
$ar = $this->primaryModel->db->affectedRows();
try {
$dbError = $this->primaryModel->db->error();
} catch (\Exception $e2) {
if ($e2->getMessage() != "Trying to get property 'errno' of non-object") {
log_message('error', $e2->getCode() . ' : ' . $e2->getMessage()) ;
}
}
if (isset($dbError['code']) && isset($dbError['message'])) {
log_message('error', $dbError['code'].' '.$dbError['message']);
} else {
$dbError = ['code' => '', 'message'=>''];
}
$result = ['persisted'=>$ar>0, 'ar'=>$ar, 'persistedId'=>null, 'affectedRows'=>$ar, 'errorCode'=>$dbError['code'], 'error'=>$dbError['message']];
$nameOfDeletedObject = static::$singularObjectNameCc;
if ($ar < 1) :
$errorMessage = lang('Basic.global.deleteError', [$nameOfDeletedObject]); // 'No ' . static::$singularObjectName . ' was deleted now, because it probably had already been deleted.';
$fdKey = isset($this->viewData['usingSweetAlert'] ) && $this->viewData['usingSweetAlert'] ? 'sweet-error' : 'errorMessage';
$errorMessage = str_replace("'", "\'", $errorMessage);
return $this->redirect2listView($fdKey, str_replace("'", '', $errorMessage));
else:
$message = lang('Basic.global.deleteSuccess', [$nameOfDeletedObject]); // 'The ' . static::$singularObjectName . ' was successfully deleted.';
$fdKey = isset($this->viewData['usingSweetAlert'] ) && $this->viewData['usingSweetAlert'] ? 'sweet-success' : 'successMessage';
if ($result['affectedRows']>1) :
log_message('warning', "More than one row has been deleted in attempt to delete row for object named '".(static::$singularObjectName ?? 'unknown')."' with id: $id");
endif;
$message = str_replace("'", "\'", $message);
return $this->redirect2listView($fdKey, $message);
endif;
}
}