summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/AngelType_model.php1
-rw-r--r--includes/model/ShiftEntry_model.php1
-rw-r--r--includes/model/Shifts_model.php7
-rw-r--r--includes/model/User_model.php20
-rw-r--r--includes/model/ValidationResult.php42
5 files changed, 51 insertions, 20 deletions
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index 2ccba2ea..dc26fce9 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -1,4 +1,5 @@
<?php
+use Engelsystem\ValidationResult;
/**
* Returns an array containing the basic attributes of angeltypes.
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 99f67028..dca7e1c1 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -115,6 +115,7 @@ function ShiftEntries_finished_by_user($user) {
JOIN `ShiftTypes` ON `ShiftTypes`.`id` = `Shifts`.`shifttype_id`
WHERE `ShiftEntry`.`UID`=" . sql_escape($user['UID']) . "
AND `Shifts`.`end` < " . sql_escape(time()) . "
+ AND `ShiftEntry`.`freeloaded` = 0
ORDER BY `Shifts`.`end`
");
}
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 6a29c540..1e1bd97d 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -263,9 +263,12 @@ function Shift_create($shift) {
/**
* Return users shifts.
*/
-function Shifts_by_user($user) {
+function Shifts_by_user($user, $include_freeload_comments = false) {
$result = sql_select("
- SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`, `ShiftEntry`.*, `Shifts`.*, `Room`.*
+ SELECT `ShiftTypes`.`id` as `shifttype_id`, `ShiftTypes`.`name`,
+ `ShiftEntry`.`id`, `ShiftEntry`.`SID`, `ShiftEntry`.`TID`, `ShiftEntry`.`UID`, `ShiftEntry`.`freeloaded`, `ShiftEntry`.`Comment`,
+ " . ($include_freeload_comments ? "`ShiftEntry`.`freeload_comment`, " : "") . "
+ `Shifts`.*, `Room`.*
FROM `ShiftEntry`
JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID`)
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index c1376abd..3ebd3bf9 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -1,4 +1,5 @@
<?php
+use Engelsystem\ValidationResult;
/**
* User model
@@ -274,23 +275,6 @@ function User($user_id) {
}
/**
- * TODO: Merge into normal user function
- * Returns user by id (limit informations.
- *
- * @param $user_id UID
- */
-function mUser_Limit($user_id) {
- $user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber` FROM `User` WHERE `UID`='" . sql_escape($user_id) . "' LIMIT 1");
- if ($user_source === false) {
- return false;
- }
- if (count($user_source) > 0) {
- return $user_source[0];
- }
- return null;
-}
-
-/**
* Returns User by api_key.
*
* @param string $api_key
@@ -300,7 +284,7 @@ function mUser_Limit($user_id) {
function User_by_api_key($api_key) {
$user = sql_select("SELECT * FROM `User` WHERE `api_key`='" . sql_escape($api_key) . "' LIMIT 1");
if ($user === false) {
- return false;
+ engelsystem_error("Unable to find user by api key.");
}
if (count($user) == 0) {
return null;
diff --git a/includes/model/ValidationResult.php b/includes/model/ValidationResult.php
new file mode 100644
index 00000000..0fc24161
--- /dev/null
+++ b/includes/model/ValidationResult.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Engelsystem;
+
+/**
+ * BO that represents the result of an entity attribute validation.
+ * It contains the validated value and a bool for validation success.
+ */
+class ValidationResult {
+
+ private $valid;
+
+ private $value;
+
+ /**
+ * Constructor.
+ *
+ * @param boolean $valid
+ * Is the value valid?
+ * @param * $value
+ * The validated value
+ */
+ public function __construct($valid, $value) {
+ $this->valid = $valid;
+ $this->value = $value;
+ }
+
+ /**
+ * Is the value valid?
+ */
+ public function isValid() {
+ return $this->valid;
+ }
+
+ /**
+ * The parsed/validated value.
+ */
+ public function getValue() {
+ return $this->value;
+ }
+}
+?> \ No newline at end of file