Skip to content

Commit 6078abc

Browse files
committed
issue #3: add persistent classes
1 parent 0ed236b commit 6078abc

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

classes/condition.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace classes;
18+
19+
use core\persistent;
20+
21+
/**
22+
* Conditions persistent class.
23+
*
24+
* @package tool_cohortmanager
25+
* @author Dmitrii Metelkin <[email protected]>
26+
* @copyright 2022 Catalyst IT
27+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28+
*/
29+
class condition extends persistent {
30+
31+
/** @var string table. */
32+
const TABLE = 'tool_dynamic_cohorts_c';
33+
34+
/**
35+
* Return the definition of the properties of this model.
36+
*
37+
* @return array
38+
*/
39+
protected static function define_properties() {
40+
return [
41+
'ruleid' => [
42+
'type' => PARAM_INT,
43+
],
44+
'classname' => [
45+
'type' => PARAM_TEXT,
46+
],
47+
'configdata' => [
48+
'type' => PARAM_RAW,
49+
'default' => '{}',
50+
],
51+
'sortorder' => [
52+
'type' => PARAM_INT,
53+
],
54+
];
55+
}
56+
}

classes/rule.php

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
namespace classes;
18+
19+
use core\persistent;
20+
21+
/**
22+
* Rules persistent
23+
*
24+
* @package tool_dynamic_cohorts
25+
* @copyright 2024 Catalyst IT
26+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27+
*/
28+
class rule extends persistent {
29+
30+
/** @var string table. */
31+
const TABLE = 'tool_dynamic_cohorts';
32+
33+
/**
34+
* Return the definition of the properties of this model.
35+
*
36+
* @return array
37+
*/
38+
protected static function define_properties() {
39+
return [
40+
'name' => [
41+
'type' => PARAM_TEXT,
42+
],
43+
'description' => [
44+
'type' => PARAM_TEXT,
45+
'default' => null,
46+
'null' => NULL_ALLOWED,
47+
],
48+
'cohortid' => [
49+
'type' => PARAM_INT,
50+
'default' => 0,
51+
],
52+
'enabled' => [
53+
'type' => PARAM_INT,
54+
'default' => 0,
55+
],
56+
'bulkprocessing' => [
57+
'type' => PARAM_INT,
58+
'default' => 0,
59+
],
60+
'broken' => [
61+
'type' => PARAM_INT,
62+
'default' => 0,
63+
],
64+
];
65+
}
66+
67+
/**
68+
* Get a list of condition records for that rule.
69+
*
70+
* @return condition[]
71+
*/
72+
public function get_condition_records(): array {
73+
$conditions = [];
74+
foreach (condition::get_records(['ruleid' => $this->get('id')], 'position') as $condition) {
75+
$conditions[$condition->get('id')] = $condition;
76+
}
77+
78+
return $conditions;
79+
}
80+
81+
/**
82+
* Return if the rule is enabled.
83+
*
84+
* @return bool
85+
*/
86+
public function is_enabled() : bool {
87+
return (bool)$this->get('enabled');
88+
}
89+
90+
/**
91+
* Check if this rule should process in bulk.
92+
* @return bool
93+
*/
94+
public function is_bulk_processing(): bool {
95+
return (bool) $this->get('bulkprocessing');
96+
}
97+
}

0 commit comments

Comments
 (0)