Skip to content

Commit 5823cb8

Browse files
Remove code for automatic mode, rename evasys_category and add mode_flags to evasys category
1 parent 7f4dd55 commit 5823cb8

13 files changed

+69
-311
lines changed

adminsettings.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
if (!empty($delid) && !empty($confirm)) {
3838
// Course category user is deleted.
39-
$persistent = new \block_evasys_sync\user_cat_allocation($delid);
39+
$persistent = new \block_evasys_sync\evasys_category($delid);
4040
$persistent->delete();
4141

4242
redirect($PAGE->url);
@@ -68,7 +68,8 @@
6868
} else {
6969
$record->category_mode = 0;
7070
}
71-
$persistent = new \block_evasys_sync\user_cat_allocation(0, $record);
71+
$record->mode_flags = 0;
72+
$persistent = new \block_evasys_sync\evasys_category(0, $record);
7273
$persistent->create();
7374

7475
redirect($PAGE->url);
@@ -101,7 +102,7 @@
101102
set_config('default_his_connection', 0, 'block_evasys_sync');
102103
}
103104

104-
$records = \block_evasys_sync\user_cat_allocation::get_records();
105+
$records = \block_evasys_sync\evasys_category::get_records();
105106
foreach ($records as $allocation) {
106107
$newvalue = 'category_' . $allocation->get('id');
107108
$oldvalue = $allocation->get('userid');

amd/src/invite_manager.js

-108
This file was deleted.

block_evasys_sync.php

+11-35
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,11 @@ public function get_content() {
7777
}
7878
return $this->content;
7979
}
80-
$ismodeautomated = (bool)\block_evasys_sync\evasys_inviter::getmode($this->page->course->category);
81-
// If the teacher can start the evaluation directly, we'll want to run some javascript initialization.
82-
if ($ismodeautomated) {
83-
$this->page->requires->js_call_amd('block_evasys_sync/invite_manager', 'init');
84-
} else {
85-
$categoryhasstandardtime = \block_evasys_sync\evasys_synchronizer::get_standard_timemode($this->page->course->category);
80+
$categoryhasstandardtime = \block_evasys_sync\evasys_synchronizer::get_standard_timemode($this->page->course->category);
8681

87-
// Only use standardtime js if no record exists.
88-
if (!$record) {
89-
$this->page->requires->js_call_amd('block_evasys_sync/standardtime', 'init');
90-
}
82+
// Only use standardtime js if no record exists.
83+
if (!$record) {
84+
$this->page->requires->js_call_amd('block_evasys_sync/standardtime', 'init');
9185
}
9286
$evasyssynchronizer = new \block_evasys_sync\evasys_synchronizer($this->page->course->id);
9387
try {
@@ -98,12 +92,7 @@ public function get_content() {
9892
return $this->content;
9993
}
10094

101-
if ($ismodeautomated) {
102-
$href = new moodle_url('/course/view.php',
103-
array('id' => $this->page->course->id, "evasyssynccheck" => true));
104-
} else {
105-
$href = new moodle_url('/blocks/evasys_sync/sync.php');
106-
}
95+
$href = new moodle_url('/blocks/evasys_sync/sync.php');
10796

10897
// Initialize data for mustache template.
10998
$startdisabled = false;
@@ -130,33 +119,20 @@ public function get_content() {
130119
// If the persistenceclass exists and the state is manual an email must have been sent.
131120
$emailsentnotice = true;
132121
}
133-
if ($state == course_evaluation_allocation::STATE_AUTO_NOTOPENED) {
134-
// If the persistenceclass exists and the state is automatic and not opened
135-
// the period must have been set.
136-
$periodsetnotice = true;
137-
}
138-
if ($state >= course_evaluation_allocation::STATE_AUTO_OPENED || $nostudents) {
139-
// If the course was already opened, disable the start date. If there are no students disable all controls.
140-
$startdisabled = true;
141-
}
142-
if ($state == course_evaluation_allocation::STATE_AUTO_CLOSED || $nostudents) {
143-
// If the course was already closed, disable the end date. If there are no students disable all controls.
144-
$enddisabled = true;
145-
}
146122
// If there is a record the period has been set at least once.
147123
// Set start and end to match the period that had been set.
148124
$start = $record->get('startdate');
149125
$end = $record->get('enddate');
150126
$recordhasstandardtime = $record->get('usestandardtime');
151127
} else {
152-
if (!$ismodeautomated && $categoryhasstandardtime) {
128+
if ($categoryhasstandardtime) {
153129
$start = $categoryhasstandardtime['start'];
154130
$end = $categoryhasstandardtime['end'];
155131
$recordhasstandardtime = true;
156132
}
157133
}
158134
// This javascript module sets the start and end fields to the correct values.
159-
$jsmodestring = $ismodeautomated ? 'automated' : 'manual';
135+
$jsmodestring = 'manual';
160136
$jsmodestring .= $enddisabled ? '_closed' : '_open';
161137
$this->page->requires->js_call_amd('block_evasys_sync/initialize', 'init', array($start, $end, $jsmodestring));
162138

@@ -212,7 +188,7 @@ public function get_content() {
212188
$courses[] = $course;
213189
}
214190

215-
$standardttimemode = (!$ismodeautomated && $recordhasstandardtime && !$record);
191+
$standardttimemode = ($recordhasstandardtime && !$record);
216192
$hisconnection = get_config('block_evasys_sync', 'default_his_connection');
217193

218194
// Create the data object for the mustache table.
@@ -224,10 +200,10 @@ public function get_content() {
224200
/* In case of the manual workflow, we can start synchronisation also, if no surveys are registered, yet.
225201
* In case of the automated workflow, we require surveys
226202
* in order to be able to automatically trigger the evaluation. */
227-
'showcontrols' => ($hassurveys || !$ismodeautomated) && count($evasyscourses) > 0 && !$invalidcourses,
228-
'usestandardtimelayout' => (!$ismodeautomated && $recordhasstandardtime && !$record),
203+
'showcontrols' => ($hassurveys) && count($evasyscourses) > 0 && !$invalidcourses,
204+
'usestandardtimelayout' => ($recordhasstandardtime && !$record),
229205
// Choose mode.
230-
'direct' => $ismodeautomated,
206+
'direct' => false,
231207
'startdisabled' => $startdisabled || $standardttimemode,
232208
'enddisabled' => $enddisabled || $standardttimemode,
233209
'onlyend' => $startdisabled && !$standardttimemode,

classes/admin_form.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private function table_body() {
225225
* @return array
226226
*/
227227
private function getrecords() {
228-
$records = \block_evasys_sync\user_cat_allocation::get_records();
228+
$records = \block_evasys_sync\evasys_category::get_records();
229229
return $records;
230230
}
231231

@@ -282,7 +282,7 @@ public function validation($data, $files) {
282282
$errors = parent::validation($data, $files);
283283

284284
// Validate user ids.
285-
$records = \block_evasys_sync\user_cat_allocation::get_records();
285+
$records = \block_evasys_sync\evasys_category::get_records();
286286
foreach ($records as $allocation) {
287287

288288
$newvalue = 'category_' . $allocation->get('id');

classes/eval_request.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static function from_id(int $id): eval_request {
8686
return $evalrequest;
8787
}
8888

89-
public static function get_evasyscategory_for($course) {
89+
private static function get_evasyscategory_for($course) {
9090
global $DB;
9191

9292
$record = $DB->get_record('block_evasys_sync_categories', array('course_category' => $course->category));
@@ -103,7 +103,6 @@ public static function get_evasyscategory_for($course) {
103103
}
104104
}
105105
return null;
106-
107106
}
108107

109108
private function update_generated_fields() {
@@ -118,7 +117,7 @@ private function update_generated_fields() {
118117
$this->courseid = $this->courses[0];
119118
}
120119
if (!isset($this->evasyscategoryid)) {
121-
$this->evasyscategoryid = self::get_evasyscategory_for(get_course($this->courseid))->id ?? null;
120+
$this->evasyscategoryid = evasys_category::for_course(get_course($this->courseid))->get('id') ?? null;
122121
}
123122
}
124123

classes/eval_request_manager.php

-32
This file was deleted.

classes/evalcat_manager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private function __construct() {
4343
}
4444

4545
private function load_categories() {
46-
$records = user_cat_allocation::get_records();
46+
$records = evasys_category::get_records();
4747

4848
$categories = [];
4949
foreach ($records as $record) {

classes/user_cat_allocation.php classes/evasys_category.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@
3434
* @copyright 2017 Tamara Gunkel
3535
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3636
*/
37-
class user_cat_allocation extends persistent {
37+
class evasys_category extends persistent {
3838

3939
const TABLE = 'block_evasys_sync_categories';
4040

41+
const MASK_TEACHER_CAN_REQUEST_EVALUATION = 1 << 0;
42+
const MASK_EVALUATION_REQUEST_NEEDS_APPROVAL = 1 << 1;
43+
const MASK_TEACHER_CAN_CHANGE_EVALUATION = 1 << 2;
44+
const MASK_EVALUATION_CHANGE_NEEDS_APPROVAL = 1 << 3;
45+
4146
/**
4247
* Return the definition of the properties of this model.
4348
*
@@ -57,6 +62,9 @@ protected static function define_properties() {
5762
'type' => PARAM_INT,
5863
'message' => new \lang_string('invalidmode', 'block_evasys_sync')
5964
),
65+
'mode_flags' => array(
66+
'type' => PARAM_INT
67+
),
6068
'standard_time_start' => array (
6169
'type' => PARAM_INT,
6270
'message' => new \lang_string('invalid_standard_time_mode', 'block_evasys_sync'),
@@ -72,6 +80,23 @@ protected static function define_properties() {
7280
);
7381
}
7482

83+
public static function for_course($course): ?evasys_category {
84+
$record = evasys_category::get_record(['course_category' => $course->category]);
85+
if ($record) {
86+
return $record;
87+
}
88+
// Loop through parents.
89+
$parents = \core_course_category::get($course->category)->get_parents();
90+
for ($i = count($parents) - 1; $i >= 0; $i--) {
91+
$record = evasys_category::get_record(['course_category' => $parents[$i]]);
92+
// Stop if a parent has been assigned a custom record.
93+
if ($record) {
94+
return $record;
95+
}
96+
}
97+
return null;
98+
}
99+
75100
/**
76101
* Validate the user ID.
77102
*
@@ -84,4 +109,8 @@ protected function validate_userid($value) {
84109
}
85110
return true;
86111
}
112+
113+
public function can_teacher_request_evaluation() : bool {
114+
return $this->get('mode_flags') & self::MASK_TEACHER_CAN_REQUEST_EVALUATION;
115+
}
87116
}

db/install.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
2-
<XMLDB PATH="blocks/evasys_sync/db" VERSION="20220924" COMMENT="XMLDB file for Moodle blocks/evasys_sync"
2+
<XMLDB PATH="blocks/evasys_sync/db" VERSION="20221213" COMMENT="XMLDB file for Moodle blocks/evasys_sync"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
55
>
@@ -9,6 +9,7 @@
99
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
1010
<FIELD NAME="course_category" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
1111
<FIELD NAME="category_mode" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
12+
<FIELD NAME="mode_flags" TYPE="int" LENGTH="11" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="See evasys_category for explanation."/>
1213
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
1314
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
1415
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>

0 commit comments

Comments
 (0)