|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @copyright CONTENT CONTROL GmbH, http://www.contentcontrol-berlin.de |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace midcom\datamanager\storage; |
|
7
|
|
|
|
|
8
|
|
|
use midcom_core_dbaobject; |
|
9
|
|
|
use midcom_core_privilege; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Experimental storage class |
|
13
|
|
|
*/ |
|
14
|
|
|
class privilege extends delayed |
|
15
|
|
|
{ |
|
16
|
5 |
|
public function __construct(midcom_core_dbaobject $object, array $config) |
|
17
|
|
|
{ |
|
18
|
5 |
|
if (!array_key_exists('classname', $config['type_config'])) { |
|
19
|
2 |
|
$config['type_config']['classname'] = ''; |
|
20
|
|
|
} |
|
21
|
5 |
|
parent::__construct($object, $config); |
|
22
|
5 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritdoc} |
|
26
|
|
|
*/ |
|
27
|
5 |
|
public function load() |
|
28
|
|
|
{ |
|
29
|
5 |
|
$source = $this->get_privilege(); |
|
30
|
5 |
|
return $source->value; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* {@inheritdoc} |
|
35
|
|
|
*/ |
|
36
|
|
|
public function save() |
|
37
|
|
|
{ |
|
38
|
|
|
$privilege = $this->get_privilege(); |
|
39
|
|
|
$privilege->value = $this->value; |
|
40
|
|
|
$privilege->store(); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @return \midcom_core_privilege |
|
45
|
|
|
*/ |
|
46
|
5 |
|
private function get_privilege() : midcom_core_privilege |
|
47
|
|
|
{ |
|
48
|
5 |
|
$privilege = $this->get_privilege_object()->get_privilege( |
|
49
|
5 |
|
$this->config['type_config']['privilege_name'], |
|
50
|
5 |
|
$this->config['type_config']['assignee'], |
|
51
|
5 |
|
$this->config['type_config']['classname']); |
|
52
|
|
|
|
|
53
|
5 |
|
if ($privilege === false) { |
|
|
|
|
|
|
54
|
|
|
throw new \midcom_error_forbidden('Failed to load privilege'); |
|
55
|
|
|
} |
|
56
|
5 |
|
return $privilege; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @return midcom_core_dbaobject |
|
61
|
|
|
*/ |
|
62
|
5 |
|
private function get_privilege_object() : midcom_core_dbaobject |
|
63
|
|
|
{ |
|
64
|
5 |
|
if (!empty($this->config['type_config']['privilege_object'])) { |
|
65
|
2 |
|
return $this->config['type_config']['privilege_object']; |
|
66
|
|
|
} |
|
67
|
5 |
|
return $this->object; |
|
68
|
|
|
} |
|
69
|
|
|
} |