32 parent::__construct(
$config, $reserved);
37 foreach (
$config as $attribute => $rules) {
38 if ($attribute ===
'%ignoreEntities') {
39 $this->ignoreEntities =
$config[
'%ignoreEntities'];
43 if (!is_string($attribute)) {
46 $this->cardinality[$attribute] = array(
'warn' =>
false);
49 if (isset($rules[0])) {
50 $this->cardinality[$attribute][
'min'] = $rules[0];
51 } elseif (isset($rules[
'min'])) {
52 $this->cardinality[$attribute][
'min'] = $rules[
'min'];
54 if (isset($rules[1])) {
55 $this->cardinality[$attribute][
'max'] = $rules[1];
56 } elseif (isset($rules[
'max'])) {
57 $this->cardinality[$attribute][
'max'] = $rules[
'max'];
59 if (array_key_exists(
'warn', $rules)) {
60 $this->cardinality[$attribute][
'warn'] = (bool) $rules[
'warn'];
64 if (!array_key_exists(
'min', $this->cardinality[$attribute])) {
65 $this->cardinality[$attribute][
'min'] = 0;
66 } elseif (!is_int($this->cardinality[$attribute][
'min']) ||
67 $this->cardinality[$attribute][
'min'] < 0
70 var_export($attribute,
true));
72 if (array_key_exists(
'max', $this->cardinality[$attribute]) &&
73 !is_int($this->cardinality[$attribute][
'max'])
76 var_export($attribute,
true));
78 if (array_key_exists(
'min', $this->cardinality[$attribute]) &&
79 array_key_exists(
'max', $this->cardinality[$attribute]) &&
80 $this->cardinality[$attribute][
'min'] > $this->cardinality[$attribute][
'max']
83 var_export($attribute,
true));
87 $this->cardinality[$attribute][
'_expr'] = sprintf(
'%d ≤ n', $this->cardinality[$attribute][
'min']);
88 if (array_key_exists(
'max', $this->cardinality[$attribute])) {
89 $this->cardinality[$attribute][
'_expr'] .= sprintf(
' ≤ %d', $this->cardinality[$attribute][
'max']);
102 assert(array_key_exists(
"Attributes",
$request));
105 if (array_key_exists(
'Source',
$request) && array_key_exists(
'entityid',
$request[
'Source'])) {
106 $entityid =
$request[
'Source'][
'entityid'];
108 if (in_array($entityid, $this->ignoreEntities,
true)) {
113 foreach (
$request[
'Attributes'] as $k => $v) {
115 if (!array_key_exists($k, $this->cardinality)) {
123 if (count($v) < $this->cardinality[$k][
'min']) {
124 if ($this->cardinality[$k][
'warn']) {
126 'Cardinality: attribute %s from %s does not meet minimum cardinality of %d (%d)',
127 $k, $entityid, $this->cardinality[$k][
'min'], count($v)
130 $request[
'core:cardinality:errorAttributes'][$k] = array(count($v), $this->cardinality[$k][
'_expr']);
136 if (array_key_exists(
'max', $this->cardinality[$k]) && count($v) > $this->cardinality[$k][
'max']) {
137 if ($this->cardinality[$k][
'warn']) {
139 'Cardinality: attribute %s from %s does not meet maximum cardinality of %d (%d)',
140 $k, $entityid, $this->cardinality[$k][
'max'], count($v)
143 $request[
'core:cardinality:errorAttributes'][$k] = array(count($v), $this->cardinality[$k][
'_expr']);
150 foreach ($this->cardinality as $k => $v) {
151 if (!$this->cardinality[$k][
'min'] || array_key_exists($k,
$request[
'Attributes'])) {
154 if ($this->cardinality[$k][
'warn']) {
156 'Cardinality: attribute %s from %s is missing',
160 $request[
'core:cardinality:errorAttributes'][$k] = array(0, $this->cardinality[$k][
'_expr']);
165 if (array_key_exists(
'core:cardinality:errorAttributes',
$request)) {
168 $this->
http->redirectTrustedURL(
$url, array(
'StateId' =>
$id));
__construct($config, $reserved, HTTPAdapter $http=null)
Initialize this filter, parse configuration.
foreach($paths as $path) $request
if(!array_key_exists('StateId', $_REQUEST)) $id
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
static http()
Fetches the global http state from ILIAS.
static saveState(&$state, $stage, $rawId=false)
Save the state.
process(&$request)
Process this filter.