aboutsummaryrefslogtreecommitdiff
path: root/lib/models/resources/RoomRequest.class.php
blob: c0898d7a0b8630f811e26e665853140b68b2620e (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
<?php

/**
 * RoomRequest.class.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.
 *
 * @param Room room Link to the Room resource (same as the resource attribute).
 * @param string seats additional field (from ResourceRequestProperty)
 * @param string booking_plan_is_public additional field
 *     (from ResourceRequestProperty)
 *
 * All other properties are inherited from the parent class (ResourceRequest).
 * @author      Cornelis Kater <ckater@gwdg.de>
 * @author      Till Glöggler <tgloeggl@uos.de>
 * @author      André Noack <noack@data-quest.de>
 * @author      Suchi & Berg GmbH <info@data-quest.de>
 * @author      Moritz Strohm <strohm@data-quest.de>
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
 * @category    Stud.IP
 *
 *
 */
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;
    }
}