diff options
author | msquare <msquare@notrademark.de> | 2016-09-29 16:04:05 +0200 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2016-09-29 16:04:05 +0200 |
commit | a128bcbb38a664bb2a07d0beb8bfb777e4b5da44 (patch) | |
tree | 83e82028409818efa165d6b2720a5ab2c040a8c4 | |
parent | 10ae8b3d5ccca647564929ef37ff59c2c14ecd96 (diff) |
use more ValidationResult
-rw-r--r-- | includes/controller/angeltypes_controller.php | 5 | ||||
-rw-r--r-- | includes/model/AngelType_model.php | 32 |
2 files changed, 17 insertions, 20 deletions
diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 92d1d8ee..5607ea7c 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -137,8 +137,9 @@ function angeltype_edit_controller() { if (! $coordinator_mode) { if (isset($_REQUEST['name'])) { - list($valid, $name) = AngelType_validate_name($_REQUEST['name'], $angeltype); - if (! $valid) { + $result = AngelType_validate_name($_REQUEST['name'], $angeltype); + $name = $result->getValue(); + if (! $result->isValid()) { $valid = false; error(_("Please check the name. Maybe it already exists.")); } diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php index 21ab3bf2..73b746f0 100644 --- a/includes/model/AngelType_model.php +++ b/includes/model/AngelType_model.php @@ -55,38 +55,34 @@ function AngelType_create($name, $restricted, $description, $requires_driver_lic /** * Validates a name for angeltypes. - * Returns array containing validation success and validated name. + * Returns ValidationResult containing validation success and validated name. * - * @param string $name - * @param AngelType $angeltype + * @param string $name + * Wanted name for the angeltype + * @param AngelType $angeltype + * The angeltype the name is for + * @return ValidationResult result and validated name */ function AngelType_validate_name($name, $angeltype) { $name = strip_item($name); if ($name == "") { - return [ - false, - $name - ]; + return new ValidationResult(false, ""); } - if (isset($angeltype) && isset($angeltype['id'])) { - return [ - sql_num_query(" + if ($angeltype != null && isset($angeltype['id'])) { + $valid = sql_num_query(" SELECT * FROM `AngelTypes` WHERE `name`='" . sql_escape($name) . "' AND NOT `id`='" . sql_escape($angeltype['id']) . "' - LIMIT 1") == 0, - $name - ]; + LIMIT 1") == 0; + return new ValidationResult($valid, $name); } - return [ - sql_num_query(" + $valid = sql_num_query(" SELECT `id` FROM `AngelTypes` WHERE `name`='" . sql_escape($name) . "' - LIMIT 1") == 0, - $name - ]; + LIMIT 1") == 0; + return new ValidationResult($valid, $name); } /** |