summaryrefslogtreecommitdiff
path: root/includes/model
diff options
context:
space:
mode:
Diffstat (limited to 'includes/model')
-rw-r--r--includes/model/ShiftEntry_model.php16
-rw-r--r--includes/model/UserDriverLicenses_model.php81
2 files changed, 66 insertions, 31 deletions
diff --git a/includes/model/ShiftEntry_model.php b/includes/model/ShiftEntry_model.php
index 63127bc7..99f67028 100644
--- a/includes/model/ShiftEntry_model.php
+++ b/includes/model/ShiftEntry_model.php
@@ -1,6 +1,22 @@
<?php
/**
+ * Returns an array with the attributes of shift entries.
+ * FIXME! Needs entity object.
+ */
+function ShiftEntry_new() {
+ return [
+ 'id' => null,
+ 'SID' => null,
+ 'TID' => null,
+ 'UID' => null,
+ 'Comment' => null,
+ 'freeloaded_comment' => null,
+ 'freeloaded' => false
+ ];
+}
+
+/**
* Counts all freeloaded shifts.
*/
function ShiftEntries_freeleaded_count() {
diff --git a/includes/model/UserDriverLicenses_model.php b/includes/model/UserDriverLicenses_model.php
index 32785c92..6a3f14ab 100644
--- a/includes/model/UserDriverLicenses_model.php
+++ b/includes/model/UserDriverLicenses_model.php
@@ -1,8 +1,37 @@
<?php
/**
+ * Returns a new empty UserDriverLicense
+ * FIXME entity object needed
+ */
+function UserDriverLicense_new($user) {
+ return [
+ 'user_id' => $user['UID'],
+ 'has_car' => false,
+ 'has_license_car' => false,
+ 'has_license_3_5t_transporter' => false,
+ 'has_license_7_5t_truck' => false,
+ 'has_license_12_5t_truck' => false,
+ 'has_license_forklift' => false
+ ];
+}
+
+/**
+ * Is it valid?
+ *
+ * @param UserDriverLicense $user_driver_license
+ * The UserDriverLicense to check
+ * @return boolean
+ */
+function UserDriverLicense_valid($user_driver_license) {
+ return $user_driver_license['has_car'] || $user_driver_license['has_license_car'] || $user_driver_license['has_license_3_5t_transporter'] || $user_driver_license['has_license_7_5t_truck'] || $user_driver_license['has_license_12_5t_truck'] || $user_driver_license['has_license_forklift'];
+}
+
+/**
* Get a users driver license information
- * @param int $user_id The users id
+ *
+ * @param int $user_id
+ * The users id
*/
function UserDriverLicense($user_id) {
$user_driver_license = sql_select("SELECT * FROM `UserDriverLicenses` WHERE `user_id`='" . sql_escape($user_id) . "'");
@@ -19,24 +48,19 @@ function UserDriverLicense($user_id) {
/**
* Create a user's driver license entry
*
- * @param bool $user_id
- * @param bool $has_car
- * @param bool $has_license_car
- * @param bool $has_license_3_5t_transporter
- * @param bool $has_license_7_5t_truck
- * @param bool $has_license_12_5t_truck
- * @param bool $has_license_forklift
+ * @param UserDriverLicense $user_driver_license
+ * The UserDriverLicense to create
*/
-function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
+function UserDriverLicenses_create($user_driver_license) {
$result = sql_query("
INSERT INTO `UserDriverLicenses` SET
- `user_id`=" . sql_escape($user_id) . ",
- `has_car`=" . sql_bool($has_car) . ",
- `has_license_car`=" . sql_bool($has_license_car) . ",
- `has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ",
- `has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ",
- `has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ",
- `has_license_forklift`=" . sql_bool($has_license_forklift));
+ `user_id`=" . sql_escape($user_driver_license['user_id']) . ",
+ `has_car`=" . sql_bool($user_driver_license['has_car']) . ",
+ `has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
+ `has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
+ `has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
+ `has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
+ `has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']));
if ($result === false) {
engelsystem_error('Unable to create user driver license');
}
@@ -46,23 +70,18 @@ function UserDriverLicenses_create($user_id, $has_car, $has_license_car, $has_li
/**
* Update a user's driver license entry
*
- * @param bool $user_id
- * @param bool $has_car
- * @param bool $has_license_car
- * @param bool $has_license_3_5t_transporter
- * @param bool $has_license_7_5t_truck
- * @param bool $has_license_12_5t_truck
- * @param bool $has_license_forklift
+ * @param UserDriverLicense $user_driver_license
+ * The UserDriverLicense to update
*/
-function UserDriverLicenses_update($user_id, $has_car, $has_license_car, $has_license_3_5t_transporter, $has_license_7_5t_truck, $has_license_12_5t_truck, $has_license_forklift) {
+function UserDriverLicenses_update($user_driver_license) {
$result = sql_query("UPDATE `UserDriverLicenses` SET
- `has_car`=" . sql_bool($has_car) . ",
- `has_license_car`=" . sql_bool($has_license_car) . ",
- `has_license_3_5t_transporter`=" . sql_bool($has_license_3_5t_transporter) . ",
- `has_license_7_5t_truck`=" . sql_bool($has_license_7_5t_truck) . ",
- `has_license_12_5t_truck`=" . sql_bool($has_license_12_5t_truck) . ",
- `has_license_forklift`=" . sql_bool($has_license_forklift) . "
- WHERE `user_id`='" . sql_escape($user_id) . "'");
+ `has_car`=" . sql_bool($user_driver_license['has_car']) . ",
+ `has_license_car`=" . sql_bool($user_driver_license['has_license_car']) . ",
+ `has_license_3_5t_transporter`=" . sql_bool($user_driver_license['has_license_3_5t_transporter']) . ",
+ `has_license_7_5t_truck`=" . sql_bool($user_driver_license['has_license_7_5t_truck']) . ",
+ `has_license_12_5t_truck`=" . sql_bool($user_driver_license['has_license_12_5t_truck']) . ",
+ `has_license_forklift`=" . sql_bool($user_driver_license['has_license_forklift']) . "
+ WHERE `user_id`='" . sql_escape($user_driver_license['user_id']) . "'");
if ($result === false) {
engelsystem_error("Unable to update user driver license information");
}