Skip to content

Commit 60021f4

Browse files
Readd block_evasys_sync_courses
1 parent 4978bc5 commit 60021f4

7 files changed

+47
-11
lines changed

addcourse.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525
$PAGE->set_context(context_course::instance($id));
2626
$PAGE->set_title(get_string('add_course_header', 'block_evasys_sync'));
2727

28-
$record = $DB->get_record('block_evasys_sync_courseeval', array('course' => $id));
29-
if ($record !== false and (($record->state > \block_evasys_sync\course_evaluation_allocation::STATE_AUTO_NOTOPENED) and
30-
!is_siteadmin() or !get_config('block_evasys_sync', 'default_his_connection'))) {
28+
$evaluation = \block_evasys_sync\evaluation::for_course($id);
29+
if ($evaluation and !is_siteadmin() or !get_config('block_evasys_sync', 'default_his_connection')) {
3130
echo $OUTPUT->header();
3231
echo get_string('forbidden', 'block_evasys_sync');
3332
echo $OUTPUT->footer();

block_evasys_sync.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ public function get_content() {
6767
if ($inlsf) {
6868
$href = new moodle_url('/course/view.php', array('id' => $this->page->course->id, "evasyssynccheck" => true));
6969
$this->content->text .= $OUTPUT->single_button($href, get_string('checkstatus', 'block_evasys_sync'), 'get');
70+
} else {
71+
$this->content->text .= get_string('missing_course_id', 'block_evasys_sync');
7072
}
7173
return $this->content;
7274
}
@@ -191,7 +193,7 @@ public function get_content() {
191193
// If the evaluation hasn't ended yet, display option to restart it.
192194
'startoption' => $startoption,
193195
// Only allow coursemapping before starting an evaluation.
194-
'coursemappingenabled' => false,
196+
'coursemappingenabled' => $hisconnection and (!$startdisabled or is_siteadmin()),
195197
'nostudents' => $nostudents,
196198
'emailsentnotice' => $emailsentnotice,
197199
'evaluationperiodsetnotice' => $periodsetnotice,

classes/evasys_synchronizer.php

+20-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,27 @@ public function get_allocated_courses() {
4545
}
4646
$course = get_course($this->courseid);
4747

48-
$this->evasyscourses = [];
49-
5048
if ($course->idnumber) {
51-
$this->evasyscourses = [$course->idnumber];
49+
$maincourse = $course->idnumber;
50+
}
51+
// Fetch persistent object id.
52+
$pid = $DB->get_field('block_evasys_sync_courses', 'id', array('course' => $this->courseid));
53+
54+
// Get all associated courses.
55+
if (!$pid === false) {
56+
$extras = new \block_evasys_sync\course_evasys_courses_allocation($pid);
57+
$extras = explode('#', $extras->get('evasyscourses'));
58+
} else {
59+
$extras = [];
5260
}
61+
// If noone has associated the course itself, we force that.
62+
if (isset($maincourse) && !empty($maincourse)) {
63+
if (!in_array($maincourse, $extras)) {
64+
$extras[] = $maincourse;
65+
}
66+
}
67+
$extras = array_filter($extras);
68+
$this->evasyscourses = $extras;
5369
return $this->evasyscourses;
5470
}
5571

@@ -110,7 +126,7 @@ public function get_course_name($coursekey) {
110126
if (isset($this->courseinformation[$coursekey])) {
111127
return $this->courseinformation[$coursekey]->m_sCourseTitle;
112128
}
113-
return "Unknown";
129+
return get_string('no_evasys_course_found', 'block_evasys_sync');
114130
}
115131

116132
public function get_raw_course_name($courseid): ?string {

db/install.xml

+14
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@
2323
<KEY NAME="userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id"/>
2424
</KEYS>
2525
</TABLE>
26+
<TABLE NAME="block_evasys_sync_courses" COMMENT="Maps one moodle course to multiple EvaSys-courses">
27+
<FIELDS>
28+
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
29+
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
30+
<FIELD NAME="evasyscourses" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
31+
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
32+
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
33+
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
34+
</FIELDS>
35+
<KEYS>
36+
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
37+
<KEY NAME="survey" TYPE="foreign-unique" FIELDS="course" REFTABLE="course" REFFIELDS="id"/>
38+
</KEYS>
39+
</TABLE>
2640
<TABLE NAME="block_evasys_sync_ereq" COMMENT="Table of outstanding evaluation (change) requests">
2741
<FIELDS>
2842
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>

db/upgrade.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ function xmldb_block_evasys_sync_upgrade ($oldversion) {
487487
$table = new xmldb_table('block_evasys_sync_courses');
488488

489489
// Conditionally launch drop table for block_evasys_sync_courses.
490-
if ($dbman->table_exists($table)) {
490+
/*if ($dbman->table_exists($table)) {
491491
$dbman->drop_table($table);
492-
}
492+
}*/
493493

494494
/// Edit block_evasys_sync_categories ///
495495

lang/de/block_evasys_sync.php

+2
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,5 @@
287287
$string['no_eval_planned'] = 'Es ist keine Evaluation geplant.';
288288
$string['evaluation_will_be_created_for_you'] = 'Eine Evaluation wird für Sie erstellt.';
289289

290+
$string['missing_course_id'] = 'Fehlende Kurs-ID';
291+
$string['no_evasys_course_found'] = 'Kein passender EvaSys-Kurs gefunden';

lang/en/block_evasys_sync.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,7 @@
296296
$string['request_eval'] = 'Request evaluation';
297297

298298
$string['no_eval_planned'] = 'There is no evaluation planned.';
299-
$string['evaluation_will_be_created_for_you'] = 'An evaluation will be created for you.';
299+
$string['evaluation_will_be_created_for_you'] = 'An evaluation will be created for you.';
300+
301+
$string['missing_course_id'] = 'Missing course id';
302+
$string['no_evasys_course_found'] = 'No matching EvaSys-Course found';

0 commit comments

Comments
 (0)