competency_iena_competencies_2.php 7.16 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'));

Thomas Fradet's avatar
Thomas Fradet committed
18 19 20 21 22 23 24 25 26 27
$is_student = false; 
if (!has_capability('moodle/course:update', $context = context_course::instance($course->id), $USER->id)) {
	$is_student = true;
	if ( $studentid != $USER->id ) {
		$link = $CFG->wwwroot . '/blocks/competency_iena/competency_iena_competencies_2.php?courseid=' . $courseid . '&studentid=' . $USER->id;
		header("Location: {$link}");
		exit;
	}
}

28
$course_cpts = \core_competency\course_competency::list_competencies($COURSE->id);
29 30
$count_course_cpts = count($course_cpts);
if ($count_course_cpts === 0) {
31 32 33 34 35
	$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
36

37 38
	// 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
39

40 41 42
	// Les étudiants. 
	$student = new block_competency_iena_student();
	$students = $student->get_all_students_by_course($COURSE->id);
Thomas Fradet's avatar
Thomas Fradet committed
43

44 45
	// L'étudiant
	$student->get_student_by_id($studentid);
Thomas Fradet's avatar
Thomas Fradet committed
46

47
	$PAGE->set_heading($OUTPUT->heading($student->firstname . " " . $student->lastname, 2, 'headingblock header outline'));
48
	$PAGE->requires->js("/blocks/competency_iena/js/dropdown.js");
49 50
	echo $OUTPUT->header();

51 52 53 54 55 56 57 58
	/* 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);
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
	$reviews_count = count($reviews_data);

	/* <<< DASHBORD >>> */

	$count_proficients = 0;
	foreach ($user_course_competencies as $u_c_cpt) {
		if ( $u_c_cpt->get('proficiency') == 1 ) {
			$count_proficients++;
		}
	}

	/* DEBUT CONTAINER */
	echo "<div class='container-fluid' id='dash-container'>";

	/* <<< DASHBOARD >>> */

	echo "<div class='alert alert-secondary row' style='padding-top: 1.5rem;'>"; /* Début tableau de bord. */
	
	/* Left col */
	echo "<div class='col-12 col-lg-6'>";
Thomas Fradet's avatar
Thomas Fradet committed
79

80 81
	echo "<h2 class='h3'>{$student->firstname} {$student->lastname}</h2>";

Thomas Fradet's avatar
Thomas Fradet committed
82
	if ( !$is_student ) {
83
		echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competencies_2.php' id='change_stud_form' class='form-inline' autocomplete='off' style='display: block;height: 1.5rem;'>";
Thomas Fradet's avatar
Thomas Fradet committed
84 85
		echo "<input type='text' hidden name='courseid' value='{$courseid}'>";
		echo "<span hidden id='studentid'>{$studentid}</span>";
86 87 88 89 90
		
		echo "<div id='student_dropdown' class='iena-dropdown' style='z-index: 10;'>";
		echo "<input type='text' hidden name='studentid' id='studentid_sel' class='iena-drop-input-value' value=''>";
		echo "<input type='text' value='' class='form-control iena-drop-input' style='font-size: .7rem; line-height: 1; width: 300px;' placeholder='{$student->firstname} {$student->lastname}'><button class='btn btn-secondary' id='prevStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button><button class='btn btn-secondary' id='nextStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button>";
		echo "<div class='iena-droplist' id='student_list'>";
Thomas Fradet's avatar
Thomas Fradet committed
91
		foreach ($students as $stud) {
92
			echo "<a href='#' data-value='{$stud->id}' class='iena-drop-item' style='display: none;'>{$stud->firstname} {$stud->lastname}</a>";
Thomas Fradet's avatar
Thomas Fradet committed
93
		}
94 95 96
		echo "</div>";
		echo "</div>";
		
Thomas Fradet's avatar
Thomas Fradet committed
97
		echo "</form>";
98 99
	}

100
	echo "<h2 class='h4 m-t-2'>Demandes d'évaluations <span class='badge badge-pill badge-primary' style='border-radius: 0.15rem;'>$reviews_count</span></h2>";
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115
	echo "</div>"; /* Left col END */

	/* Right col */
	echo "<div class='col-12 col-lg-6'>"; 
	echo "<h2 class='h4'>Compétences validées</h2>";
	$chart = new \core\chart_pie();
	$proficiency_serie = new core\chart_series('', [$count_proficients, $count_course_cpts - $count_proficients]);
	$chart->set_doughnut(true); 
	$chart->add_series($proficiency_serie);
	$chart->set_labels(["Validé", "Non validé"]);
	echo $OUTPUT->render($chart);
	echo "</div>"; /* Right col END */

	echo "</div>"; /* Fin tableau de bord */
116

117 118 119 120 121
	/* <<< COMPETENCY LIST >>> */

	echo "<div class='row'>";

	echo "<div class='col-12' style='padding: 0;'>";
122 123 124 125 126

	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'));
127 128 129
		/* Visuel indentation to reflect levels in cpt framework */
		$cpt_level_in_framework = substr_count($cpt->get('path'), '/') - 1; /* start at 1 */
		$level_indentation = $cpt_level_in_framework * 1.5;
130 131 132 133 134 135 136 137 138
		// 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 "
139
		<a href='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php?courseid={$courseid}&studentid={$studentid}&competencyid={$cpt->get('id')}' class='list-group-item list-group-item-action{$proficient_class}' style='padding-left: {$level_indentation}rem;'>
140
		<div class='d-flex w-100 justify-content-between'>
141
		<h3 class='mb-1 iena-cpt-action-title h5'>{$cpt->get('shortname')}</h3>";
142 143 144 145 146 147 148
		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>
149
		<p class='small' style='margin-bottom: 0;'>Évaluation : {$eval} / Acquis : {$proficient_str}</p>
150 151 152
		</a>";
	}
	echo "</div>";
Thomas Fradet's avatar
Thomas Fradet committed
153

154 155 156 157 158 159 160
	echo "</div>";

	echo "</div>"; /* Fin de la liste. */


	echo "</div>"; /* FIN CONTAINER */

161
	echo $OUTPUT->footer();
162

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