Completed
Push — master ( eaac63...8dbf53 )
by Andreas
24:16
created

get_parent_guid_uncached_static()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @package midcom.db
4
 * @author The Midgard Project, http://www.midgard-project.org
5
 * @copyright The Midgard Project, http://www.midgard-project.org
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 */
8
9
/**
10
 * MidCOM level replacement for the Midgard Parameter record with framework support.
11
 *
12
 * The uplink is the parentguid parameter.
13
 *
14
 * @property string $domain Namespace of the parameter
15
 * @property string $name Key of the parameter
16
 * @property string $value Value of the parameter
17
 * @property string $parentguid GUID of the object the parameter extends
18
 * @package midcom.db
19
 */
20
class midcom_db_parameter extends midcom_core_dbaobject
21
{
22
    public $__midcom_class_name__ = __CLASS__;
23
    public $__mgdschema_class_name__ = 'midgard_parameter';
24
25
    public $_use_rcs = false;
26
27
    public function get_parent_guid_uncached()
28
    {
29
        return $this->parentguid;
30
    }
31
32
    /**
33
     * Returns the Parent of the Parameter.
34
     */
35
    public static function get_parent_guid_uncached_static($guid) : ?string
36
    {
37
        $mc = new midgard_collector('midgard_parameter', 'guid', $guid);
38
        $mc->set_key_property('parentguid');
39
        $mc->execute();
40
        return key($mc->list_keys());
41
    }
42
43
    /**
44
     * Read a parameter without loading the corresponding object.
45
     * This is primarily for improving performance, so the function does not check
46
     * for privileges.
47
     *
48
     * @param string $objectguid The object's GUID
49
     * @param string $domain The parameter's domain
50
     * @param string $name The parameter to look for
51
     */
52 11
    public static function get_by_objectguid($objectguid, $domain, $name)
53
    {
54 11
        static $parameter_cache = [];
55 11
        $cache_key = $objectguid . '::' . $domain . '::' . $name;
56
57 11
        if (!array_key_exists($cache_key, $parameter_cache)) {
58
59 4
            $mc = midgard_parameter::new_collector('parentguid', $objectguid);
60 4
            $mc->set_key_property('value');
61 4
            $mc->add_constraint('name', '=', $name);
62 4
            $mc->add_constraint('domain', '=', $domain);
63 4
            $mc->set_limit(1);
64 4
            $mc->execute();
65
66 4
            $parameter_cache[$cache_key] = key($mc->list_keys());
67
        }
68 11
        return $parameter_cache[$cache_key];
69
    }
70
71
    public function get_label() : string
72
    {
73
        return "{$this->domain} {$this->name}";
74
    }
75
}
76