@@ -32,6 +32,8 @@ public function init() {
32
32
*/
33
33
public function get_content () {
34
34
global $ OUTPUT ;
35
+ $ evasyssynccheck = optional_param ('evasyssynccheck ' , 0 , PARAM_BOOL );
36
+ $ status = optional_param ('status ' , "" , PARAM_TEXT );
35
37
36
38
// Return cached content if there is any.
37
39
if ($ this ->content !== null ) {
@@ -47,40 +49,160 @@ public function get_content() {
47
49
return $ this ->content ;
48
50
}
49
51
52
+ // If there has been a status in the url, show the prompt.
53
+ $ this ->display_status ($ status );
54
+
50
55
$ evasyscategory = \block_evasys_sync \evasys_category::for_course ($ this ->page ->course );
56
+
51
57
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
+ }
52
71
return $ this ->content ;
53
72
}
54
73
55
74
$ evalrequest = \block_evasys_sync \evaluation_request::for_course ($ this ->page ->course ->id );
56
75
$ evaluations = \block_evasys_sync \evaluation::for_course ($ this ->page ->course ->id );
57
76
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 );
59
110
60
111
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 ;
66
160
}
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 ;
82
164
}
165
+
166
+ $ course ['surveys ' ] = $ surveys ;
167
+ // Append this course.
168
+ $ courses [] = $ course ;
83
169
}
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 = '' ;
84
206
return $ this ->content ;
85
207
}
86
208
0 commit comments