forked from flack/openpsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource.php
106 lines (93 loc) · 2.81 KB
/
resource.php
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
<?php
/**
* @package org.openpsa.calendar
* @author Nemein Oy, http://www.nemein.com/
* @copyright Nemein Oy, http://www.nemein.com/
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
*/
/**
* MidCOM wrapped class for access to stored queries
*
* @package org.openpsa.calendar
*/
class org_openpsa_calendar_resource_dba extends midcom_core_dbaobject
{
public $__midcom_class_name__ = __CLASS__;
public $__mgdschema_class_name__ = 'org_openpsa_calendar_resource';
function get_parent_guid_uncached()
{
if ($this->owner != 0)
{
$parent = new midcom_db_person($this->owner);
return $parent->guid;
}
else
{
return null;
}
}
public function _on_creating()
{
if ($this->_check_duplicates($this->name))
{
midcom_connection::set_error(MGD_ERR_OBJECT_NAME_EXISTS);
return false;
}
return true;
}
public function _on_updating()
{
if ($this->_check_duplicates($this->name))
{
midcom_connection::set_error(MGD_ERR_OBJECT_NAME_EXISTS);
return false;
}
return true;
}
private function _check_duplicates($name)
{
if ($name == '')
{
return false;
}
// Check for duplicates
$qb = org_openpsa_calendar_resource_dba::new_query_builder();
$qb->add_constraint('name', '=', $name);
if ($this->id)
{
$qb->add_constraint('id', '<>', $this->id);
}
$result = $qb->execute();
if (count($result) > 0)
{
return true;
}
return false;
}
function get_reservations($from, $to)
{
$qb = org_openpsa_calendar_event_resource_dba::new_query_builder();
// Find all events that occur during [$from, $end]
$qb->begin_group("OR");
// The event begins during [$from, $to]
$qb->begin_group("AND");
$qb->add_constraint("event.start", ">=", $from);
$qb->add_constraint("event.start", "<=", $to);
$qb->end_group();
// The event begins before and ends after [$from, $to]
$qb->begin_group("AND");
$qb->add_constraint("event.start", "<=", $from);
$qb->add_constraint("event.end", ">=", $to);
$qb->end_group();
// The event ends during [$from, $to]
$qb->begin_group("AND");
$qb->add_constraint("event.end", ">=", $from);
$qb->add_constraint("event.end", "<=", $to);
$qb->end_group();
$qb->end_group();
$qb->add_constraint('resource', '=', $this->id);
$qb->add_order('event.start');
return $qb->execute();
}
}
?>