@@ -28,6 +28,7 @@ class Pager {
28
28
'page ' => 1 ,
29
29
'joins ' => [],
30
30
'sort_permissions ' => [],
31
+ 'conditions_restrictions ' => [],
31
32
];
32
33
33
34
/**
@@ -186,6 +187,19 @@ public function add_condition() {
186
187
$ this ->options ['conditions ' ] = $ conditions ;
187
188
}
188
189
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
+
189
203
/**
190
204
* Has condition
191
205
*
@@ -509,6 +523,21 @@ public function page($all = false) {
509
523
throw new \Exception ('Sorting not allowed for field ' . $ this ->options ['sort ' ]);
510
524
}
511
525
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
+
512
541
$ sort = $ this ->options ['sort ' ];
513
542
514
543
$ this ->options ['all ' ] = $ all ;
0 commit comments