summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2016-09-29 11:18:17 +0200
committermsquare <msquare@notrademark.de>2016-09-29 11:18:17 +0200
commite965f8d04150fbd17ee1b5fcbca5ae85bbe6d6bd (patch)
treef610d047f1cdc830ffc34881f6ea6d26ef0e3983 /includes/model
parent91dafb19ec171e747d9976cf738606759bde3aae (diff)
prohibit inline control structures on model and view
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/AngelType_model.php38
-rw-r--r--includes/model/EventConfig_model.php6
-rw-r--r--includes/model/Message_model.php10
-rw-r--r--includes/model/NeededAngelTypes_model.php15
-rw-r--r--includes/model/Room_model.php9
-rw-r--r--includes/model/ShiftEntry_model.php10
-rw-r--r--includes/model/ShiftTypes_model.php9
-rw-r--r--includes/model/Shifts_model.php60
-rw-r--r--includes/model/UserAngelTypes_model.php15
-rw-r--r--includes/model/UserDriverLicenses_model.php6
-rw-r--r--includes/model/User_model.php60
11 files changed, 147 insertions, 91 deletions
diff --git a/includes/model/AngelType_model.php b/includes/model/AngelType_model.php
index e4aef450..47c13667 100644
--- a/includes/model/AngelType_model.php
+++ b/includes/model/AngelType_model.php
@@ -47,8 +47,9 @@ function AngelType_create($name, $restricted, $description, $requires_driver_lic
`restricted`=" . sql_bool($restricted) . ",
`description`='" . sql_escape($description) . "',
`requires_driver_license`=" . sql_bool($requires_driver_license));
- if ($result === false)
+ if ($result === false) {
return false;
+ }
return sql_id();
}
@@ -61,13 +62,14 @@ function AngelType_create($name, $restricted, $description, $requires_driver_lic
*/
function AngelType_validate_name($name, $angeltype) {
$name = strip_item($name);
- if ($name == "")
- return array(
+ if ($name == "") {
+ return [
false,
$name
- );
- if (isset($angeltype) && isset($angeltype['id']))
- return array(
+ ];
+ }
+ if (isset($angeltype) && isset($angeltype['id'])) {
+ return [
sql_num_query("
SELECT *
FROM `AngelTypes`
@@ -75,16 +77,16 @@ function AngelType_validate_name($name, $angeltype) {
AND NOT `id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1") == 0,
$name
- );
- else
- return array(
- sql_num_query("
+ ];
+ }
+ return [
+ sql_num_query("
SELECT `id`
FROM `AngelTypes`
WHERE `name`='" . sql_escape($name) . "'
LIMIT 1") == 0,
- $name
- );
+ $name
+ ];
}
/**
@@ -119,10 +121,12 @@ function AngelTypes() {
*/
function AngelType_ids() {
$angelType_source = sql_select("SELECT `id` FROM `AngelTypes`");
- if ($angelType_source === false)
+ if ($angelType_source === false) {
return false;
- if (count($angelType_source) > 0)
+ }
+ if (count($angelType_source) > 0) {
return $angelType_source;
+ }
return null;
}
@@ -134,10 +138,12 @@ function AngelType_ids() {
*/
function AngelType($id) {
$angelType_source = sql_select("SELECT * FROM `AngelTypes` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
- if ($angelType_source === false)
+ if ($angelType_source === false) {
return false;
- if (count($angelType_source) > 0)
+ }
+ if (count($angelType_source) > 0) {
return $angelType_source[0];
+ }
return null;
}
diff --git a/includes/model/EventConfig_model.php b/includes/model/EventConfig_model.php
index 0529c286..ac8d5e72 100644
--- a/includes/model/EventConfig_model.php
+++ b/includes/model/EventConfig_model.php
@@ -5,10 +5,12 @@
*/
function EventConfig() {
$event_config = sql_select("SELECT * FROM `EventConfig` LIMIT 1");
- if ($event_config === false)
+ if ($event_config === false) {
return false;
- if (count($event_config) > 0)
+ }
+ if (count($event_config) > 0) {
return $event_config[0];
+ }
return null;
}
diff --git a/includes/model/Message_model.php b/includes/model/Message_model.php
index 7bae0dd4..92b76a80 100644
--- a/includes/model/Message_model.php
+++ b/includes/model/Message_model.php
@@ -1,7 +1,7 @@
<?php
-/**
- * Returns Message id array
+/**
+ * Returns Message id array
*/
function Message_ids() {
return sql_select("SELECT `id` FROM `Messages`");
@@ -15,10 +15,12 @@ function Message_ids() {
*/
function Message($id) {
$message_source = sql_select("SELECT * FROM `Messages` WHERE `id`='" . sql_escape($id) . "' LIMIT 1");
- if ($message_source === false)
+ if ($message_source === false) {
return false;
- if (count($message_source) > 0)
+ }
+ if (count($message_source) > 0) {
return $message_source[0];
+ }
return null;
}
diff --git a/includes/model/NeededAngelTypes_model.php b/includes/model/NeededAngelTypes_model.php
index 8d6b8cce..96ceca83 100644
--- a/includes/model/NeededAngelTypes_model.php
+++ b/includes/model/NeededAngelTypes_model.php
@@ -14,10 +14,11 @@ function NeededAngelTypes_by_shift($shiftId) {
AND `count` > 0
ORDER BY `room_id` DESC
");
- if ($needed_angeltypes_source === false)
+ if ($needed_angeltypes_source === false) {
return false;
-
- // Use settings from room
+ }
+
+ // Use settings from room
if (count($needed_angeltypes_source) == 0) {
$needed_angeltypes_source = sql_select("
SELECT `NeededAngelTypes`.*, `AngelTypes`.`name`, `AngelTypes`.`restricted`
@@ -28,15 +29,17 @@ function NeededAngelTypes_by_shift($shiftId) {
AND `count` > 0
ORDER BY `room_id` DESC
");
- if ($needed_angeltypes_source === false)
+ if ($needed_angeltypes_source === false) {
return false;
+ }
}
- $needed_angeltypes = array();
+ $needed_angeltypes = [];
foreach ($needed_angeltypes_source as $angeltype) {
$shift_entries = ShiftEntries_by_shift_and_angeltype($shiftId, $angeltype['angel_type_id']);
- if ($shift_entries === false)
+ if ($shift_entries === false) {
return false;
+ }
$angeltype['taken'] = count($shift_entries);
$needed_angeltypes[] = $angeltype;
diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php
index 6d8a205e..1768b61b 100644
--- a/includes/model/Room_model.php
+++ b/includes/model/Room_model.php
@@ -25,8 +25,9 @@ function Room_create($name, $from_frab, $public) {
`FromPentabarf`='" . sql_escape($from_frab ? 'Y' : '') . "',
`show`='" . sql_escape($public ? 'Y' : '') . "',
`Number`=0");
- if ($result === false)
+ if ($result === false) {
return false;
+ }
return sql_id();
}
@@ -38,10 +39,12 @@ function Room_create($name, $from_frab, $public) {
function Room($id) {
$room_source = sql_select("SELECT * FROM `Room` WHERE `RID`='" . sql_escape($id) . "' AND `show` = 'Y'");
- if ($room_source === false)
+ if ($room_source === false) {
return false;
- if (count($room_source) > 0)
+ }
+ if (count($room_source) > 0) {
return $room_source[0];
+ }
return null;
}
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 6324c3bf..425b92e8 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -51,10 +51,12 @@ function ShiftEntry_update($shift_entry) {
*/
function ShiftEntry($shift_entry_id) {
$shift_entry = sql_select("SELECT * FROM `ShiftEntry` WHERE `id`='" . sql_escape($shift_entry_id) . "'");
- if ($shift_entry === false)
+ if ($shift_entry === false) {
return false;
- if (count($shift_entry) == 0)
+ }
+ if (count($shift_entry) == 0) {
return null;
+ }
return $shift_entry[0];
}
@@ -89,8 +91,8 @@ function ShiftEntries_upcoming_for_user($user) {
*
* @param User $user
*/
-function ShiftEntries_finished_by_user($user){
- return sql_select("
+function ShiftEntries_finished_by_user($user) {
+ return sql_select("
SELECT *
FROM `ShiftEntry`
JOIN `Shifts` ON (`Shifts`.`SID` = `ShiftEntry`.`SID`)
diff --git a/includes/model/ShiftTypes_model.php b/includes/model/ShiftTypes_model.php
index 7f057da8..a9cf77bd 100644
--- a/includes/model/ShiftTypes_model.php
+++ b/includes/model/ShiftTypes_model.php
@@ -37,8 +37,9 @@ function ShiftType_create($name, $angeltype_id, $description) {
`name`='" . sql_escape($name) . "',
`angeltype_id`=" . sql_null($angeltype_id) . ",
`description`='" . sql_escape($description) . "'");
- if ($result === false)
+ if ($result === false) {
return false;
+ }
return sql_id();
}
@@ -49,10 +50,12 @@ function ShiftType_create($name, $angeltype_id, $description) {
*/
function ShiftType($shifttype_id) {
$shifttype = sql_select("SELECT * FROM `ShiftTypes` WHERE `id`='" . sql_escape($shifttype_id) . "'");
- if ($shifttype === false)
+ if ($shifttype === false) {
return false;
- if ($shifttype == null)
+ }
+ if ($shifttype == null) {
return null;
+ }
return $shifttype[0];
}
diff --git a/includes/model/Shifts_model.php b/includes/model/Shifts_model.php
index d32de0cb..cca5139d 100644
--- a/includes/model/Shifts_model.php
+++ b/includes/model/Shifts_model.php
@@ -6,10 +6,13 @@
* @param array<Shift> $shifts
*/
function Shift_collides($shift, $shifts) {
- foreach ($shifts as $other_shift)
- if ($shift['SID'] != $other_shift['SID'])
- if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start']))
+ foreach ($shifts as $other_shift) {
+ if ($shift['SID'] != $other_shift['SID']) {
+ if (! ($shift['start'] >= $other_shift['end'] || $shift['end'] <= $other_shift['start'])) {
return true;
+ }
+ }
+ }
return false;
}
@@ -25,41 +28,46 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
if ($user_shifts == null) {
$user_shifts = Shifts_by_user($user);
- if ($user_shifts === false)
+ if ($user_shifts === false) {
engelsystem_error('Unable to load users shifts.');
+ }
}
$collides = Shift_collides($shift, $user_shifts);
if ($user_angeltype == null) {
$user_angeltype = UserAngelType_by_User_and_AngelType($user, $angeltype);
- if ($user_angeltype === false)
+ if ($user_angeltype === false) {
engelsystem_error('Unable to load user angeltype.');
+ }
}
$signed_up = false;
- foreach ($user_shifts as $user_shift)
+ foreach ($user_shifts as $user_shift) {
if ($user_shift['SID'] == $shift['SID']) {
$signed_up = true;
break;
}
+ }
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
- if ($needed_angeltypes === false)
+ if ($needed_angeltypes === false) {
engelsystem_error('Unable to load needed angel types.');
-
- // is the shift still running or alternatively is the user shift admin?
+ }
+
+ // is the shift still running or alternatively is the user shift admin?
$user_may_join_shift = true;
// you canot join if shift is full
- foreach ($needed_angeltypes as $needed_angeltype)
+ foreach ($needed_angeltypes as $needed_angeltype) {
if ($needed_angeltype['angel_type_id'] == $angeltype['id']) {
if ($needed_angeltype['taken'] >= $needed_angeltype['count'])
$user_may_join_shift = false;
break;
}
-
- // you cannot join if user alread joined a parallel or this shift
+ }
+
+ // you cannot join if user alread joined a parallel or this shift
$user_may_join_shift &= ! $collides;
// you cannot join if you already singed up for this shift
@@ -69,10 +77,11 @@ function Shift_signup_allowed($shift, $angeltype, $user_angeltype = null, $user_
$user_may_join_shift &= $user_angeltype != null;
// you cannot join if you are not confirmed
- if ($angeltype['restricted'] == 1 && $user_angeltype != null)
+ if ($angeltype['restricted'] == 1 && $user_angeltype != null) {
$user_may_join_shift &= isset($user_angeltype['confirm_user_id']);
-
- // you can only join if the shift is in future
+ }
+
+ // you can only join if the shift is in future
$user_may_join_shift &= time() < $shift['start'];
// User shift admins may join anybody in every shift
@@ -123,10 +132,12 @@ function Shift_update($shift) {
*/
function Shift_update_by_psid($shift) {
$shift_source = sql_select("SELECT `SID` FROM `Shifts` WHERE `PSID`=" . $shift['PSID']);
- if ($shift_source === false)
+ if ($shift_source === false) {
return false;
- if (count($shift_source) == 0)
+ }
+ if (count($shift_source) == 0) {
return null;
+ }
$shift['SID'] = $shift_source[0]['SID'];
return Shift_update($shift);
}
@@ -148,8 +159,9 @@ function Shift_create($shift) {
`PSID`=" . sql_null($shift['PSID']) . ",
`created_by_user_id`='" . sql_escape($user['UID']) . "',
`created_at_timestamp`=" . time());
- if ($result === false)
+ if ($result === false) {
return false;
+ }
return sql_id();
}
@@ -205,8 +217,9 @@ function Shifts_filtered() {
// real request
$shifts_source = sql_select("SELECT `SID` FROM `Shifts`" . $filter);
- if ($shifts_source === false)
+ if ($shifts_source === false) {
return false;
+ }
if (count($shifts_source) > 0) {
return $shifts_source;
}
@@ -227,8 +240,9 @@ function Shift($id) {
WHERE `SID`='" . sql_escape($id) . "'");
$shiftsEntry_source = sql_select("SELECT `id`, `TID` , `UID` , `freeloaded` FROM `ShiftEntry` WHERE `SID`='" . sql_escape($id) . "'");
- if ($shifts_source === false)
+ if ($shifts_source === false) {
return false;
+ }
if (count($shifts_source) > 0) {
$result = $shifts_source[0];
@@ -260,13 +274,15 @@ function Shifts() {
JOIN `ShiftTypes` ON (`ShiftTypes`.`id` = `Shifts`.`shifttype_id`)
JOIN `Room` ON `Room`.`RID` = `Shifts`.`RID`
");
- if ($shifts_source === false)
+ if ($shifts_source === false) {
return false;
+ }
foreach ($shifts_source as &$shift) {
$needed_angeltypes = NeededAngelTypes_by_shift($shift['SID']);
- if ($needed_angeltypes === false)
+ if ($needed_angeltypes === false) {
return false;
+ }
$shift['angeltypes'] = $needed_angeltypes;
}
diff --git a/includes/model/UserAngelTypes_model.php b/includes/model/UserAngelTypes_model.php
index f942483e..d3538f09 100644
--- a/includes/model/UserAngelTypes_model.php
+++ b/includes/model/UserAngelTypes_model.php
@@ -133,8 +133,9 @@ function UserAngelType_create($user, $angeltype) {
INSERT INTO `UserAngelTypes` SET
`user_id`='" . sql_escape($user['UID']) . "',
`angeltype_id`='" . sql_escape($angeltype['id']) . "'");
- if ($result === false)
+ if ($result === false) {
return false;
+ }
return sql_id();
}
@@ -149,10 +150,12 @@ function UserAngelType($user_angeltype_id) {
FROM `UserAngelTypes`
WHERE `id`='" . sql_escape($user_angeltype_id) . "'
LIMIT 1");
- if ($angeltype === false)
+ if ($angeltype === false) {
return false;
- if (count($angeltype) == 0)
+ }
+ if (count($angeltype) == 0) {
return null;
+ }
return $angeltype[0];
}
@@ -169,10 +172,12 @@ function UserAngelType_by_User_and_AngelType($user, $angeltype) {
WHERE `user_id`='" . sql_escape($user['UID']) . "'
AND `angeltype_id`='" . sql_escape($angeltype['id']) . "'
LIMIT 1");
- if ($angeltype === false)
+ if ($angeltype === false) {
return false;
- if (count($angeltype) == 0)
+ }
+ if (count($angeltype) == 0) {
return null;
+ }
return $angeltype[0];
}
?> \ No newline at end of file
diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php
index b99c8b1b..19f87e63 100644
--- a/includes/model/UserDriverLicenses_model.php
+++ b/includes/model/UserDriverLicenses_model.php
@@ -6,10 +6,12 @@
*/
function UserDriverLicense($user_id) {
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
- if ($user_driver_license === false)
+ if ($user_driver_license === false) {
return false;
- if (count($user_driver_license) > 0)
+ }
+ if (count($user_driver_license) > 0) {
return $user_driver_license[0];
+ }
return null;
}
diff --git a/includes/model/User_model.php b/includes/model/User_model.php
index 00c3bfdd..3d5416da 100644
--- a/includes/model/User_model.php
+++ b/includes/model/User_model.php
@@ -6,7 +6,7 @@
/**
* Delete a user
- *
+ *
* @param int $user_id
*/
function User_delete($user_id) {
@@ -164,10 +164,12 @@ function User_validate_Nick($nick) {
*/
function User($id) {
$user_source = sql_select("SELECT * FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
- if ($user_source === false)
+ if ($user_source === false) {
return false;
- if (count($user_source) > 0)
+ }
+ if (count($user_source) > 0) {
return $user_source[0];
+ }
return null;
}
@@ -179,10 +181,12 @@ function User($id) {
*/
function mUser_Limit($id) {
$user_source = sql_select("SELECT `UID`, `Nick`, `Name`, `Vorname`, `Telefon`, `DECT`, `Handy`, `email`, `jabber` FROM `User` WHERE `UID`='" . sql_escape($id) . "' LIMIT 1");
- if ($user_source === false)
+ if ($user_source === false) {
return false;
- if (count($user_source) > 0)
+ }
+ if (count($user_source) > 0) {
return $user_source[0];
+ }
return null;
}
@@ -195,10 +199,12 @@ function mUser_Limit($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)
+ if ($user === false) {
return false;
- if (count($user) == 0)
+ }
+ if (count($user) == 0) {
return null;
+ }
return $user[0];
}
@@ -210,10 +216,12 @@ function User_by_api_key($api_key) {
*/
function User_by_email($email) {
$user = sql_select("SELECT * FROM `User` WHERE `email`='" . sql_escape($email) . "' LIMIT 1");
- if ($user === false)
+ if ($user === false) {
return false;
- if (count($user) == 0)
+ }
+ if (count($user) == 0) {
return null;
+ }
return $user[0];
}
@@ -225,10 +233,12 @@ function User_by_email($email) {
*/
function User_by_password_recovery_token($token) {
$user = sql_select("SELECT * FROM `User` WHERE `password_recovery_token`='" . sql_escape($token) . "' LIMIT 1");
- if ($user === false)
+ if ($user === false) {
return false;
- if (count($user) == 0)
+ }
+ if (count($user) == 0) {
return null;
+ }
return $user[0];
}
@@ -240,10 +250,12 @@ function User_by_password_recovery_token($token) {
function User_reset_api_key(&$user, $log = true) {
$user['api_key'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `api_key`='" . sql_escape($user['api_key']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
- if ($result === false)
+ if ($result === false) {
return false;
- if ($log)
+ }
+ if ($log) {
engelsystem_log(sprintf("API key resetted (%s).", User_Nick_render($user)));
+ }
}
/**
@@ -254,25 +266,25 @@ function User_reset_api_key(&$user, $log = true) {
function User_generate_password_recovery_token(&$user) {
$user['password_recovery_token'] = md5($user['Nick'] . time() . rand());
$result = sql_query("UPDATE `User` SET `password_recovery_token`='" . sql_escape($user['password_recovery_token']) . "' WHERE `UID`='" . sql_escape($user['UID']) . "' LIMIT 1");
- if ($result === false)
+ if ($result === false) {
return false;
+ }
engelsystem_log("Password recovery for " . User_Nick_render($user) . " started.");
return $user['password_recovery_token'];
}
-
function User_get_eligable_voucher_count(&$user) {
global $voucher_settings;
- $shifts_done = count(ShiftEntries_finished_by_user($user));
-
- $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
- $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
- if ( $elegible_vouchers < 0) {
- return 0;
- }
-
- return $elegible_vouchers;
+ $shifts_done = count(ShiftEntries_finished_by_user($user));
+
+ $earned_vouchers = $user['got_voucher'] - $voucher_settings['initial_vouchers'];
+ $elegible_vouchers = $shifts_done / $voucher_settings['shifts_per_voucher'] - $earned_vouchers;
+ if ($elegible_vouchers < 0) {
+ return 0;
+ }
+
+ return $elegible_vouchers;
}
?>