org_openpsa_calendar_event_resource_dba   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 29
c 0
b 0
f 0
dl 0
loc 64
ccs 0
cts 30
cp 0
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get_label() 0 8 2
A _on_updating() 0 7 2
A notify() 0 3 1
A verify_can_reserve() 0 17 4
A _on_creating() 0 7 2
1
<?php
2
/**
3
 * @package org.openpsa.calendar
4
 * @author Nemein Oy, http://www.nemein.com/
5
 * @copyright Nemein Oy, http://www.nemein.com/
6
 * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
7
 */
8
9
/**
10
 * MidCOM wrapped class for access to stored queries
11
 *
12
 * @property integer $resource
13
 * @property integer $event
14
 * @property string $description
15
 * @package org.openpsa.calendar
16
 */
17
class org_openpsa_calendar_event_resource_dba extends midcom_core_dbaobject
18
{
19
    public string $__midcom_class_name__ = __CLASS__;
20
    public string $__mgdschema_class_name__ = 'org_openpsa_calendar_event_resource';
21
22
    /**
23
     * Human-readable label for cases like Asgard navigation
24
     */
25
    public function get_label() : string
26
    {
27
        if ($this->resource) {
28
            $resource = new org_openpsa_calendar_resource_dba($this->resource);
29
            $event = new org_openpsa_calendar_event_dba($this->event);
30
            return sprintf(midcom::get()->i18n->get_string('%s for %s', 'midcom'), $resource->title, $event->title);
31
        }
32
        return "member #{$this->id}";
33
    }
34
35
    /**
36
     * Function to check whether we can reserve the resource we are trying to
37
     */
38
    public function verify_can_reserve() : bool
39
    {
40
        if (empty($this->resource)) {
41
            debug_add("Resource is set to empty value returning true");
42
            return true;
43
        }
44
        try {
45
            $resource = org_openpsa_calendar_resource_dba::get_cached($this->resource);
46
        } catch (midcom_error) {
47
            debug_add("Cannot fetch resource #{$this->resource} returning false", MIDCOM_LOG_INFO);
48
            return false;
49
        }
50
        $stat = $resource->can_do('org.openpsa.calendar:reserve');
51
        if (!$stat) {
52
            debug_add("\$resource->can_do('org.openpsa.calendar:reserve'), returned false, so will we", MIDCOM_LOG_INFO);
53
        }
54
        return $stat;
55
    }
56
57
    public function _on_creating() : bool
58
    {
59
        if (!$this->verify_can_reserve()) {
60
            midcom_connection::set_error(MGD_ERR_ACCESS_DENIED);
61
            return false;
62
        }
63
        return true;
64
    }
65
66
    public function _on_updating() : bool
67
    {
68
        if (!$this->verify_can_reserve()) {
69
            midcom_connection::set_error(MGD_ERR_ACCESS_DENIED);
70
            return false;
71
        }
72
        return true;
73
    }
74
75
    /**
76
     * @todo Send notification to resource owner
77
     */
78
    function notify($repeat_handler = 'this', $event = false)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
79
    {
80
        return true;
81
    }
82
}
83