diff --git a/classes/condition.php b/classes/condition.php new file mode 100644 index 0000000..3eaf511 --- /dev/null +++ b/classes/condition.php @@ -0,0 +1,55 @@ +. + +namespace classes; + +use core\persistent; + +/** + * Conditions persistent + * + * @package tool_dynamic_cohorts + * @copyright 2024 Catalyst IT + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class condition extends persistent { + + /** @var string table. */ + const TABLE = 'tool_dynamic_cohorts_c'; + + /** + * Return the definition of the properties of this model. + * + * @return array + */ + protected static function define_properties() { + return [ + 'ruleid' => [ + 'type' => PARAM_INT, + ], + 'classname' => [ + 'type' => PARAM_TEXT, + ], + 'configdata' => [ + 'type' => PARAM_RAW, + 'default' => '{}', + ], + 'sortorder' => [ + 'type' => PARAM_INT, + ], + ]; + } +} diff --git a/classes/rule.php b/classes/rule.php new file mode 100644 index 0000000..1e1b281 --- /dev/null +++ b/classes/rule.php @@ -0,0 +1,97 @@ +. + +namespace classes; + +use core\persistent; + +/** + * Rules persistent + * + * @package tool_dynamic_cohorts + * @copyright 2024 Catalyst IT + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class rule extends persistent { + + /** @var string table. */ + const TABLE = 'tool_dynamic_cohorts'; + + /** + * Return the definition of the properties of this model. + * + * @return array + */ + protected static function define_properties() { + return [ + 'name' => [ + 'type' => PARAM_TEXT, + ], + 'description' => [ + 'type' => PARAM_TEXT, + 'default' => null, + 'null' => NULL_ALLOWED, + ], + 'cohortid' => [ + 'type' => PARAM_INT, + 'default' => 0, + ], + 'enabled' => [ + 'type' => PARAM_INT, + 'default' => 0, + ], + 'bulkprocessing' => [ + 'type' => PARAM_INT, + 'default' => 0, + ], + 'broken' => [ + 'type' => PARAM_INT, + 'default' => 0, + ], + ]; + } + + /** + * Get a list of condition records for that rule. + * + * @return condition[] + */ + public function get_condition_records(): array { + $conditions = []; + foreach (condition::get_records(['ruleid' => $this->get('id')], 'position') as $condition) { + $conditions[$condition->get('id')] = $condition; + } + + return $conditions; + } + + /** + * Return if the rule is enabled. + * + * @return bool + */ + public function is_enabled() : bool { + return (bool)$this->get('enabled'); + } + + /** + * Check if this rule should process in bulk. + * @return bool + */ + public function is_bulk_processing(): bool { + return (bool) $this->get('bulkprocessing'); + } +}