Skip to content

Commit 4978bc5

Browse files
Adapt sync.php to new db structure
1 parent 2fe7ab3 commit 4978bc5

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

block_evasys_sync.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function get_content() {
191191
// If the evaluation hasn't ended yet, display option to restart it.
192192
'startoption' => $startoption,
193193
// Only allow coursemapping before starting an evaluation.
194-
'coursemappingenabled' => $hisconnection and (!$startdisabled or is_siteadmin()),
194+
'coursemappingenabled' => false,
195195
'nostudents' => $nostudents,
196196
'emailsentnotice' => $emailsentnotice,
197197
'evaluationperiodsetnotice' => $periodsetnotice,

classes/evasys_synchronizer.php

+21-13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
namespace block_evasys_sync;
1818

19+
use block_evasys_sync\local\entity\evaluation_state;
20+
1921
defined('MOODLE_INTERNAL') || die();
2022

2123
require_once($CFG->libdir . '/adminlib.php');
@@ -56,7 +58,6 @@ private function get_course_information() {
5658
foreach ($this->get_allocated_courses() as $course) {
5759
$soapresult = $this->soapclient->GetCourse($course, 'PUBLIC', true, true);
5860
if (is_soap_fault($soapresult)) {
59-
var_dump($soapresult);
6061
// var_dump("soap verbindung nicht funktioniert");
6162
// This happens e.g. if there is no corresponding course in EvaSys.
6263
return null;
@@ -354,26 +355,33 @@ static public function get_assigned_user($course) {
354355
*/
355356
public function set_evaluation_period($dates) : bool {
356357
$usestandardtime = ($dates == 'Standard');
358+
$course = get_course($this->courseid);
357359
if ($usestandardtime) {
358-
$course = get_course($this->courseid);
359360
$dates = self::get_standard_timemode($course->category);
360361
}
361362
$changed = false;
362-
$data = course_evaluation_allocation::get_record_by_course($this->courseid, false);
363+
$data = evaluation::for_course($this->courseid);
363364
if (!$data) {
364-
$data = new course_evaluation_allocation(0);
365-
$data->set('course', $this->courseid);
366-
$data->set('state', course_evaluation_allocation::STATE_MANUAL);
365+
$data = new evaluation();
366+
$data->courses = [$this->courseid];
367+
foreach ($this->courseinformation as $lsfid => $information) {
368+
$data->evaluations[$lsfid] = (object) [
369+
'title' => $this->get_raw_course_name($lsfid),
370+
'lsfid' => $lsfid,
371+
'start' => $dates['start'],
372+
'end' => $dates['end'],
373+
'state' => evaluation_state::MANUAL
374+
];
375+
}
367376
} else {
368-
// Don't display date changed warning on first sync.
369-
if ($data->get('startdate') != $dates['start'] || $data->get('enddate') != $dates['end']) {
370-
$changed = true;
377+
foreach ($data->evaluations as &$evaluation) {
378+
if ($evaluation->start != $dates['start'] || $evaluation['end'] != $dates['end']) {
379+
$changed = true;
380+
$evaluation->start = $dates['start'];
381+
$evaluation->end = $dates['end'];
382+
}
371383
}
372384
}
373-
374-
$data->set('startdate', $dates['start']);
375-
$data->set('enddate', $dates['end']);
376-
$data->set('usestandardtime', $usestandardtime);
377385
$data->save();
378386

379387
return $changed;

sync.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
require_login($courseid);
2424
require_sesskey();
2525

26+
$PAGE->set_url('/blocks/evasys_sync/sync.php');
27+
$DB->get_record('course', array('id' => $courseid), 'id', MUST_EXIST);
28+
29+
$PAGE->set_context(context_course::instance($courseid));
30+
require_capability('block/evasys_sync:synchronize', context_course::instance($courseid));
31+
2632
$returnurl = new moodle_url($CFG->wwwroot . '/course/view.php');
2733
$returnurl->param('id', $courseid);
2834
$returnurl->param('evasyssynccheck', 1);
@@ -80,18 +86,12 @@
8086
$evasyssynchronizer = new \block_evasys_sync\evasys_synchronizer($courseid);
8187
$datechanged = $evasyssynchronizer->set_evaluation_period($dates);
8288
} catch (\dml_missing_record_exception $e) {
83-
debugging($exception);
89+
debugging($e);
8490
$returnurl->param('status', 'failure');
8591
notice(get_string('syncnotpossible', 'block_evasys_sync'), $returnurl);
8692
exit();
8793
}
8894

89-
$PAGE->set_url('/blocks/evasys_sync/sync.php');
90-
$DB->get_record('course', array('id' => $courseid), 'id', MUST_EXIST);
91-
92-
$PAGE->set_context(context_course::instance($courseid));
93-
require_capability('block/evasys_sync:synchronize', context_course::instance($courseid));
94-
9595
try {
9696
if (count_enrolled_users(context_course::instance($courseid), 'block/evasys_sync:mayevaluate') == 0) {
9797
$returnurl->param('status', 'nostudents');
@@ -113,11 +113,11 @@
113113
$event->trigger();
114114

115115
$returnurl->param('status', 'success');
116-
redirect($returnurl, get_string('syncsucessful', 'block_evasys_sync'), 0);
116+
redirect($returnurl, get_string('syncsucessful', 'block_evasys_sync'));
117117
exit();
118118
} else {
119119
$returnurl->param('status', 'uptodate');
120-
redirect($returnurl, get_string('syncalreadyuptodate', 'block_evasys_sync'), 0);
120+
redirect($returnurl, get_string('syncalreadyuptodate', 'block_evasys_sync'));
121121
exit();
122122
}
123123
} catch (Exception $exception) {

0 commit comments

Comments
 (0)