competency_iena_competencies_2.php 5.01 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
<?php

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

require_once('entity/block_competency_iena_student.php');

global $COURSE, $DB, $USER, $CFG;

$courseid = required_param('courseid', PARAM_INT);
$studentid = optional_param('studentid', $USER->id, PARAM_INT);
$url = new moodle_url('/blocks/competency_iena/competency_iena_competencies_2.php', array('courseid' => $courseid, 'studentid' => $studentid));
$PAGE->set_pagelayout('course');
$PAGE->set_url($url);
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
require_login($course, false, NULL);
$PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));

18 19 20 21 22 23 24
$course_cpts = \core_competency\course_competency::list_competencies($COURSE->id);
if (count($course_cpts) === 0) {
	$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
	echo $OUTPUT->header();
	echo "<p class='alert alert-warning'>Pour le moment, aucune compétence n'a été liée à ce cours. Pour lier des compétences au cours et les associer à des activités, rendez-vous dans la page <a href='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competencies_mgmt.php?courseid={$courseid}'>Gestion des compétences</a>. </p>";
	echo $OUTPUT->footer();
} else {
Thomas Fradet's avatar
Thomas Fradet committed
25

26 27 28 29
	$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");
	echo $OUTPUT->header();
Thomas Fradet's avatar
Thomas Fradet committed
30

31 32 33 34
	// Les compétences du cours. 
	// $course_cpts = \core_competency\course_competency::list_competencies($COURSE->id);
	// L'état des compétences du cours pour un utilisateur
	$user_course_competencies = \core_competency\api::list_user_competencies_in_course($COURSE->id, $studentid);
Thomas Fradet's avatar
Thomas Fradet committed
35

36 37 38
	// Les étudiants. 
	$student = new block_competency_iena_student();
	$students = $student->get_all_students_by_course($COURSE->id);
Thomas Fradet's avatar
Thomas Fradet committed
39

40 41
	// L'étudiant
	$student->get_student_by_id($studentid);
Thomas Fradet's avatar
Thomas Fradet committed
42

43 44 45 46 47 48 49 50 51
	/* Les demandes de validation de compétence (review) prises dans le cptuser car n'existent pas dans le contexte restreint à un cours. */
	/* TODO : préciser sur quelles compétences ? */
	$sql = "SELECT * FROM {competency_usercomp} 
	WHERE userid = ? AND status = ?";
	$params_rev = array();
	$params_rev[] = $student->studentid;
	$params_rev[] = 1;
	$reviews_data = $DB->get_records_sql($sql, $params_rev);
	// $reviews_count = count($reviews_data);
Thomas Fradet's avatar
Thomas Fradet committed
52

53 54 55
	echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competencies_2.php' id='change_stud_form' class='form-inline m-b-1 alert alert-secondary'>";
	echo "<input type='text' hidden name='courseid' value='{$courseid}'>";
	echo "<span hidden id='studentid'>{$studentid}</span>";
Thomas Fradet's avatar
Thomas Fradet committed
56

57 58 59
	// https://github.com/mfranzke/datalist-polyfill
	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'>";
Thomas Fradet's avatar
Thomas Fradet committed
60

61
	echo "<datalist id='student_list' title='Select student'>";
Thomas Fradet's avatar
Thomas Fradet committed
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
	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>";

	echo "<button class='btn btn-secondary m-l-1' id='prevStud'>Précédent</button>";
	echo "<button class='btn btn-secondary m-l-1' id='nextStud'>Suivant</button>";

	echo "</form>";

	echo "<h2>{$student->firstname} {$student->lastname}</h2>";

	echo "<div class='list-group'>";
	foreach ($user_course_competencies as $user_course_competency) {
		// Crée un obj cpt à partir de l'ID. Attention, id de compétence et course_competency sont différents. 
		$cpt = new \core_competency\competency($user_course_competency->get('competencyid'));
		// Récupère les chaines de caractère de l'échelle d'évaluation
		$cpt_scale = $cpt->get_scale()->scale_items;
		$eval = "-";
		if ( $user_course_competency->get('grade') != null ) {
			$eval = $cpt_scale[$user_course_competency->get('grade') - 1];
		}
		$proficient_class = $user_course_competency->get('proficiency') == 1 ? " list-group-item-success" : "";
		$proficient_str = $user_course_competency->get('proficiency') == 1 ? "Oui" : "Non";
		echo "
		<a href='#?courseid={$courseid}&studentid={$studentid}&competencyid={$cpt->get('id')}' class='list-group-item list-group-item-action{$proficient_class}'>
		<div class='d-flex w-100 justify-content-between'>
90 91 92 93 94 95 96 97
		<h3 class='mb-1 iena-cpt-action-title'>{$cpt->get('shortname')}</h3>";
		foreach ($reviews_data as $review) {
			if ( $review->competencyid == $cpt->get('id') ) {
				echo "<div><small class='review-badge'>Évaluation demandée</small></div>";
				break;
			}
		}
		echo "</div>
98 99 100 101 102
		<p class='' style='margin-bottom: 0;'>Évaluation : <em>{$eval}</em></p>
		<small class=''>Acquis : {$proficient_str}</small>
		</a>";
	}
	echo "</div>";
Thomas Fradet's avatar
Thomas Fradet committed
103

104
	echo $OUTPUT->footer();
105

106
} /* Fin else condition qu'il y ait des cpt liées au cours. */