| 1 |
<?php |
| 2 |
/** |
| 3 |
* Rule engine group model. |
| 4 |
* |
| 5 |
* @package ContentControl |
| 6 |
* @subpackage Models |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace ContentControl\Models\RuleEngine; |
| 10 |
|
| 11 |
/** |
| 12 |
* Handler for condition groups. |
| 13 |
* |
| 14 |
* @package ContentControl |
| 15 |
*/ |
| 16 |
class Group extends Item { |
| 17 |
|
| 18 |
/** |
| 19 |
* Group id. |
| 20 |
* |
| 21 |
* @var string |
| 22 |
*/ |
| 23 |
public $id; |
| 24 |
|
| 25 |
/** |
| 26 |
* Group label. |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
public $label; |
| 31 |
|
| 32 |
/** |
| 33 |
* Group query. |
| 34 |
* |
| 35 |
* @var Query |
| 36 |
*/ |
| 37 |
public $query; |
| 38 |
|
| 39 |
/** |
| 40 |
* Build a group. |
| 41 |
* |
| 42 |
* @param array{id:string,label:string,query:array<mixed>} $group Group data. |
| 43 |
*/ |
| 44 |
public function __construct( $group ) { |
| 45 |
$group = wp_parse_args( $group, [ |
| 46 |
'id' => '', |
| 47 |
'label' => '', |
| 48 |
'query' => [], |
| 49 |
]); |
| 50 |
|
| 51 |
$this->id = $group['id']; |
| 52 |
$this->label = $group['label']; |
| 53 |
$this->query = new Query( $group['query'] ); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Check if this group has JS based rules. |
| 58 |
* |
| 59 |
* @return bool |
| 60 |
*/ |
| 61 |
public function has_js_rules() { |
| 62 |
return $this->query->has_js_rules(); |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* Check this groups rules. |
| 67 |
* |
| 68 |
* @return bool |
| 69 |
*/ |
| 70 |
public function check_rules() { |
| 71 |
return $this->query->check_rules(); |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Check this groups rules. |
| 76 |
* |
| 77 |
* @return array<bool|null|array<bool|null>> |
| 78 |
*/ |
| 79 |
public function get_checks() { |
| 80 |
return $this->query->get_checks(); |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Return the rule check as an array of information. |
| 85 |
* |
| 86 |
* Useful for debugging. |
| 87 |
* |
| 88 |
* @return array<mixed> |
| 89 |
*/ |
| 90 |
public function get_check_info() { |
| 91 |
return $this->query->get_check_info(); |
| 92 |
} |
| 93 |
} |
| 94 |
|