course_competency.php 21.1 KB
Newer Older
Thomas Fradet's avatar
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
<?php 

require_once('../../config.php');

global $USER, $COURSE;

$courseid = required_param('courseid', PARAM_INT);
$studentid = required_param('studentid', PARAM_INT);
$competencyid = required_param('competencyid', PARAM_INT);

$url = new moodle_url('/blocks/competency_iena/course_competency.php', array('courseid' => $courseid, 'studentid' => $studentid, 'competencyid' => $competencyid));
$PAGE->set_url($url);

require_login($courseid, false, NULL);

$PAGE->set_pagelayout('course');
$PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
$PAGE->requires->js("/blocks/competency_iena/js/datalist-polyfill.min.js");
$PAGE->requires->js("/blocks/competency_iena/js/stud-x-cpts.js");
$PAGE->requires->js("/blocks/competency_iena/js/cpt-x-studs.js");

23

Thomas Fradet's avatar
Thomas Fradet committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
/* <<< GESTION DROITS D'ACCÈS >>> */

$context = context_course::instance($courseid);

/* Check if studentid is a course participant */
$is_enrolled = is_enrolled($context, $studentid, '', true);

/* Check if the user is teacher */
$is_teacher = false; 
if (has_capability('moodle/course:update', $context, $USER->id)) {
	$is_teacher = true;
}

/* Redirect student if he try accèss another student data */
if ( $is_teacher === false && $studentid != $USER->id ) {
	$link = $CFG->wwwroot . '/blocks/competency_iena/course_competency.php?courseid=' . $courseid . '&studentid=' . $USER->id . '&competencyid=' . $competencyid;
	header("Location: {$link}");
	exit;
}

echo $OUTPUT->header();

46 47 48

/* <<< REVIEW DATA >>> */

Thomas Fradet's avatar
Thomas Fradet committed
49 50 51 52 53
$sql_rev = "SELECT * FROM {competency_usercomp} 
WHERE userid = ? AND competencyid = ? AND status = ?";
$reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
$review_asked = count($reviews_data) > 0 ? true : false;

54 55 56

/* <<< POST >>> */

Thomas Fradet's avatar
Thomas Fradet committed
57 58
/* POST EVALUATION */

59
if ( isset($_POST['grade']) ) {
Thomas Fradet's avatar
Thomas Fradet committed
60
	$note = $_POST['note'];
Thomas Fradet's avatar
Thomas Fradet committed
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
	\core_competency\api::grade_competency_in_course($courseid, $studentid, $competencyid, $_POST['grade'], $note);
	if ( $review_asked ) {
		\core_competency\api::user_competency_start_review($studentid, $competencyid);
		\core_competency\api::user_competency_stop_review($studentid, $competencyid);
		/* Refresh review data */
		$reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
		$review_asked = count($reviews_data) > 0 ? true : false;
	}
}

/* POST REVIEW */

if ( isset($_POST['review']) ) {
	if ( $_POST['review'] == 'request' ) {
		\core_competency\api::user_competency_request_review($studentid, $competencyid);
	} elseif ( $_POST['review'] == 'cancel' ) {
		\core_competency\api::user_competency_cancel_review_request($studentid, $competencyid);
	}
	/* Refresh review data */
	$reviews_data = $DB->get_records_sql($sql_rev, [$studentid, $competencyid, 1]);
	$review_asked = count($reviews_data) > 0 ? true : false;
}


85 86
/* <<< HELPERS >>> */

Thomas Fradet's avatar
Thomas Fradet committed
87 88 89 90 91 92 93 94 95
function _html($el, $str, $class = "") {
	$class = " class='" . $class . "'";
	echo "<" . $el . $class . ">" . $str . "</" . $el . ">";
}

function _modal_builder($id, $title, $body) {
	return "<div class='modal fade' id='{$id}' tabindex='-1' role='dialog' aria-labelledby='exampleModalScrollableTitle' aria-hidden='true'><div class='modal-dialog modal-dialog-scrollable' role='document'><div class='modal-content'><div class='modal-header'><h5 class='modal-title' id='exampleModalScrollableTitle'>{$title}</h5><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button></div><div class='modal-body'>{$body}</div></div></div></div>";
}

96

Thomas Fradet's avatar
Thomas Fradet committed
97 98 99 100 101 102
/* <<< GESTION ERREUR ACCÈS >>> */

if ( $is_enrolled === false ) {
	_html("p", "L'étudiant demandé n'est pas inscrit dans ce cours.", "alert alert-warning");
}

103

Thomas Fradet's avatar
Thomas Fradet committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
/* <<< DATA >>> */

/* Student USER object */
$student = user_get_users_by_id([$studentid])[$studentid];

/* All students */
/* Only if is teacher because it's to load stud list to switch : teacher feature */
$students = NULL;
if ( $is_teacher ) {
	$students = get_enrolled_users($context);
}

/* Course modules linked to this competency */
$cm_ids = \core_competency\api::list_course_modules_using_competency($competencyid, $courseid);

/* Competency */
$u_c_cpt = \core_competency\api::get_user_competency_in_course($courseid, $studentid, $competencyid);
$cpt = new \core_competency\competency($competencyid);
$cpt_scale = $cpt->get_scale()->scale_items;
$eval = "-"; /* current eval string */
if ( $u_c_cpt->get('grade') != null ) {
	$eval = $cpt_scale[$u_c_cpt->get('grade') - 1];
}
$proficiency = $u_c_cpt->get('proficiency') == 1 ? "Oui" : "Non";
128
$proficiency_class = $u_c_cpt->get('proficiency') == 1 ? "success" : "secondary";
Thomas Fradet's avatar
Thomas Fradet committed
129 130 131 132 133

/* All course competencies */
$course_cpts = \core_competency\course_competency::list_competencies($COURSE->id);


134
/* <<< PAGE >>> */
Thomas Fradet's avatar
Thomas Fradet committed
135

136 137 138
// echo "<pre>";
// var_dump($_POST);
// echo "</pre>";
Thomas Fradet's avatar
Thomas Fradet committed
139 140

/* STUDENT NAME */
141 142

_html("h2", $student->firstname . " " . $student->lastname, "h3' style='margin-bottom: 0.3rem;'");
Thomas Fradet's avatar
Thomas Fradet committed
143 144

/* SWITCH STUDENT FORM */
145

Thomas Fradet's avatar
Thomas Fradet committed
146
if ( $is_teacher && $students != NULL && count($students) != 0 ) {
147
	echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php' id='change_stud_form' class='form-inline m-b-1'>";
Thomas Fradet's avatar
Thomas Fradet committed
148 149 150
	echo "<input type='text' hidden name='courseid' value='{$courseid}'>";
	echo "<input type='text' hidden name='competencyid' value='{$competencyid}'>";
	echo "<span hidden id='studentid'>{$studentid}</span>";
151 152
	/*echo "<label class='m-y-1 m-r-1' for='studentid_sel' style='color: black;'>Etudiant</label>";*/
	echo "<input type='text' name='studentid' id='studentid_sel' value='' list='student_list' class='form-control' style='font-size: .7rem; line-height: 1;'>";
Thomas Fradet's avatar
Thomas Fradet committed
153 154 155 156 157
	echo "<datalist id='student_list' title='Select student'>";
	foreach ($students as $stud) {
		echo "<option value='{$stud->firstname} {$stud->lastname} ({$stud->id})' data-value='{$stud->id}'>{$stud->firstname} {$stud->lastname} ({$stud->id})</option>";
	}
	echo "</datalist>";
158 159
	echo "<div><button class='btn btn-secondary' id='prevStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button>";
	echo "<button class='btn btn-secondary' id='nextStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button></div>";
Thomas Fradet's avatar
Thomas Fradet committed
160 161 162
	echo "</form>";
}

163
/* INFO ABOUT COMPETENCIES, FRAMEWORK AND CURRENT GRADE */
Thomas Fradet's avatar
Thomas Fradet committed
164

165
_html('h2', $cpt->get('shortname'), "h3' style='margin-bottom: 0.3rem;'");
Thomas Fradet's avatar
Thomas Fradet committed
166

167
/* COMPETENCY TREE PATH */
Thomas Fradet's avatar
Thomas Fradet committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184

/* Competency tree parents path from current to framework */
$cptid = $competencyid;
$parent_cpts = array();
while ($cptid > 0) {
	$tmp_cpt = new \core_competency\competency($cptid);
	array_unshift($parent_cpts, ['id' => $tmp_cpt->get('id'), 'shortname' => $tmp_cpt->get('shortname'), 'description' => $tmp_cpt->get('description')]);
	$cptid = $tmp_cpt->get('parentid');
}
/* Framework infos */
$cpt_path_link = "<a href='#' data-toggle='modal' data-target='#modalref'>{$cpt->get_framework()->get('shortname')}</a>" . _modal_builder('modalref', $cpt->get_framework()->get('shortname'), $cpt->get_framework()->get('description'));
/* Each competency info */
foreach ($parent_cpts as $parent_cpt) {
	$cpt_path_link .= " / <a href='#' data-toggle='modal' data-target='#modal{$parent_cpt['id']}'>{$parent_cpt['shortname']}</a>" . _modal_builder("modal{$parent_cpt['id']}", $parent_cpt['shortname'], $parent_cpt['description']);
}
echo "<div style='margin-bottom: 0.7rem;'>" . $cpt_path_link . "</div>";

185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
/* SWITCH COMPETENCY FORM */

echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php' id='change_cpt_form' class='form-inline m-b-1'>";
echo "<input type='text' hidden name='courseid' value='{$courseid}'>";
echo "<input type='text' hidden name='studentid' value='{$studentid}'>";
echo "<span hidden id='competencyid'>{$competencyid}</span>";
/*echo "<label class='m-r-1' for='competencyid_sel' style=''>Changer de compétence</label>";*/
echo "<input type='text' name='competencyid' id='competencyid_sel' value='' list='competency_list' class='form-control' style='font-size: .7rem; line-height: 1;'>";
echo "<datalist id='competency_list' title='Select competency'>";
foreach ($course_cpts as $course_cpt) {
	echo "<option value='{$course_cpt->get('shortname')} ({$course_cpt->get('id')})' data-value='{$course_cpt->get('id')}'>{$course_cpt->get('shortname')} ({$course_cpt->get('id')})</option>";
}
echo "</datalist>";
echo "<button class='btn btn-secondary' id='prevCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button>";
echo "<button class='btn btn-secondary' id='nextCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button>";
echo "</form>";
/* END switch competency form */

/* EVALUATION INFOS AND ACTIONS */
Thomas Fradet's avatar
Thomas Fradet committed
204

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
echo "<div class='row'>";
/* Proficiency info */
echo "<div class='col-12 col-lg-3'>";
echo "<div class='alert alert-{$proficiency_class}'>";
echo "<h3 class='h4'>Validé</h3>";
echo "<p class='m-b-0 btn p-l-0'>{$proficiency}</p>";
echo "</div>";
echo "</div>";
/* Grade info */
echo "<div class='col-12 col-lg-3'>";
echo "<div class='alert alert-{$proficiency_class}'>";
echo "<h3 class='h4'>Évaluation</h3>";
echo "<p class='m-b-0 btn p-l-0'>{$eval}</p>";
echo "</div>";
echo "</div>";
/* Review and grade ASK and ACTION */
$review_class = $review_asked ? "info" : "secondary";
$review_msg = $review_asked ? "Évaluation demandée" : "Aucune évaluation demandée";
echo "<div class='col-12 col-lg-6'>";
echo "<div class='alert alert-{$review_class}'>";
echo "<h3 class='h4'>{$review_msg}</h3>";
Thomas Fradet's avatar
Thomas Fradet committed
226
if ( $review_asked ) {
227
	/* Request review and cancel buttons */
Thomas Fradet's avatar
Thomas Fradet committed
228
	if ( $USER->id == $studentid ) {
229 230
		/* Student cancel his own review */
		echo "<form method='post' action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php?courseid={$courseid}&studentid={$studentid}&competencyid={$competencyid}' style='display: inline; margin-right: 1rem;'>";
Thomas Fradet's avatar
Thomas Fradet committed
231 232 233 234 235 236 237
		echo "<input hidden style='display: none;' type='text' name='review' value='cancel'>";
		echo "<button type='submit' class='btn btn-secondary'>Annuler la demande</button>";
		echo "</form>";
	}
} else {
	if ( $USER->id == $studentid ) {
		/* Student ask review */
238
		echo "<form method='post' action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php?courseid={$courseid}&studentid={$studentid}&competencyid={$competencyid}' style='display: inline; margin-right: 1rem;'>";
Thomas Fradet's avatar
Thomas Fradet committed
239 240 241 242 243
		echo "<input hidden style='display: none;' type='text' name='review' value='request'>";
		echo "<button type='submit' class='btn btn-primary'>Demande d'évaluation</button>";
		echo "</form>";
	}
}
244 245 246 247 248 249 250 251 252 253 254 255
if ( $is_teacher ) {
	/* Evaluation button and modal */
	echo "<a href='#' data-toggle='modal' data-target='#modaleval' class='btn btn-primary'>Évaluer</a>";
	$eval_modale_echo = "";
	$eval_modale_echo .= "<form method='post' action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php?courseid={$courseid}&studentid={$studentid}&competencyid={$competencyid}'><div class='form-group'><div class='form-group'><label>Évaluation</label><select name='grade' class='form-control'>";
	foreach ($cpt_scale as $key => $item) {
		$grade = $key + 1;
		$selected = "";
		if ( $item == $eval ) {
			$selected = " selected";
		}
		$eval_modale_echo .= "<option value='{$grade}'{$selected}>{$item}</option>";
Thomas Fradet's avatar
Thomas Fradet committed
256
	}
257 258
	$eval_modale_echo .= "</select></div><div class='form-group'><textarea name='note' class='form-control' placeholder=\"Commentaire d'évaluation\"></textarea></div><button type='submit' class='btn btn-primary'>Évaluer</button></form></div>";
	echo _modal_builder("modaleval", "Évaluation", $eval_modale_echo);
Thomas Fradet's avatar
Thomas Fradet committed
259
}
260 261 262
echo "</div>"; /* END review and grade ASK and ACTION - col */
echo "</div>"; /* END review and grade ASK and ACTION - alert */
echo "</div>"; /* END evaluation info and actions row */
Thomas Fradet's avatar
Thomas Fradet committed
263

Thomas Fradet's avatar
Thomas Fradet committed
264
/* GRADES AND EVIDENCES HISTORY CHART AND LIST */
Thomas Fradet's avatar
Thomas Fradet committed
265

266 267 268
// quelle différence
// read_user_evidence($id)
// read_evidence($evidenceid)
Thomas Fradet's avatar
Thomas Fradet committed
269

270
// delete_user_evidence($id)
Thomas Fradet's avatar
Thomas Fradet committed
271

272 273
// pour toutes les cpt
// list_user_evidence($userid)
Thomas Fradet's avatar
Thomas Fradet committed
274

275 276 277
// lié à la compétence
// list_evidence($userid = 0, $competencyid = 0, $planid = 0, $sort = 'timecreated',
//                                          $order = 'DESC', $skip = 0, $limit = 0)
Thomas Fradet's avatar
Thomas Fradet committed
278

279 280
// list_evidence_in_course($userid = 0, $courseid = 0, $competencyid = 0, $sort = 'timecreated',
                                                   // $order = 'DESC', $skip = 0, $limit = 0)
Thomas Fradet's avatar
Thomas Fradet committed
281 282


283 284 285

// OKOK

Thomas Fradet's avatar
Thomas Fradet committed
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 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406


/* Utilisation des renderer du /admin/tool/lp/class/output pour obtenir toutes les données d'historique construites et organisées */
/* Dabord dans le cours, puis dans l'absolu pour les différencier / filtrer */

$tool_lp_renderer = $PAGE->get_renderer('tool_lp');

$user_cpt_course_data = new \tool_lp\output\user_competency_summary_in_course($studentid, $competencyid, $courseid);
$user_cpt_course_data = $user_cpt_course_data->export_for_template($tool_lp_renderer);
$course_evidences = $user_cpt_course_data->usercompetencysummary->evidence;
$course_evidences_ids = array();
foreach ($course_evidences as $course_evidence) {
	$course_evidences_ids[] = $course_evidence->id;
}

$user_competency = \core_competency\api::get_user_competency($studentid, $competencyid);
$user_cpt_all_data = new \tool_lp\output\user_competency_summary($user_competency);
$user_cpt_all_data = $user_cpt_all_data->export_for_template($tool_lp_renderer);
$all_evidences = $user_cpt_all_data->evidence;

echo "<div class='row'>";
echo "<div class='col-12 col-lg-6'>";
echo "<h2 class='h3'>Historique</h2><ul class='nav nav-tabs' id='hist-tabs'>
<li class='nav-item'>
<a class='nav-link active' href='#' id='all_history_tab'>Complet</a>
</li>
<li class='nav-item'>
<a class='nav-link' href='#' id='course_history_tab'>Dans ce cours</a>
</li>
<li class='nav-item'>
<a class='nav-link' href='#' id='other_history_tab'>Hors de ce cours</a>
</li>
</ul>";
echo "<ul class='list-group' style='height: 50vh; min-height: 300px; overflow: scroll;'>";
/* proficient or not depending of rating in scale (set in framework by creator) */
foreach ($all_evidences as $key => $ev) {
	/* mark difference between this course evidences in html for JS filter with tabs */
	if ( in_array($ev->id, $course_evidences_ids) ) {
		$is_course_evidence = " data-evidenceorigin='course'";
	} else {
		$is_course_evidence = " data-evidenceorigin='other'";
	}
	if ( $ev->action === "0" ) {
		$grade_make_proficient = ' list-group-item-light';
	} else { 
		$scale_rules = json_decode($user_cpt_all_data->competency->scaleconfiguration);
		foreach ($scale_rules as $scale_rule) {
			if ( isset($scale_rule->proficient) && $scale_rule->id == $ev->grade && $scale_rule->proficient == 1 ) {
				$grade_make_proficient = ' list-group-item-success';
			} else {
				$grade_make_proficient = '';
			}
		}
	}
	$date = date("d/m/y – H:i", $ev->timemodified);
	echo "<li class='list-group-item{$grade_make_proficient}'{$is_course_evidence}>
	<div class='d-flex w-100 justify-content-between'>";
	if ( isset($ev->gradename) ) {
		echo "<h5 class='mb-1' style='font-weight: 600;'>$ev->gradename</h5>";
	}
	echo "<small>{$date}</small>
	</div>
	<p class='mb-1 font-weight-light'><em>{$ev->description}</em></p>";
	if ( isset($ev->note) && $ev->note != "" ) {
		echo "<p class='mb-1' style='font-weight: 500;'>{$ev->note}</p>";
	}
	if ( isset($ev->actionuser) ) {
		echo "<small>Évalué par : <a target='_blank' href='{$ev->actionuser->profileurl}'>{$ev->actionuser->fullname}</a></small>";
	}
	echo "</li>";
}
echo "</ul>";
echo "</div>";
echo "<script>
(function() {
	function active_tabs(active_tab) {
		var tabs = document.querySelectorAll('#hist-tabs .nav-link');
		for ( var i=0; i < tabs.length; i++ ) {
			tabs[i].setAttribute('class', 'nav-link');
		}
		active_tab.setAttribute('class', 'nav-link active');
	}
	function filter(type) {
		var list_items = document.querySelectorAll('[data-evidenceorigin]');
		for ( var j = 0; j < list_items.length; j++  ) {
			if ( list_items[j].dataset.evidenceorigin != type ) {
				list_items[j].style.display = 'none';
			} else {
				list_items[j].style.display = '';
			}
		}
	}
	document.getElementById('all_history_tab').addEventListener('click', function (e) { e.preventDefault(); active_tabs(e.target); filter('course'); });
	document.getElementById('course_history_tab').addEventListener('click', function (e) { e.preventDefault(); active_tabs(e.target); filter('course'); });
	document.getElementById('other_history_tab').addEventListener('click', function (e) { e.preventDefault(); active_tabs(e.target); filter('other'); });
})();
</script>;";
echo "</div>";

echo "<pre>";
var_dump($course_evidences_ids);
print_r($all_evidences);
echo "</pre>";

/* 

TODO : 

Remonter ces données en haut et commenter les données préalablement récupérées d'une autre manière devenues superflues avec celles-ci. Ca réduira l'impact du chargement de la page. Et ça sera plus propre et plus concis. Quand-même garder les éléments en commentaire au cas où les exporteurs sautent dans les prochaines versions de MOODLE. 

*/


// echo $output_lp->render($cpt_base_page);






/* Data */
Thomas Fradet's avatar
Thomas Fradet committed
407 408
$course_evidencies = \core_competency\api::list_evidence_in_course($studentid, $courseid, $competencyid, $sort = 'timecreated', $order = 'DESC', $skip = 0, $limit = 0);
$all_evidencies = \core_competency\api::list_evidence($studentid, $competencyid, $planid = 0, $sort = 'timecreated', $order = 'DESC', $skip = 0, $limit = 0);
409

Thomas Fradet's avatar
Thomas Fradet committed
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
$evidences = array();
foreach ($course_evidencies as $course_ev) {
	$ev = new stdClass();
	// echo "<pre>";
	// var_dump($course_ev);
	// echo "</pre>";
	$ev->id = $course_ev->get('id');
	$ev->usercompetencyid = $course_ev->get('usercompetencyid');
	$ev->contextid = $course_ev->get('contextid');
	$ev->actionuserid = $course_ev->get('actionuserid');
	$ev->descidentifier = $course_ev->get('descidentifier'); /* nature de l'événement */
	// $course_ev->get('actionuserid')
	$ev->out = $course_ev->get_description()->out();
	$evidences[] = $ev;
}

foreach ($evidences as $ev) {
	// echo "<p>{$ev->out}</p>";
}

// $user_competency_summary_in_course = new \tool_lp\output\user_competency_summary_in_course($studentid, $competencyid, $courseid);
// $dataSumCourse = $user_competency_summary_in_course->export_for_template(new renderer_base(new moodle_page(), 'autre'));
// var_dump($dataSumCourse);


Thomas Fradet's avatar
Thomas Fradet committed
435 436 437
$labels = array();
$series_data = array();
$series_data_all = array();
438

Thomas Fradet's avatar
Thomas Fradet committed
439
foreach ($all_evidencies as $evidence) {
Thomas Fradet's avatar
Thomas Fradet committed
440
	// echo "<ul>";
Thomas Fradet's avatar
Thomas Fradet committed
441 442


Thomas Fradet's avatar
Thomas Fradet committed
443
	// echo "<li>{$evidence->get('id')}</li>";
444
	
Thomas Fradet's avatar
Thomas Fradet committed
445
	// echo "<li>Action : {$evidence->get('action')} (0 : log, 2 ou 3 : rating)</li>";
Thomas Fradet's avatar
Thomas Fradet committed
446
	$grade = $evidence->get('grade');
447
	
Thomas Fradet's avatar
Thomas Fradet committed
448 449
	if ( $grade != NULL ) { /* liéer à descidentifier == evidence_manualoverrideincourse ??? */
		$grade_label = $cpt_scale[$grade - 1];
Thomas Fradet's avatar
Thomas Fradet committed
450
		// echo "<li>{$grade_label}</li>";
Thomas Fradet's avatar
Thomas Fradet committed
451 452
		if ( $evidence->get('contextid') == $context->__get('id') ) {
			$series_data[] = $grade;
Thomas Fradet's avatar
Thomas Fradet committed
453
			$series_data_all[] = end($series_data_all);
Thomas Fradet's avatar
Thomas Fradet committed
454
		} else {
Thomas Fradet's avatar
Thomas Fradet committed
455
			$series_data[] = end($series_data);
Thomas Fradet's avatar
Thomas Fradet committed
456 457 458 459 460
			$series_data_all[] = $grade;
		}
		$labels[] = userdate($evidence->get('timecreated'), "%d/%m/%y");
	} else {
	}
461
	
Thomas Fradet's avatar
Thomas Fradet committed
462 463 464 465 466 467
	// evidence_manualoverride
	// evidence_manualoverrideinplan
	// evidence_manualoverrideincourse
	$evidence_type = $evidence->get('descidentifier');
	if ( $evidence_type == 'evidence_manualoverrideincourse' ) {
		$emitter = user_get_users_by_id([$evidence->get('actionuserid')])[$evidence->get('actionuserid')];
Thomas Fradet's avatar
Thomas Fradet committed
468
		// echo "<li>{$emitter->firstname} {$emitter->lastname}</li>";
Thomas Fradet's avatar
Thomas Fradet committed
469
	} elseif ( $evidence_type == 'evidence_coursemodulecompleted' ) {
Thomas Fradet's avatar
Thomas Fradet committed
470
		// echo "<li>{$evidence->get('desca')}</li>";
Thomas Fradet's avatar
Thomas Fradet committed
471
	}
472

Thomas Fradet's avatar
Thomas Fradet committed
473
	// var_dump($evidence->get_description()->out());
474

Thomas Fradet's avatar
Thomas Fradet committed
475
	// echo "</ul>";
Thomas Fradet's avatar
Thomas Fradet committed
476
}
Thomas Fradet's avatar
Thomas Fradet committed
477 478


Thomas Fradet's avatar
Thomas Fradet committed
479
// echo "<pre>";
Thomas Fradet's avatar
Thomas Fradet committed
480 481 482 483 484
// var_dump($context->__get('id'));
// var_dump($all_evidencies);
// var_dump($series_data);
// var_dump($series_data_all);
// var_dump($labels);
Thomas Fradet's avatar
Thomas Fradet committed
485
// echo "</pre>";
Thomas Fradet's avatar
Thomas Fradet committed
486

487 488 489 490 491
// OK OK END



echo "<div class='alert alert-secondary'>";
Thomas Fradet's avatar
Thomas Fradet committed
492 493
_html('h2', "Historique d'évaluation", "h3");

Thomas Fradet's avatar
Thomas Fradet committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
// $chart = new core\chart_line();
// $chart->get_yaxis(0, true)->set_labels(["Non évaluant", "Non compétent", "Compétent"]);
// $series = new core\chart_series('Donnée dans ce cours', array_reverse($series_data));
// $series_all = new core\chart_series("Donnée dans d'autres cours", array_reverse($series_data_all));
// $chart->add_series($series);
// $chart->add_series($series_all);
// $chart->set_labels(array_reverse($labels));
// echo $OUTPUT->render($chart);
// echo "<hr>";

// $chart = new core\chart_bar();
// $chart->get_yaxis(0, true)->set_labels(["Non évaluant", "Non compétent", "Compétent"]);
// $series = new core\chart_series('Donnée dans ce cours', array_reverse($series_data));
// $series_all = new core\chart_series("Donnée dans d'autres cours", array_reverse($series_data_all));
// $chart->add_series($series);
// $chart->add_series($series_all);
// $chart->set_labels(array_reverse($labels));
// echo $OUTPUT->render($chart);
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529
echo "</div>";

/* LINKED MODULES */

if ( count($cm_ids) !== 0 ) {
	$modinfo = get_fast_modinfo($courseid);
	_html("h3", "Lié à cette compétence");
	echo "<div class='list-group'>";
	foreach ($cm_ids as $cm_id) {
		echo "<a href='{$modinfo->cms[$cm_id]->url->out()}' target='_blank' class='list-group-item list-group-item-action'><img src='$CFG->wwwroot/theme/image.php/boost/{$modinfo->cms[$cm_id]->modname}/1/icon>' style='height: 1.3rem;'><span class='align-middle'> {$modinfo->cms[$cm_id]->name}</span></a>";
	}
	echo "</div>";
} else {
	_html("p", "Aucune ressource ou activité n'est liée à cette compétence dans ce cours. ", "alert alert-secondary");
}


echo $OUTPUT->footer();
Thomas Fradet's avatar
Thomas Fradet committed
530 531

?>