Skip to content

Commit b81bb06

Browse files
Implemented conditions restrictions
1 parent 4b9fac5 commit b81bb06

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/Skeleton/Pager/Pager.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class Pager {
2828
'page' => 1,
2929
'joins' => [],
3030
'sort_permissions' => [],
31+
'conditions_restrictions' => [],
3132
];
3233

3334
/**
@@ -186,6 +187,19 @@ public function add_condition() {
186187
$this->options['conditions'] = $conditions;
187188
}
188189

190+
/**
191+
* Add condition restriction
192+
*
193+
* @access public
194+
* @param string $field
195+
* @param string $comparison (optional)
196+
* @param string $value
197+
*/
198+
public function add_condition_restriction($field, $comparison, $params) {
199+
$field = $this->expand_field_name($field);
200+
$this->options['conditions_restrictions'][] = new Condition($field, $comparison, $params);
201+
}
202+
189203
/**
190204
* Has condition
191205
*
@@ -509,6 +523,21 @@ public function page($all = false) {
509523
throw new \Exception('Sorting not allowed for field ' . $this->options['sort']);
510524
}
511525

526+
// Check if all the condition restrictions are fulfulled
527+
foreach ($this->options['conditions_restrictions'] as $condition_restriction) {
528+
$found = false;
529+
foreach ($this->get_conditions() as $condition) {
530+
$condition = array_shift($condition);
531+
if ($condition->equals($condition_restriction)) {
532+
$found = true;
533+
break;
534+
}
535+
}
536+
if ($found === false) {
537+
throw new \Exception('Permission denied');
538+
}
539+
}
540+
512541
$sort = $this->options['sort'];
513542

514543
$this->options['all'] = $all;

0 commit comments

Comments
 (0)