Skip to content

Commit 1a5bda4

Browse files
committed
WIP: move classes to own files
1 parent 9883f33 commit 1a5bda4

15 files changed

+309
-185
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
/**
18+
* Choice instance for ratingallocate.
19+
*
20+
* @package mod_ratingallocate
21+
* @copyright 2025 Tamaro Walter
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace mod_ratingallocate\choice;
26+
27+
use stdClass;
28+
29+
/**
30+
* Kapselt eine Instanz von ratingallocate_choice
31+
*
32+
* @property int $id
33+
* @property int $ratingallocateid
34+
* @property string $title
35+
* @property string explanation
36+
* @property int $maxsize
37+
* @property bool $active
38+
* @property bool $usegroups Whether to restrict the visibility of this choice to the members of specified groups.
39+
*/
40+
class ratingallocate_choice {
41+
/** @var stdClass original db record */
42+
public $dbrecord;
43+
44+
/** Emulates the functionality as if there were explicit records by passing them to the original db record
45+
*
46+
* @param string $name
47+
* @return mixed
48+
*/
49+
public function __get($name) {
50+
return $this->dbrecord->{$name};
51+
}
52+
53+
/** Emulates the functionality as if there were explicit records by passing them to the original db record
54+
*
55+
* @param string $name
56+
* @param mixed $value
57+
*/
58+
public function __set($name, $value) {
59+
$this->dbrecord->{$name} = $value;
60+
}
61+
62+
/**
63+
* Construct.
64+
*
65+
* @param stdClass $record
66+
*/
67+
public function __construct($record) {
68+
$this->dbrecord = $record;
69+
}
70+
71+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
/**
18+
* Choice instance for ratingallocate.
19+
*
20+
* @package mod_ratingallocate
21+
* @copyright 2025 Tamaro Walter
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
25+
namespace mod_ratingallocate\choice;
26+
27+
use stdClass;
28+
29+
/**
30+
* Kapselt eine Instanz von ratingallocate_group_choices.
31+
* (Encapsulating an instance of ratingallocate_group_choices.)
32+
*
33+
* @property int $id
34+
* @property int $choiceid
35+
* @property int $groupid
36+
*/
37+
class ratingallocate_group_choices {
38+
/** @var stdClass original db record */
39+
public $dbrecord;
40+
41+
/**
42+
* Emulates the functionality as if there were explicit records by passing them to the original db record.
43+
*
44+
* @param string $name
45+
* @return mixed
46+
*/
47+
public function __get($name) {
48+
return $this->dbrecord->{$name};
49+
}
50+
51+
/**
52+
* Emulates the functionality as if there were explicit records by passing them to the original db record.
53+
*
54+
* @param string $name
55+
* @param mixed $value
56+
*/
57+
public function __set($name, $value) {
58+
$this->dbrecord->{$name} = $value;
59+
}
60+
61+
/**
62+
* Construct.
63+
*
64+
* @param stdClass $record
65+
*/
66+
public function __construct($record) {
67+
$this->dbrecord = $record;
68+
}
69+
}

classes/choice_importer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2424
*/
2525
namespace mod_ratingallocate;
26+
use mod_ratingallocate\choice\ratingallocate_choice;
2627
use mod_ratingallocate\db as this_db;
2728

2829
defined('MOODLE_INTERNAL') || die();
@@ -237,7 +238,7 @@ public function import($content, $live=true) {
237238

238239
// Create and insert a choice record.
239240
// Note: this will add duplicates if run multiple times.
240-
$choice = new \ratingallocate_choice($recordmap);
241+
$choice = new ratingallocate_choice($recordmap);
241242
$choice->{this_db\ratingallocate_choices::RATINGALLOCATEID} = $this->ratingallocateid;
242243

243244
$recordmap->id = $DB->insert_record(this_db\ratingallocate_choices::TABLE, $choice->dbrecord);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
/**
18+
* Strategymanager for ratingallocate.
19+
*
20+
* @package mod_ratingallocate
21+
* @copyright 2025 Tamaro Walter
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
namespace mod_ratingallocate\manager;
25+
26+
/**
27+
* Simulate a static/singleton class that holds all the strategies that registered with him
28+
*/
29+
class strategymanager {
30+
31+
/** @var array of string-identifier of all registered strategies */
32+
private static $strategies = [];
33+
34+
/**
35+
* Add a strategy to the strategymanager
36+
* @param string $strategyname
37+
*/
38+
public static function add_strategy($strategyname) {
39+
self::$strategies[] = $strategyname;
40+
}
41+
42+
/**
43+
* Get the current list of strategies
44+
* @return array
45+
*/
46+
public static function get_strategies() {
47+
return self::$strategies;
48+
}
49+
50+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
/**
18+
* Wrapper for db-record for ratingallocate.
19+
*
20+
* @package mod_ratingallocate
21+
* @copyright 2025 Tamaro Walter
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
*/
24+
namespace mod_ratingallocate\wrapper;
25+
26+
use stdClass;
27+
28+
/**
29+
* Wrapper for db-record to have IDE autocomplete feature of fields
30+
* @property int $id
31+
* @property int $course
32+
* @property string $name
33+
* @property string $intro
34+
* @property string $strategy
35+
* @property int $accesstimestart
36+
* @property int $accesstimestop
37+
* @property int $publishdate
38+
* @property int $published
39+
* @property int $notificationsend
40+
* @property int $runalgorithmbycron
41+
* @property int $algorithmstarttime
42+
* @property int $algorithmstatus
43+
* -1 failure while running algorithm;
44+
* 0 algorithm has not been running;
45+
* 1 algorithm running;
46+
* 2 algorithm finished;
47+
* @property string $setting
48+
*/
49+
class ratingallocate_db_wrapper {
50+
51+
/** @var stdClass */
52+
public $dbrecord;
53+
54+
/** Emulates the functionality as if there were explicit records by passing them to the original db record
55+
*
56+
* @param string $name
57+
* @return mixed
58+
*/
59+
public function __get($name) {
60+
return $this->dbrecord->{$name};
61+
}
62+
63+
64+
/**
65+
* Emulates the functionality as if there were explicit records by passing them to the original db record
66+
*
67+
* @param string $name
68+
* @param mixed $value
69+
*/
70+
public function __set($name, $value) {
71+
$this->dbrecord->{$name} = $value;
72+
}
73+
74+
/**
75+
* Construct.
76+
*
77+
* @param stdClass $record
78+
*/
79+
public function __construct($record) {
80+
$this->dbrecord = $record;
81+
}
82+
83+
}

form_modify_choice.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use mod_ratingallocate\choice\ratingallocate_choice;
18+
1719
defined('MOODLE_INTERNAL') || die();
1820

1921
global $CFG;

0 commit comments

Comments
 (0)