summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-12-13 17:58:41 +0100
committermsquare <msquare@notrademark.de>2016-12-13 17:58:41 +0100
commitdeac80e700d69a56992fec70997a9d54716bdafa (patch)
tree47cf3f58b6158667a6b5af35b4eba5559dae9232
parente7767af4c1551dacbeb1ef22ab193e334826c81e (diff)
merge #253
-rw-r--r--db/update.sql11
-rw-r--r--includes/model/AngelType_model.php71
2 files changed, 76 insertions, 6 deletions
diff --git a/db/update.sql b/db/update.sql
index 5682f1ee..3e455e86 100644
--- a/db/update.sql
+++ b/db/update.sql
@@ -6,4 +6,13 @@ ALTER TABLE `UserAngelTypes` CHANGE `coordinator` `supporter` BOOLEAN;
ALTER TABLE `User` ADD COLUMN `email_by_human_allowed` BOOLEAN NOT NULL;
-- No Self Sign Up for some Angel Types
-ALTER TABLE engelsystem.AngelTypes ADD no_self_signup TINYINT(1) NOT NULL; \ No newline at end of file
+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;
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index dc26fce9..8d6a89b3 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -12,11 +12,63 @@ function AngelType_new() {
'restricted' => false,
'no_self_signup' => false,
'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.
*
* @param Angeltype $angeltype
@@ -46,7 +98,11 @@ function AngelType_update($angeltype) {
`restricted`=" . sql_bool($angeltype['restricted']) . ",
`description`='" . sql_escape($angeltype['description']) . "',
`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']) . "'");
if ($result === false) {
engelsystem_error("Unable to update angeltype.");
@@ -68,7 +124,12 @@ function AngelType_create($angeltype) {
`name`='" . sql_escape($angeltype['name']) . "',
`restricted`=" . sql_bool($angeltype['restricted']) . ",
`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) {
engelsystem_error("Unable to create angeltype.");
}
@@ -162,7 +223,7 @@ function AngelType_ids() {
* 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) {
engelsystem_error("Unable to load angeltype.");
}
@@ -172,4 +233,4 @@ function AngelType($angeltype_id) {
return null;
}
-?> \ No newline at end of file
+?>