summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
authorFelix Favre <gnomus@gnomus.de>2014-12-07 18:04:03 +0100
committerFelix Favre <gnomus@gnomus.de>2014-12-07 18:04:03 +0100
commit5b3e5750ebd48993a58b38c657bb87e1e810d180 (patch)
tree848fd9c99eeb13027bf205c0850d0404ae0c58a1 /includes/model
parent09ef38ff351b6d3308022531ec3f79b5700f2731 (diff)
parentb75700ee1bf4bc07f1da7899aac864cb561022f4 (diff)
Merge branch 'master' of github.com:engelsystem/engelsystem
Conflicts: includes/model/ShiftEntry_model.php
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/ShiftEntry_model.php23
-rw-r--r--includes/model/Shifts_model.php63
2 files changed, 85 insertions, 1 deletions
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index e3046152..0cf5c040 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -7,9 +7,12 @@ function ShiftEntries_freeleaded_count() {
return sql_select_single_cell("SELECT COUNT(*) FROM `ShiftEntry` WHERE `freeloaded` = 1");
}
+/**
+ * List users subsribed to a given shift.
+ */
function ShiftEntries_by_shift($shift_id) {
return sql_select("
- SELECT `User`.`email`, `User`.`email_shiftinfo`, `User`.`Nick`, `User`.`Sprache`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
+ SELECT `User`.`Nick`, `User`.`email`, `User`.`email_shiftinfo`, `User`.`Sprache`, `ShiftEntry`.`UID`, `ShiftEntry`.`TID`, `ShiftEntry`.`SID`, `AngelTypes`.`name` as `angel_type_name`, `ShiftEntry`.`Comment`, `ShiftEntry`.`freeloaded`
FROM `ShiftEntry`
JOIN `User` ON `ShiftEntry`.`UID`=`User`.`UID`
JOIN `AngelTypes` ON `ShiftEntry`.`TID`=`AngelTypes`.`id`
@@ -32,6 +35,24 @@ function ShiftEntry_create($shift_entry) {
}
/**
+ * Update a shift entry.
+ */
+function ShiftEntry_update($shift_entry) {
+ return sql_query("UPDATE `ShiftEntry` SET
+ `Comment`='" . sql_escape($shift_entry['Comment']) . "',
+ `freeload_comment`='" . sql_escape($shift_entry['freeload_comment']) . "',
+ `freeloaded`=" . sql_escape($shift_entry['freeloaded'] ? 'TRUE' : 'FALSE') . "
+ WHERE `id`=" . sql_escape($shift_entry['id']));
+}
+
+/**
+ * Delete a shift entry.
+ */
+function ShiftEntry_delete($shift_entry_id) {
+ return sql_query("DELETE FROM `ShiftEntry` WHERE `id`=" . sql_escape($shift_entry_id));
+}
+
+/**
* Returns next (or current) shifts of given user.
*
* @param User $user
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index 5d0ec4a2..28f84c26 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -1,4 +1,67 @@
<?php
+
+/**
+ * Delete a shift by its external id.
+ */
+function Shift_delete_by_psid($shift_psid) {
+ return sql_query("DELETE FROM `Shifts` WHERE `PSID`=" . sql_escape($shift_psid));
+}
+
+/**
+ * Delete a shift.
+ */
+function Shift_delete($shift_id) {
+ return sql_query("DELETE FROM `Shifts` WHERE `SID`=" . sql_escape($shift_id));
+}
+
+/**
+ * Update a shift.
+ */
+function Shift_update($shift) {
+ return sql_query("UPDATE `Shifts` SET
+ `start`=" . sql_escape($shift['start']) . ",
+ `end`=" . sql_escape($shift['end']) . ",
+ `RID`=" . sql_escape($shift['RID']) . ",
+ `name`=" . sql_null($shift['name']) . ",
+ `URL`=" . sql_null($shift['URL']) . ",
+ `PSID`=" . sql_null($shift['PSID']) . "
+ WHERE `SID`=" . sql_escape($shift['SID']));
+}
+
+/**
+ * Update a shift by its external id.
+ */
+function Shift_update_by_psid($shift) {
+ return sql_query("UPDATE `Shifts` SET
+ `start`=" . sql_escape($shift['start']) . ",
+ `end`=" . sql_escape($shift['end']) . ",
+ `RID`=" . sql_escape($shift['RID']) . ",
+ `name`=" . sql_null($shift['name']) . ",
+ `URL`=" . sql_null($shift['URL']) . "
+ WHERE `PSID`=" . sql_escape($shift['PSID']));
+}
+
+/**
+ * Create a new shift.
+ *
+ * @return new shift id or false
+ */
+function Shift_create($shift) {
+ $result = sql_query("INSERT INTO `Shifts` SET
+ `start`=" . sql_escape($shift['start']) . ",
+ `end`=" . sql_escape($shift['end']) . ",
+ `RID`=" . sql_escape($shift['RID']) . ",
+ `name`=" . sql_null($shift['name']) . ",
+ `URL`=" . sql_null($shift['URL']) . ",
+ `PSID`=" . sql_null($shift['PSID']));
+ if ($result === false)
+ return false;
+ return sql_id();
+}
+
+/**
+ * Return users shifts.
+ */
function Shifts_by_user($user) {
return sql_select("
SELECT *