merge #253
This commit is contained in:
parent
e7767af4c1
commit
deac80e700
|
@ -7,3 +7,12 @@ ALTER TABLE `User` ADD COLUMN `email_by_human_allowed` BOOLEAN NOT NULL;
|
||||||
|
|
||||||
-- No Self Sign Up for some Angel Types
|
-- No Self Sign Up for some Angel Types
|
||||||
ALTER TABLE engelsystem.AngelTypes ADD no_self_signup TINYINT(1) NOT NULL;
|
ALTER TABLE engelsystem.AngelTypes ADD no_self_signup TINYINT(1) NOT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `AngelTypes`
|
||||||
|
ADD `contact_user_id` INT NULL,
|
||||||
|
ADD `contact_name` VARCHAR(250) NULL,
|
||||||
|
ADD `contact_dect` VARCHAR(5) NULL,
|
||||||
|
ADD `contact_email` VARCHAR(250) NULL,
|
||||||
|
ADD INDEX (`contact_user_id`);
|
||||||
|
ALTER TABLE `AngelTypes`
|
||||||
|
ADD FOREIGN KEY (`contact_user_id`) REFERENCES `User`(`UID`) ON DELETE SET NULL ON UPDATE CASCADE;
|
||||||
|
|
|
@ -12,10 +12,62 @@ function AngelType_new() {
|
||||||
'restricted' => false,
|
'restricted' => false,
|
||||||
'no_self_signup' => false,
|
'no_self_signup' => false,
|
||||||
'description' => '',
|
'description' => '',
|
||||||
'requires_driver_license' => false
|
'requires_driver_license' => false,
|
||||||
|
'contact_user_id' => null,
|
||||||
|
'contact_name' => null,
|
||||||
|
'contact_dect' => null,
|
||||||
|
'contact_email' => null
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the contact user
|
||||||
|
*
|
||||||
|
* @param Angeltype $angeltype
|
||||||
|
* The angeltype
|
||||||
|
* @return ValidationResult
|
||||||
|
*/
|
||||||
|
function AngelType_validate_contact_user_id($angeltype) {
|
||||||
|
if (! isset($angeltype['contact_user_id'])) {
|
||||||
|
return new ValidationResult(true, null);
|
||||||
|
}
|
||||||
|
if (isset($angeltype['contact_name']) || isset($angeltype['contact_dect']) || isset($angeltype['contact_email'])) {
|
||||||
|
return new ValidationResult(false, $angeltype['contact_user_id']);
|
||||||
|
}
|
||||||
|
if (User($angeltype['contact_user_id']) == null) {
|
||||||
|
return new ValidationResult(false, $angeltype['contact_user_id']);
|
||||||
|
}
|
||||||
|
return new ValidationResult(true, $angeltype['contact_user_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns contact data (name, dect, email) for given angeltype or null
|
||||||
|
*
|
||||||
|
* @param Angeltype $angeltype
|
||||||
|
* The angeltype
|
||||||
|
*/
|
||||||
|
function AngelType_contact_info($angeltype) {
|
||||||
|
if (isset($angeltype['contact_user_id'])) {
|
||||||
|
$contact_user = User($angeltype['contact_user_id']);
|
||||||
|
$contact_data = [
|
||||||
|
'contact_name' => $contact_user['Nick'],
|
||||||
|
'contact_dect' => $contact_user['DECT']
|
||||||
|
];
|
||||||
|
if ($contact_user['email_by_human_allowed']) {
|
||||||
|
$contact_data['contact_email'] = $contact_user['email'];
|
||||||
|
}
|
||||||
|
return $contact_data;
|
||||||
|
}
|
||||||
|
if (isset($angeltype['contact_name'])) {
|
||||||
|
return [
|
||||||
|
'contact_name' => $angeltype['contact_name'],
|
||||||
|
'contact_dect' => $angeltype['contact_dect'],
|
||||||
|
'contact_email' => $angeltype['contact_email']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an Angeltype.
|
* Delete an Angeltype.
|
||||||
*
|
*
|
||||||
|
@ -46,7 +98,11 @@ function AngelType_update($angeltype) {
|
||||||
`restricted`=" . sql_bool($angeltype['restricted']) . ",
|
`restricted`=" . sql_bool($angeltype['restricted']) . ",
|
||||||
`description`='" . sql_escape($angeltype['description']) . "',
|
`description`='" . sql_escape($angeltype['description']) . "',
|
||||||
`requires_driver_license`=" . sql_bool($angeltype['requires_driver_license']) . ",
|
`requires_driver_license`=" . sql_bool($angeltype['requires_driver_license']) . ",
|
||||||
`no_self_signup`=" . sql_bool($angeltype['no_self_signup']) . "
|
`no_self_signup`=" . sql_bool($angeltype['no_self_signup']) . ",
|
||||||
|
`contact_user_id`=" . sql_null($angeltype['contact_user_id']) . ",
|
||||||
|
`contact_name`=" . sql_null($angeltype['contact_name']) . ",
|
||||||
|
`contact_dect`=" . sql_null($angeltype['contact_dect']) . ",
|
||||||
|
`contact_email`=" . sql_null($angeltype['contact_email']) . "
|
||||||
WHERE `id`='" . sql_escape($angeltype['id']) . "'");
|
WHERE `id`='" . sql_escape($angeltype['id']) . "'");
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
engelsystem_error("Unable to update angeltype.");
|
engelsystem_error("Unable to update angeltype.");
|
||||||
|
@ -68,7 +124,12 @@ function AngelType_create($angeltype) {
|
||||||
`name`='" . sql_escape($angeltype['name']) . "',
|
`name`='" . sql_escape($angeltype['name']) . "',
|
||||||
`restricted`=" . sql_bool($angeltype['restricted']) . ",
|
`restricted`=" . sql_bool($angeltype['restricted']) . ",
|
||||||
`description`='" . sql_escape($angeltype['description']) . "',
|
`description`='" . sql_escape($angeltype['description']) . "',
|
||||||
`requires_driver_license`=" . sql_bool($angeltype['requires_driver_license']));
|
`requires_driver_license`=" . sql_bool($angeltype['requires_driver_license']) . ",
|
||||||
|
`no_self_signup`=" . sql_bool($angeltype['no_self_signup']) . ",
|
||||||
|
`contact_user_id`=" . sql_null($angeltype['contact_user_id']) . ",
|
||||||
|
`contact_name`=" . sql_null($angeltype['contact_name']) . ",
|
||||||
|
`contact_dect`=" . sql_null($angeltype['contact_dect']) . ",
|
||||||
|
`contact_email`=" . sql_null($angeltype['contact_email']));
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
engelsystem_error("Unable to create angeltype.");
|
engelsystem_error("Unable to create angeltype.");
|
||||||
}
|
}
|
||||||
|
@ -162,7 +223,7 @@ function AngelType_ids() {
|
||||||
* ID
|
* ID
|
||||||
*/
|
*/
|
||||||
function AngelType($angeltype_id) {
|
function AngelType($angeltype_id) {
|
||||||
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "' LIMIT 1");
|
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($angeltype_id) . "'");
|
||||||
if ($angelType_source === false) {
|
if ($angelType_source === false) {
|
||||||
engelsystem_error("Unable to load angeltype.");
|
engelsystem_error("Unable to load angeltype.");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue