Skip to content

Commit

Permalink
Implemented conditions restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
LionelLaffineur committed Jul 25, 2023
1 parent 4b9fac5 commit b81bb06
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/Skeleton/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Pager {
'page' => 1,
'joins' => [],
'sort_permissions' => [],
'conditions_restrictions' => [],
];

/**
Expand Down Expand Up @@ -186,6 +187,19 @@ public function add_condition() {
$this->options['conditions'] = $conditions;
}

/**
* Add condition restriction
*
* @access public
* @param string $field
* @param string $comparison (optional)
* @param string $value
*/
public function add_condition_restriction($field, $comparison, $params) {
$field = $this->expand_field_name($field);
$this->options['conditions_restrictions'][] = new Condition($field, $comparison, $params);
}

/**
* Has condition
*
Expand Down Expand Up @@ -509,6 +523,21 @@ public function page($all = false) {
throw new \Exception('Sorting not allowed for field ' . $this->options['sort']);
}

// Check if all the condition restrictions are fulfulled
foreach ($this->options['conditions_restrictions'] as $condition_restriction) {
$found = false;
foreach ($this->get_conditions() as $condition) {
$condition = array_shift($condition);
if ($condition->equals($condition_restriction)) {
$found = true;
break;
}
}
if ($found === false) {
throw new \Exception('Permission denied');
}
}

$sort = $this->options['sort'];

$this->options['all'] = $all;
Expand Down

0 comments on commit b81bb06

Please sign in to comment.