Skip to content

Commit 2fe7ab3

Browse files
First try of old design
1 parent 6c6ffa6 commit 2fe7ab3

File tree

2 files changed

+144
-21
lines changed

2 files changed

+144
-21
lines changed

block_evasys_sync.php

Lines changed: 143 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function init() {
3232
*/
3333
public function get_content() {
3434
global $OUTPUT;
35+
$evasyssynccheck = optional_param('evasyssynccheck', 0, PARAM_BOOL);
36+
$status = optional_param('status', "", PARAM_TEXT);
3537

3638
// Return cached content if there is any.
3739
if ($this->content !== null) {
@@ -47,40 +49,160 @@ public function get_content() {
4749
return $this->content;
4850
}
4951

52+
// If there has been a status in the url, show the prompt.
53+
$this->display_status($status);
54+
5055
$evasyscategory = \block_evasys_sync\evasys_category::for_course($this->page->course);
56+
5157
if (!$evasyscategory) {
58+
$this->content->text = 'This course isn\'t inside any evaluation category!';
59+
return $this->content;
60+
}
61+
62+
// If we are not in sync mode, we display either the course mapping or the check status button.
63+
if ($evasyssynccheck !== 1) {
64+
$inlsf = !empty($this->page->course->idnumber);
65+
66+
// Display the check status button.
67+
if ($inlsf) {
68+
$href = new moodle_url('/course/view.php', array('id' => $this->page->course->id, "evasyssynccheck" => true));
69+
$this->content->text .= $OUTPUT->single_button($href, get_string('checkstatus', 'block_evasys_sync'), 'get');
70+
}
5271
return $this->content;
5372
}
5473

5574
$evalrequest = \block_evasys_sync\evaluation_request::for_course($this->page->course->id);
5675
$evaluations = \block_evasys_sync\evaluation::for_course($this->page->course->id);
5776

58-
$stringformat = get_string('strftimedatetime', 'langconfig');
77+
$categoryhasstandardtime = $evasyscategory->default_period_set();
78+
// Only use standardtime js if no record exists.
79+
if (!$evaluations) {
80+
$this->page->requires->js_call_amd('block_evasys_sync/standardtime', 'init');
81+
}
82+
83+
$evasyssynchronizer = new block_evasys_sync\evasys_synchronizer($this->page->course->id);
84+
try {
85+
$evasyscourses = $evasyssynchronizer->get_allocated_courses();
86+
} catch (Exception $exception) {
87+
\core\notification::warning(get_string('syncnotpossible', 'block_evasys_sync'));
88+
$this->content->text .= html_writer::div(get_string('syncnotpossible', 'block_evasys_sync'));
89+
return $this->content;
90+
}
91+
92+
$href = new moodle_url('/blocks/evasys_sync/sync.php');
93+
94+
// Initialize data for mustache template.
95+
$startdisabled = false;
96+
$enddisabled = false;
97+
$emailsentnotice = false;
98+
$periodsetnotice = false;
99+
100+
// Set start to today and end to a week from now.
101+
$start = time();
102+
$oneweeklater = $time = new \DateTime();
103+
$oneweeklater->add(new \DateInterval("P7D"));
104+
$end = $oneweeklater->getTimestamp();
105+
106+
// See if there are any students that can evaluate.
107+
// If there are no students we disable all controls.
108+
$nostudents = (count_enrolled_users(
109+
context_course::instance($this->page->course->id), 'block/evasys_sync:mayevaluate') == 0);
59110

60111
if ($evaluations) {
61-
$this->content->text .= html_writer::tag('h5', get_string('evaluations', 'block_evasys_sync'));
62-
foreach ($evaluations->evaluations as $evaluation) {
63-
$this->content->text .= html_writer::tag('p', '<b>' . $evaluation->title . '</b><br>' .
64-
get_string('startondate', 'block_evasys_sync') . ': ' . userdate($evaluation->start, $stringformat) . '<br>' .
65-
get_string('endondate', 'block_evasys_sync') . ': ' . userdate($evaluation->end, $stringformat));
112+
$emailsentnotice = true;
113+
$first = array_key_first($evaluations->evaluations);
114+
$start = $evaluations->evaluations[$first]->start;
115+
$end = $evaluations->evaluations[$first]->end;
116+
} elseif ($evasyscategory->default_period_set()) {
117+
$start = $evasyscategory->get('standard_time_start');
118+
$end = $evasyscategory->get('standard_time_end');
119+
}
120+
121+
// This javascript module sets the start and end fields to the correct values.
122+
$jsmodestring = 'manual';
123+
$jsmodestring .= $enddisabled ? '_closed' : '_open';
124+
$this->page->requires->js_call_amd('block_evasys_sync/initialize', 'init', array($start, $end, $jsmodestring));
125+
126+
127+
// Initialize variables to pass to mustache.
128+
$courses = array();
129+
$hassurveys = false;
130+
$startoption = ($startdisabled xor $enddisabled);
131+
$warning = false;
132+
$invalidcourses = false;
133+
// Query course data (put in function).
134+
foreach ($evasyscourses as $evasyscourseinfo) {
135+
$course = array();
136+
$course['evasyscoursetitle'] = $evasyssynchronizer->get_course_name($evasyscourseinfo);
137+
$course['technicalid'] = $evasyssynchronizer->get_course_id($evasyscourseinfo);
138+
$course['evasyscourseid'] = $evasyscourseinfo;
139+
$course['c_participants'] = format_string($evasyssynchronizer->get_amount_participants($evasyscourseinfo));
140+
$rawsurveys = $evasyssynchronizer->get_surveys($evasyscourseinfo);
141+
$surveys = array();
142+
foreach ($rawsurveys as $rawsurvey) {
143+
$survey = array();
144+
$survey['formName'] = format_string($rawsurvey->formName);
145+
$survey['surveystatus'] = get_string('surveystatus' . $rawsurvey->surveyStatus, 'block_evasys_sync');
146+
$survey['amountOfCompleteForms'] = format_string($rawsurvey->amountOfCompletedForms);
147+
148+
if (!$evaluations && $rawsurvey->surveyStatus == 'closed') {
149+
// In case of a manual evaluation get the status of the evaluation by...
150+
// checking whether the evaluations are closed.
151+
$emailsentnotice = false;
152+
$startdisabled = true;
153+
$enddisabled = true;
154+
$startoption = true;
155+
}
156+
157+
// Append this survey.
158+
$surveys[] = $survey;
159+
$hassurveys = true;
66160
}
67-
} else if ($evalrequest) {
68-
$this->content->text .= '<p>Request pending approval: </p><pre>' . json_encode($evalrequest, JSON_PRETTY_PRINT) . '</pre>';
69-
$this->content->text .= html_writer::link(
70-
new moodle_url('/blocks/evasys_sync/evalrequest.php', ['cid' => $this->page->course->id]),
71-
'Change evaluation request', ['class' => 'btn btn-secondary']
72-
);
73-
} else {
74-
$this->content->text .= html_writer::tag('p', get_string('no_eval_planned', 'block_evasys_sync'));
75-
if ($evasyscategory->can_teacher_request_evaluation()) {
76-
$this->content->text .= html_writer::link(
77-
new moodle_url('/blocks/evasys_sync/evalrequest.php', ['cid' => $this->page->course->id]),
78-
get_string('request_eval', 'block_evasys_sync'), ['class' => 'btn btn-primary']
79-
);
80-
} else {
81-
$this->content->text .= html_writer::tag('p', get_string('evaluation_will_be_created_for_you', 'block_evasys_sync'));
161+
// If any course has an unkown technical id, we don't want to allow synchronization.
162+
if ($course['technicalid'] == "Unknown") {
163+
$invalidcourses = true;
82164
}
165+
166+
$course['surveys'] = $surveys;
167+
// Append this course.
168+
$courses[] = $course;
83169
}
170+
171+
$standardttimemode = !$evaluations && $categoryhasstandardtime;
172+
$hisconnection = get_config('block_evasys_sync', 'default_his_connection');
173+
174+
// Create the data object for the mustache table.
175+
$data = array(
176+
'href' => $href,
177+
'sesskey' => sesskey(),
178+
'courseid' => $this->page->course->id,
179+
'courses' => $courses,
180+
/* In case of the manual workflow, we can start synchronisation also, if no surveys are registered, yet.
181+
* In case of the automated workflow, we require surveys
182+
* in order to be able to automatically trigger the evaluation. */
183+
'showcontrols' => count($evasyscourses) > 0 && !$invalidcourses,
184+
'usestandardtimelayout' => $standardttimemode,
185+
// Choose mode.
186+
'direct' => false,
187+
'startdisabled' => $startdisabled || $standardttimemode,
188+
'enddisabled' => $enddisabled || $standardttimemode,
189+
'onlyend' => $startdisabled && !$standardttimemode,
190+
'disablesubmit' => $enddisabled,
191+
// If the evaluation hasn't ended yet, display option to restart it.
192+
'startoption' => $startoption,
193+
// Only allow coursemapping before starting an evaluation.
194+
'coursemappingenabled' => $hisconnection and (!$startdisabled or is_siteadmin()),
195+
'nostudents' => $nostudents,
196+
'emailsentnotice' => $emailsentnotice,
197+
'evaluationperiodsetnotice' => $periodsetnotice,
198+
// Defines if an lsf course is already mapped to the moodle course.
199+
'optional' => !empty($evasyscourses),
200+
// Outputs a warning that there are open course when there shouldn't.
201+
'warning' => $warning
202+
);
203+
204+
$this->content->text .= $OUTPUT->render_from_template("block_evasys_sync/block", $data);
205+
$this->content->footer = '';
84206
return $this->content;
85207
}
86208

classes/evasys_synchronizer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ private function get_course_information() {
5656
foreach ($this->get_allocated_courses() as $course) {
5757
$soapresult = $this->soapclient->GetCourse($course, 'PUBLIC', true, true);
5858
if (is_soap_fault($soapresult)) {
59+
var_dump($soapresult);
5960
// var_dump("soap verbindung nicht funktioniert");
6061
// This happens e.g. if there is no corresponding course in EvaSys.
6162
return null;

0 commit comments

Comments
 (0)