ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 {
49 parent::__construct($config, $reserved);
50 assert(is_array($config));
51
53
54 $this->scopeAttribute = $config->getString('scopeAttribute');
55 $this->sourceAttribute = $config->getString('sourceAttribute');
56 $this->targetAttribute = $config->getString('targetAttribute');
57 $this->onlyIfEmpty = $config->getBoolean('onlyIfEmpty', false);
58 }
59
60
66 public function process(&$request)
67 {
68 assert(is_array($request));
69 assert(array_key_exists('Attributes', $request));
70
71 $attributes =& $request['Attributes'];
72
73 if (!isset($attributes[$this->scopeAttribute])) {
74 return;
75 }
76
77 if (!isset($attributes[$this->sourceAttribute])) {
78 return;
79 }
80
81 if (!isset($attributes[$this->targetAttribute])) {
83 }
84
85 if ($this->onlyIfEmpty && count($attributes[$this->targetAttribute]) > 0) {
86 return;
87 }
88
89 foreach ($attributes[$this->scopeAttribute] as $scope) {
90 if (strpos($scope, '@') !== false) {
91 $scope = explode('@', $scope, 2);
92 $scope = $scope[1];
93 }
94
95 foreach ($attributes[$this->sourceAttribute] as $value) {
96 $value = $value . '@' . $scope;
97
98 if (in_array($value, $attributes[$this->targetAttribute], true)) {
99 // Already present
100 continue;
101 }
102
104 }
105 }
106 }
107}
foreach($paths as $path) $request
Definition: asyncclient.php:32
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.
if(array_key_exists('yes', $_REQUEST)) $attributes
Definition: getconsent.php:85
$config
Definition: bootstrap.php:15