ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ScopeAttribute.php
Go to the documentation of this file.
1<?php
2
9
16
17
24
25
32
38 private $onlyIfEmpty = false;
39
40
47 public function __construct($config, $reserved) {
48 parent::__construct($config, $reserved);
49 assert('is_array($config)');
50
52
53 $this->scopeAttribute = $config->getString('scopeAttribute');
54 $this->sourceAttribute = $config->getString('sourceAttribute');
55 $this->targetAttribute = $config->getString('targetAttribute');
56 $this->onlyIfEmpty = $config->getBoolean('onlyIfEmpty', false);
57 }
58
59
65 public function process(&$request) {
66 assert('is_array($request)');
67 assert('array_key_exists("Attributes", $request)');
68
69 $attributes =& $request['Attributes'];
70
71 if (!isset($attributes[$this->scopeAttribute])) {
72 return;
73 }
74
75 if (!isset($attributes[$this->sourceAttribute])) {
76 return;
77 }
78
79 if (!isset($attributes[$this->targetAttribute])) {
81 }
82
83 if ($this->onlyIfEmpty and count($attributes[$this->targetAttribute]) > 0) {
84 return;
85 }
86
87 foreach ($attributes[$this->scopeAttribute] as $scope) {
88
89 if (strpos($scope, '@') !== FALSE) {
90 $scope = explode('@', $scope, 2);
91 $scope = $scope[1];
92 }
93
94 foreach ($attributes[$this->sourceAttribute] as $value) {
95 $value = $value . '@' . $scope;
96
97 if (in_array($value, $attributes[$this->targetAttribute], TRUE)) {
98 // Already present
99 continue;
100 }
101
103 }
104 }
105
106 }
107
108}
An exception for terminatinating execution or to throw for unit testing.
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
__construct($config, $reserved)
Initialize this filter, parse configuration.
process(&$request)
Apply this filter to the request.
$attributes