diff --git a/application/helpers/hlp_common_helper.php b/application/helpers/hlp_common_helper.php index 00c0a1b93..edbde5272 100644 --- a/application/helpers/hlp_common_helper.php +++ b/application/helpers/hlp_common_helper.php @@ -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)); +} diff --git a/application/language/english/form_validation_lang.php b/application/language/english/form_validation_lang.php index b8918a721..2777cd05e 100644 --- a/application/language/english/form_validation_lang.php +++ b/application/language/english/form_validation_lang.php @@ -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.';