view_competency_iena_competencies.php 13.3 KB
Newer Older
Thomas Fradet's avatar
folder  
Thomas Fradet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php

class view_competency_iena_competencies
{

	public function get_content($studentid)
	{

		global $COURSE, $USER, $CFG;

		$studentI = new block_competency_iena_student();
		$students = $studentI->get_all_students_by_course($COURSE->id);
		$studentI->get_student_by_id($studentid);

		$content = false;
		$link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies.php?courseid=' . $COURSE->id . '&studentid=';
		$content .= "
		<link rel=\"stylesheet\" type=\"text/css\" href=\"https://cdn.datatables.net/1.10.16/css/jquery.dataTables.css\">

		<h3>$studentI->lastname $studentI->firstname </h3>

		";

		if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
			$content .= "
			<div class='centered'>
			<span class=\"myarrow\"><input list=\"browsers\" id=\"myBrowser\" name=\"myBrowser\" placeholder='$studentI->lastname $studentI->firstname' /></span>
			<datalist id=\"browsers\">
			";
			foreach ($students as $item) {
				$content .= "<option data-value='$link$item->id'  value='$item->lastname $item->firstname'></option>";
			}

			$content .= "
			</datalist>
			</div>";
		}

		// liste des compétences avec toutes les infos
		// TODO : traduire l'évaluation numérique en échelle
Thomas Fradet's avatar
Thomas Fradet committed
41
		
Thomas Fradet's avatar
folder  
Thomas Fradet committed
42
43
		$competencies = new block_competency_iena_competency();
		$cpts = $competencies->get_competencies_by_userID($studentid);
Thomas Fradet's avatar
Thomas Fradet committed
44
45
46
47
48





Thomas Fradet's avatar
folder  
Thomas Fradet committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
		// var_dump($cpts);

		// entête de la table
		$content .= "
		<table id=\"example\" class=\"display\" style=\"width:100%\">
		<thead>
		<tr>
		<th>" . get_string('competency', 'block_competency_iena') . "</th>
		<th>" . get_string('status', 'block_competency_iena') . "</th>
		<th>" . get_string('competent', 'block_competency_iena') . "</th>
		<th>" . get_string('eval', 'block_competency_iena') . "</th>
		<th>" . get_string('modules', 'block_competency_iena') . "</th>
		<th>" . get_string('action', 'block_competency_iena') . "</th>
		</tr>
		";


		// FILTRES DE LA TABLE

		$content .= "
		<tr> <div class=\"form-group\">
		<th></th>
		<th></th>
		<th><select class='form-control' style='width:auto; height:auto;' id=\"filter-competent\">
		<option value=\"\">" . get_string('all', 'block_competency_iena') . "</option>
		";
		$proficiencies_names = [];
		foreach ($cpts as $cpt) {
			array_push($proficiencies_names, $cpt->proficiencyname);
		}
		$proficiencies_names = array_unique($proficiencies_names);
		foreach ($proficiencies_names as $proficiency_name) {
			$content .= "<option>$proficiency_name</option>";
		}
		$content .= "
		</select></th>
		<th><select  class='form-control' id=\"filter-evaluation\" style='width:auto; height:auto;'>
		<option value=\"\">" . get_string('all', 'block_competency_iena') . "</option>
		";
		$grades_names = [];
		foreach ($cpts as $cpt) {
			array_push($grades_names, $cpt->gradename);
		}
		$grades_names = array_unique($grades_names);
		foreach ($grades_names as $grade_name) {
			$content .= "<option>$grade_name</option>";
		}
		$content .= "
		</select></th>
		<th><select  class='form-control' id=\"filter-module\" style='width:auto; height:auto;'>
		<option value=\"\">" . get_string('all', 'block_competency_iena') . "</option>
		<option value=\"0\">0%</option>
		<option value=\"<50\">&lt; 50%</option>
		<option value=\">=50\">&gt;= 50%</option>
		<option value=\"100\">100%</option>
		</select>
		</th>
		<th></th>
		</div> </tr>
		</thead>";

		// corps de la table
		$content .= "<tbody>";

		foreach ($cpts as $cpt) {

			// rapport de complétion des activités liées
			// $pourcent = count($cpt->cms) == 0 ? 0 : count($cpt->cpl_cms) / count($cpt->cms);
			$pourcent = $cpt->cms == 0 ? 0 : ($cpt->cpl_cms / $cpt->cms)*100;

			// ajout d'un espace pour chaque niveau de profondeur d'une cpt dans le référentiel
			$level = "";
			for ( $i = 0; $i < $cpt->framework_level; $i++ ) { 
				$level .= "&nbsp;&nbsp;";
			}

			// lien vers la page cpt x user x cours
			$user_cpts_page = $CFG->wwwroot . "/blocks/competency_iena/competency_iena_user.php?courseid=" . $COURSE->id . "&competencyid=" . $cpt->cpt_id . "&studentid=" . $studentid;
			// lien vers le tableau inverse ( cpt x users )
			$cpt_users_page = $CFG->wwwroot . "/blocks/competency_iena/competency_iena_competency_students.php?courseid=" . $COURSE->id . "&competencyid=" . $cpt->cpt_id;

			// validation demandée par l'étudiant
			$status = $cpt->val_asked == 1 ? "Validation demandée" : "";

			// nombre de modules liées et parmis eux achevés
			$modules_ok = $cpt->cpl_cms;
			$modules_total = $cpt->cms;

			$content .= "<tr data-percent='$pourcent' class='pourcent-$pourcent all-pourcent'>
			<td>$level $cpt->cpt_shortname</td>
			<td><span class=\"label label-success\">$status</span></td>
			<td>$cpt->proficiencyname</td>
			<td>$cpt->gradename</td>
			<td>$modules_ok/$modules_total</td>
			<td>
			<a href=\"$user_cpts_page\">
			<i class=\"fa fa-user\" style=\"margin-right: 25px; color: black; font-size:24px\"></i>
			</a>
			";
			if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
				$content .= "
				<a href=\"$cpt_users_page\">
				<i class=\"fa fa-users\" style=\"margin-right: 25px;color: black;font-size:24px\"></i>
				</a> ";
			}

			$content .= "</td></tr>";

		}

		$content .= "</tbody></table>";









		// $module_instance = new block_competency_iena_module();
		// $tab_aff_grade = array();
		// $tab_aff_proficient = array();
		// foreach ($tabcompetencies as $competency) {
		// 	$data = $competencies->get_data($studentid, $competency->id, $COURSE->id);
		// 	if ($data->usercompetencysummary->usercompetencycourse->gradename != '-') {
		// 		array_push($tab_aff_grade, $data->usercompetencysummary->usercompetencycourse->gradename);
		// 	} else {
		// 		array_push($tab_aff_grade, get_string('no_evalued', 'block_competency_iena'));
		// 	}
		// 	array_push($tab_aff_proficient, $data->usercompetencysummary->usercompetencycourse->proficiencyname);
		// }
		// $tab_aff_grade = array_unique($tab_aff_grade);
		// $tab_aff_proficient = array_unique($tab_aff_proficient);

		// $content .= "


		// ";

		// $content .= "
		// <table id=\"example\" class=\"display\" style=\"width:100%\">
		// <thead>
		// <tr>
		// <th>" . get_string('competency', 'block_competency_iena') . "</th>
		// <th>" . get_string('status', 'block_competency_iena') . "</th>
		// <th>" . get_string('competent', 'block_competency_iena') . "</th>
		// <th>" . get_string('eval', 'block_competency_iena') . "</th>
		// <th>" . get_string('modules', 'block_competency_iena') . "</th>
		// <th>" . get_string('action', 'block_competency_iena') . "</th>
		// </tr>
		// ";







		// $content .= "

		// <tr> <div class=\"form-group\">
		// <th></th>
		// <th></th>
		// <th><select class='form-control' style='width:auto; height:auto;' id=\"filter-competent\">
		// <option value=\"\">" . get_string('all', 'block_competency_iena') . "</option>
		// ";
		// foreach ($tab_aff_proficient as $value) {
		// 	$content .= "<option>$value</option>";
		// }
		// $content .= "
		// </select></th>
		// <th><select  class='form-control' id=\"filter-evaluation\" style='width:auto; height:auto;'>
		// <option value=\"\">" . get_string('all', 'block_competency_iena') . "</option>
		// ";
		// foreach ($tab_aff_grade as $value) {
		// 	$content .= "<option>$value</option>";
		// }
		// $content .= "
		// </select></th>
		// <th><select  class='form-control' id=\"filter-module\" style='width:auto; height:auto;'>
		// <option value=\"\">" . get_string('all', 'block_competency_iena') . "</option>
		// <option value=\"0\">0%</option>
		// <option value=\"25\">< 50%</option>
		// <option value=\"50\">50%</option>
		// <option value=\"100\">100%</option>
		// </select>
		// </th>
		// <th></th>
		// </div> </tr>
		// </thead>

		// <tbody>

		// ";
		// foreach ($tabcompetencies as $competency) {
		// 	$data = $competencies->get_data($studentid, $competency->id, $COURSE->id);
		// 	$status = $competencies->get_status_by_competenceid($competency->id, $studentid);
		// 	$competency->student_proficiency = $data->usercompetencysummary->usercompetencycourse->proficiencyname;
		// 	$competency->student_grade = $data->usercompetencysummary->usercompetencycourse->gradename;
		// 	if ($competency->student_grade == '-') {
		// 		$competency->student_grade = get_string('no_evalued', 'block_competency_iena');
		// 	}
		// 		//var_dump($data->usercompetencysummary->competency->competency->path);echo '<hr>';
		// 	$nb_position = explode('/', $data->usercompetencysummary->competency->competency->path);
		// 	$indic = 0;
		// 	$signe = "";
		// 	foreach ($nb_position as $value) {
		// 		if ($value != "") {
		// 			$indic++;
		// 			$signe .= ">";
		// 		}
		// 	}
		// 	$module_comp = $module_instance->get_modules_by_competencyID($competency->id);
		// 	$nbmoduleOk = $module_instance->get_nb_module_ok_by_userid_competenceid($competency->id, $studentid, $COURSE->id);
		// 	$nb_comp = count($module_comp);

		// 	$pourcent = $nbmoduleOk * 100 / $nb_comp;
		// 	if (is_nan($pourcent)) {
		// 		$pourcent = 0;
		// 	}
		// 	if ($pourcent > 0 && $pourcent < 50) {
		// 		$pourcent = 25;
		// 	}
		// 	$linkStudentsCompetence = $CFG->wwwroot . "/blocks/competency_iena/competency_iena_competency_students.php?courseid=" . $COURSE->id . "&competencyid=" . $competency->id;
		// 	$linkCompetence = $CFG->wwwroot . "/blocks/competency_iena/competency_iena_user.php?courseid=" . $COURSE->id . "&competencyid=" . $competency->id;
		// 	$competency->shortname = str_replace('"', "", $competency->shortname);
		// 	$competency->shortname = str_replace("'", "", $competency->shortname);
		// 	$content .= "<tr class='pourcent-$pourcent all-pourcent'>
		// 	<td>$signe $competency->shortname</td>
		// 	<td><span class=\"label label-success\">$status</span></td>
		// 	<td>$competency->student_proficiency</td>
		// 	<td>$competency->student_grade</td>
		// 	<td>$nbmoduleOk/$nb_comp</td>
		// 	<td>
		// 	<a href=\"$linkCompetence\">
		// 	<i class=\"fa fa-user\" style=\"margin-right: 25px; color: black; font-size:24px\"></i>
		// 	</a>
		// 	";
		// 	if (has_capability('moodle/course:update', $context = context_course::instance($COURSE->id), $USER->id)) {
		// 		$content .= "
		// 		<a href=\"$linkStudentsCompetence\">
		// 		<i class=\"fa fa-users\" style=\"margin-right: 25px;color: black;font-size:24px\"></i>
		// 		</a> ";
		// 	}
		// 	$content .= "
		// 	</td>
		// 	</tr>
		// 	";
		// }
		$content .= "
		</tbody>
		</table>";

		$content .= "
		<script type=\"text/javascript\" charset=\"utf8\" src=\"https://code.jquery.com/jquery-3.3.1.min.js\"></script>
		<script type=\"text/javascript\" charset=\"utf8\" src=\"https://code.jquery.com/ui/1.12.0/jquery-ui.min.js\"></script>
		<script type=\"text/javascript\" charset=\"utf8\" src=\"https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js\"></script>
		<script>
		$(document).ready(function() {
			var table = $('#example').DataTable( {
				\"language\": {
					\"url\": \"https://cdn.datatables.net/plug-ins/1.10.16/i18n/French.json\",
					},
					\"ordering\": false
					} );

					$( '#filter-module' ).on('change', function() {
						table.draw();
					});

        //We wait 0.5 secondes for datatable load
								setTimeout(function() {
									$('#example_filter').hide();
									$('#example_length').hide();
									$('#example_info').hide();
									}, 500);

									$( '#filter-competent' ).on( 'change', function () {
										table.column(2).search($(this).val()).draw();
										} );

										$( '#filter-evaluation' ).on( 'change', function () {
										// console.log($(this).val());
											if ($(this).val()){
												table.column(3).search('^'+$(this).val()+'$',true,false).draw(); 
												} else {
													table.column(3).search($(this).val()).draw();
												}
												});
												$(\"#myBrowser\").on('input', function () {
													var val = this.value;
													if($('#browsers option').filter(function(){
														return this.value === val;        
														}).length) {
															var value2send = document.querySelector(\"#browsers option[value='\"+this.value+\"']\").dataset.value;
															window.location.replace(value2send);
														}
														});

// triggered by `table.draw()` and filter all the table
$.fn.dataTable.ext.search.push(function( settings, data, dataIndex ) {
	var filter = $( '#filter-module' );

	var completion_rate = data[4].split('/');
	var done = completion_rate[0];
	var total = completion_rate[1];
	completion_rate = parseFloat(total == 0 ? 0 : (done / total)*100);

	if ( filter.val() != '' ) {
		filter = filter.val();
		if ( filter == 0 && completion_rate == 0 ) {
			return true;
		} else if ( filter == '<50' && completion_rate < 50 ) {
			return true;
		} else if ( filter == '>=50' && completion_rate >= 50 ) {
			return true;
		} else if ( filter == '100' && completion_rate == 100 ) {
			return true;
		} else {
			return false;
		}
	} else {
		return true;
	}
});


														} );



														</script>
														";
														return $content;

													}

												}

												?>