summaryrefslogtreecommitdiff
path: root/includes/model/EventConfig_model.php
blob: f5846870469fd615ae64f6b466cb47ca95e73f9c (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
<?php

use Engelsystem\Database\DB;

/**
 * Get event config.
 *
 * @return array|null
 */
function EventConfig()
{
    $event_config = DB::select('SELECT * FROM `EventConfig` LIMIT 1');
    if (DB::getStm()->errorCode() != '00000') {
        engelsystem_error('Unable to load event config.');
        return null;
    }

    if (empty($event_config)) {
        return null;
    }

    return array_shift($event_config);
}

/**
 * Update event config.
 *
 * @param string $event_name
 * @param int    $buildup_start_date
 * @param int    $event_start_date
 * @param int    $event_end_date
 * @param int    $teardown_end_date
 * @param string $event_welcome_msg
 * @return bool
 */
function EventConfig_update(
    $event_name,
    $buildup_start_date,
    $event_start_date,
    $event_end_date,
    $teardown_end_date,
    $event_welcome_msg
) {
    if (EventConfig() == null) {
        return DB::insert('
              INSERT INTO `EventConfig` (
                  `event_name`,
                  `buildup_start_date`,
                  `event_start_date`,
                  `event_end_date`,
                  `teardown_end_date`,
                  `event_welcome_msg`
              )
              VALUES (?, ?, ?, ?, ?, ?)
            ',
            [
                $event_name,
                $buildup_start_date,
                $event_start_date,
                $event_end_date,
                $teardown_end_date,
                $event_welcome_msg
            ]
        );
    }

    return (bool)DB::update('
          UPDATE `EventConfig` SET
          `event_name` = ?,
          `buildup_start_date` = ?,
          `event_start_date` = ?,
          `event_end_date` = ?,
          `teardown_end_date` = ?,
          `event_welcome_msg` = ?
        ',
        [
            $event_name,
            $buildup_start_date,
            $event_start_date,
            $event_end_date,
            $teardown_end_date,
            $event_welcome_msg,
        ]
    );
}