blob: 4ba11bce53be5aad9d35b8f4a6ce6fcec184feb1 (
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
|
<?php
/**
* RoomRequest.php - model class for table resource_requests
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @property string $id database column
* @property string $course_id database column
* @property string $termin_id database column
* @property string $metadate_id database column
* @property string $user_id database column
* @property string $last_modified_by database column
* @property string $resource_id database column
* @property string|null $category_id database column
* @property string|null $comment database column
* @property string|null $reply_comment database column
* @property string $reply_recipients database column
* @property int $closed database column
* @property int|null $mkdate database column
* @property int|null $chdate database column
* @property int $begin database column
* @property int $end database column
* @property int $preparation_time database column
* @property int $marked database column
* @property SimpleORMapCollection|ResourceRequestProperty[] $properties has_many ResourceRequestProperty
* @property SimpleORMapCollection|ResourceRequestAppointment[] $appointments has_many ResourceRequestAppointment
* @property Room $room belongs_to Room
* @property Resource $resource belongs_to Resource
* @property ResourceCategory|null $category belongs_to ResourceCategory
* @property User $user belongs_to User
* @property User $last_modifier belongs_to User
* @property Course $course belongs_to Course
* @property SeminarCycleDate $cycle belongs_to SeminarCycleDate
* @property CourseDate $date belongs_to CourseDate
* @property mixed $seats additional field
* @property mixed $room_type additional field
* @property mixed $booking_plan_is_public additional field
*/
class RoomRequest extends ResourceRequest
{
protected static function configure($config = [])
{
$config['belongs_to']['room'] = [
'class_name' => Room::class,
'foreign_key' => 'resource_id',
'assoc_func' => 'find'
];
$required_properties = [
'seats',
'room_type',
'booking_plan_is_public'
];
$config['additional_fields'] = [];
foreach ($required_properties as $property) {
$config['additional_fields'][$property] = [
'get' => 'getProperty',
'set' => 'setProperty'
];
}
parent::configure($config);
}
public function checkOpen($also_change = false)
{
$db = DBManager::get();
$existing_assign = false;
//a request for a date is easy...
if ($this->termin_id) {
$query = sprintf("SELECT id FROM resource_bookings WHERE range_id = %s ", $db->quote($this->termin_id));
$existing_assign = $db->query($query)->fetchColumn();
//metadate request
} elseif ($this->metadate_id) {
$query = sprintf("SELECT count(termin_id)=count(resource_bookings.id) FROM termine LEFT JOIN resource_bookings ON(termin_id=resource_bookings.range_id)
WHERE metadate_id=%s", $db->quote($this->metadate_id));
//seminar request
} else {
$query = sprintf("SELECT count(termin_id)=count(resource_bookings.id) FROM termine LEFT JOIN resource_bookings ON(termin_id=resource_bookings.range_id)
WHERE range_id='%s' AND date_typ IN" . getPresenceTypeClause(), $this->course_id);
}
if ($query) {
$existing_assign = $db->query($query)->fetchColumn();
}
if ($existing_assign && $also_change) {
$this->closed = 1;
$this->store();
}
return (bool)$existing_assign;
}
}
|