add validation "is_in_db"

This commit is contained in:
chfhtw
2025-09-02 16:04:02 +02:00
parent edce5716fd
commit b378649b06
2 changed files with 29 additions and 0 deletions
+28
View File
@@ -515,3 +515,31 @@ function has_permissions_for_stg($studiengang_kz, $permissions = '')
return false;
}
/**
* check if an entry exists in the database
*/
function is_in_db($key, $model = '')
{
if (!$model)
return false;
$field = strstr($model, ":");
if ($field) {
$model = strstr($model, ":", true);
$field = substr($field, 1);
}
$CI =& get_instance();
$CI->load->model($model, $model);
if ($field) {
$result = $CI->$model->loadWhere([
$field => $key
]);
} else {
$result = $CI->$model->load($key);
}
return (isSuccess($result) && hasData($result));
}
@@ -41,3 +41,4 @@ if (!defined('BASEPATH')) exit('No direct script access allowed');
$lang['form_validation_has_write_permissions'] = 'You have no rights to edit {field} field.';
$lang['form_validation_is_valid_date'] = 'The date format is invalid or out of range.';
$lang['form_validation_has_permissions_for_stg'] = 'You have no rights for stg {field}.';
$lang['form_validation_is_in_db'] = '{field} does not exist.';