summaryrefslogtreecommitdiff
path: root/includes/model/ShiftTypes_model.php
blob: 96a823d46da165a3c4043976da04daad845f24d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php

use Engelsystem\Database\DB;

/**
 * Delete a shift type.
 *
 * @param int $shifttype_id
 * @return bool
 */
function ShiftType_delete($shifttype_id)
{
    return DB::delete('DELETE FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
}

/**
 * Update a shift type.
 *
 * @param int    $shifttype_id
 * @param string $name
 * @param int    $angeltype_id
 * @param string $description
 * @return bool
 */
function ShiftType_update($shifttype_id, $name, $angeltype_id, $description)
{
    DB::update('
      UPDATE `ShiftTypes` SET
      `name`=?,
      `angeltype_id`=?,
      `description`=?
      WHERE `id`=?
    ',
        [
            $name,
            $angeltype_id,
            $description,
            $shifttype_id,
        ]
    );

    return DB::getStm()->errorCode() == '00000';
}

/**
 * Create a shift type.
 *
 * @param string $name
 * @param int    $angeltype_id
 * @param string $description
 * @return int|false new shifttype id
 */
function ShiftType_create($name, $angeltype_id, $description)
{
    $result = DB::insert('
        INSERT INTO `ShiftTypes` (`name`, `angeltype_id`, `description`)
        VALUES(?, ?, ?)
        ',
        [
            $name,
            $angeltype_id,
            $description
        ]
    );

    if ($result === false) {
        return false;
    }

    return DB::getPdo()->lastInsertId();
}

/**
 * Get a shift type by id.
 *
 * @param int $shifttype_id
 * @return array|null
 */
function ShiftType($shifttype_id)
{
    $shifttype = DB::select('SELECT * FROM `ShiftTypes` WHERE `id`=?', [$shifttype_id]);
    if (DB::getStm()->errorCode() != '00000') {
        engelsystem_error('Unable to load shift type.');
    }
    if (empty($shifttype)) {
        return null;
    }
    return array_shift($shifttype);
}

/**
 * Get all shift types.
 *
 * @return array|false
 */
function ShiftTypes()
{
    $result = DB::select('SELECT * FROM `ShiftTypes` ORDER BY `name`');

    if (DB::getStm()->errorCode() != '00000') {
        return false;
    }

    return $result;
}