Skip to content

Commit

Permalink
issue #3: add persistent classes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriim committed Mar 4, 2024
1 parent 0ed236b commit 6078abc
Show file tree
Hide file tree
Showing 2 changed files with 153 additions and 0 deletions.
56 changes: 56 additions & 0 deletions classes/condition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace classes;

use core\persistent;

/**
* Conditions persistent class.
*
* @package tool_cohortmanager
* @author Dmitrii Metelkin <[email protected]>
* @copyright 2022 Catalyst IT
* @license http://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,
],
];
}
}
97 changes: 97 additions & 0 deletions classes/rule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

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');
}
}

0 comments on commit 6078abc

Please sign in to comment.