Newer
Older
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
require_once 'Bachelor.php';
class Fahrt {
const STATUS_IS_OPEN_NOT_FULL = 0;
const STATUS_IS_OPEN_FULL = 1;
const STATUS_IS_CLOSED = 2;
const ALLOWED_FIELDS = ['fahrt_id', 'titel', 'ziel', 'vom', 'bis', 'regopen', 'beschreibung', 'leiter', 'kontakt',
'map_pin', 'max_bachelor', 'wikilink', 'paydeadline', 'payinfo', 'opentime'];
private $environment;
private $fid;
private $data;
function __construct($fid) {
$this->environment = Environment::getEnv();
$this->fid = $fid;
$this->data = null;
}
private function getBachelorsSelector($params) {
$conditions = [
'fahrt_id' => $this->fid
];
if (isset($params['waiting'])) {
$conditions['transferred' . (($params['waiting']) ? '' : '[!]')] = null;
$conditions['on_waitlist'] = ($params['waiting']) ? 1 : 0;
}
if (isset($params['essen']))
$conditions['essen'] = $params['essen'];
if (isset($params['studityp']))
$conditions['studityp'] = $params['studityp'];
if (isset($params['virgin']))
$conditions['virgin'] = ($params['virgin']) ? 1 : 0;
if (isset($params['backstepped']))
$conditions['backstepped' . (($params['backstepped']) ? '[!]' : '')] = null;
if (isset($params['paid']))
$conditions['paid' . (($params['paid']) ? '[!]' : '')] = null;
if (isset($params['repaid']))
$conditions['repaid' . (($params['backstepped']) ? '[!]' : '')] = null;
if (isset($params['public']))
$conditions['public'] = ($params['public']) ? 1 : 0;
$selector = [
'table' => 'bachelor',
'fields' => !isset($params['fields']) ? Bachelor::ALLOWED_FIELDS : $params['fields'],
'where' => ['AND' => $conditions]
];
return $selector;
}
/**
* This function returns participants of this fahrt.
* Set parameters to filter, keep unset means 'dont care'.
*
* Form the param array as follows:
* - $fields (array[string]) columns you want to select
* - $waiting (bool) is on the waitlist and not transferred
* - $essen (str) has specific food preferences
* - $studityp (int) is of specific studityp
* - $virgin (bool) is <18 or not
* - $backstepped (bool) stepped back or not
* - $paid (bool) paid or not
* - $repaid (bool) got money back or not
* - $public (bool) publically visible
*
* @param array $params params for the selector
*
* @return medoo result
*/
public function getBachelors($params) {
$selector = $this->getBachelorsSelector($params);
return $this->environment->database->select($selector['table'], $selector['fields'], $selector['where']);
}
public function getBachelor($bid) {
return Bachelor::makeFromDB($this->fid, $bid);
}
public function getFahrtDetails() {
if (!is_null($this->data))
return $this->data;
$this->data = $this->environment->database->get('fahrten', Fahrt::ALLOWED_FIELDS, ['fahrt_id' => $this->fid]);
return $this->data;
}
public function getID() {
return $this->fid;
}
public function getPossibleDates(){
$details = $this->getFahrtDetails();
$end = new DateTime($details['bis']);
$period = new DatePeriod(
new DateTime($details['von']),
new DateInterval('P1D'),
$end->modify( '+1 day' )
);
$ret = [];
foreach($period as $d){
array_push($ret, $d->format("d.m.Y"));
}
return $ret;
}
public function getRegistrationState() {
comm_verbose(3, 'checking if fid ' . $this->fid . ' is open');
if (!$this->environment->database->has('fahrten', ['AND' => ['fahrt_id' => $this->fid, 'regopen' => 1]]))
return Fahrt::STATUS_IS_CLOSED;
$selector = $this->getBachelorsSelector(['backstepped' => false, 'waiting' => false]);
$cnt = $this->environment->database->count('bachelor', $selector['where']);
$max = $this->getFahrtDetails()['max_bachelor'];
if ($cnt < $max)
return Fahrt::STATUS_IS_OPEN_NOT_FULL;
return Fahrt::STATUS_IS_OPEN_FULL;
}
public function isRegistrationOpen() {
$state = $this->getRegistrationState();
return $state == Fahrt::STATUS_IS_OPEN_FULL or $state == Fahrt::STATUS_IS_OPEN_NOT_FULL;
}
}