competency_iena_competency_students_2.php 14.1 KB
Newer Older
1 2 3 4 5
<?php

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

// ENLEVER SI NON NECESSAIRE :
6 7 8 9
// require_once('entity/block_competency_iena_competency.php');
// require_once('entity/block_competency_iena_module.php');
// require_once('entity/block_competency_iena_ressource.php');
// require_once('entity/block_competency_iena_section.php');
10 11 12
require_once('entity/block_competency_iena_student.php');


13
global $COURSE, $DB, $CFG;
14 15 16

$courseid = required_param('courseid', PARAM_INT);
$competencyid = optional_param('competencyid', 0, PARAM_INT);
17 18 19 20
$grade = optional_param('grade', 'all', PARAM_ALPHANUM);
$proficiency = optional_param('proficiency', 'all', PARAM_ALPHANUM);
$review = optional_param('review', 'all', PARAM_ALPHANUM);
$url = new moodle_url('/blocks/competency_iena/competency_iena_competency_students_2.php', array('courseid' => $courseid, 'competencyid' => $competencyid, 'grade' => $grade, 'proficiency' => $proficiency, 'review' => $review));
21 22 23
//$requete = $DB->get_record_sql('SELECT course FROM {block_competency_iena} WHERE id = ?', array($courseid));
$PAGE->set_pagelayout('course');
$PAGE->set_url($url);
24 25
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
if (!has_capability('moodle/course:update', $context = context_course::instance($course->id), $USER->id)) {
26 27 28 29 30 31 32 33
	$link = $CFG->wwwroot . '/course/view.php?id=' . $courseid;
	header("Location: {$link}");
	exit;
}
require_login($course, false, NULL);

$PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/* Liste des compétences du cours */
$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 {

	$current_cpt = new stdClass();
	foreach ($course_cpts as $course_cpt) {
		$current_cpt->id = $course_cpt->get('id');
		if ( $current_cpt->id == $competencyid || $competencyid == 0 ) {
			$current_cpt->shortname = $course_cpt->get('shortname');
			$current_cpt->scale = $course_cpt->get_scale()->scale_items;
			break;
		}
	}
	
	$PAGE->set_heading($OUTPUT->heading($current_cpt->shortname, 2, 'headingblock header outline'));
	$PAGE->requires->js("/blocks/competency_iena/js/datalist-polyfill.min.js");
	$PAGE->requires->js("/blocks/competency_iena/js/cpt-x-studs.js");
	echo $OUTPUT->header();

	/* Les étudiants. */
	$student_entity = new block_competency_iena_student();
	$students = $student_entity->get_all_students_by_course($COURSE->id);
	$count_students = count($students);
	$student_ids = array();
	foreach ($students as $stud) {
Thomas Fradet's avatar
Thomas Fradet committed
65
		$student_ids[] = intval($stud->id);
66 67
	}

Thomas Fradet's avatar
Thomas Fradet committed
68
	echo "<div class='container-fluid' id='dash-container'>";
69 70

	/* ===== CHANGE COMPETENCY ===== */
Thomas Fradet's avatar
Thomas Fradet committed
71
	/* There is 2 forms witch use data from each other while submitting. */
72 73 74 75 76

	echo "<div class='alert row' style='padding: 0;'>"; /* Début change competency. */
	echo "<div class='col-12' style='padding-left: 0;'>";
	echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competency_students_2.php' id='change_cpt_form' class='form-inline'>";
	echo "<input type='text' hidden name='courseid' value='{$COURSE->id}'>";
Thomas Fradet's avatar
Thomas Fradet committed
77 78 79 80 81 82 83 84 85
	if ( isset($_GET['grade']) ) {
		echo "<input type='text' hidden name='grade' value='{$_GET['grade']}'>";
	}
	if ( isset($_GET['proficiency']) ) {
		echo "<input type='text' hidden name='proficiency' value='{$_GET['proficiency']}'>";
	}
	if ( isset($_GET['review']) ) {
		echo "<input type='text' hidden name='review' value='{$_GET['review']}'>";
	}
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
	echo "<span hidden id='competencyid'>{$current_cpt->id}</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'>";
	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 m-l-1' id='prevCpt'>Précédent</button>";
	echo "<button class='btn btn-secondary m-l-1' id='nextCpt'>Suivant</button>";
	echo "</form>";
	echo "</div>";
	echo "</div>"; /* Fin change competency. */

	/* ===== DASHBOARD ===== */

	echo "<div class='alert alert-secondary row' style='padding-top: 1.5rem;'>"; /* Début tableau de bord. */

	/* <<< PROFICIENCY SECTION >>> */
	echo "<div class='col-12 col-lg-6'>";

	/* Nombre d'enregistrements, donc d'étudiants, proficients pour la compétence courante. */
	$count_proficients = $DB->count_records('competency_usercompcourse', [
		'courseid' => $COURSE->id,
		'proficiency' => 1,
		'competencyid' => $current_cpt->id
	]);

Thomas Fradet's avatar
Thomas Fradet committed
114
	echo "<h2 class='h4'>Compétences validées</h2>";
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

	$chart = new \core\chart_pie();
	$proficiency_serie = new core\chart_series('', [$count_proficients, $count_students - $count_proficients]);
	$chart->set_doughnut(true); 
	$chart->add_series($proficiency_serie);
	$chart->set_labels(["Validé", "Non validé"]);
	echo $OUTPUT->render($chart);

	echo "</div>"; /* proficiency section end */

	/* <<< GRADE SECTION >>> */
	echo "<div class='col-12 col-lg-6'>";
	echo "<h2 class='h4'>Évaluations</h2>";

	/* Nombre d'enregistrements, donc d'étudiants, de chaque grade sur la scale d'évaluation. */
	$bd_grades = $DB->get_records('competency_usercompcourse', ['courseid' => $COURSE->id, 'competencyid' => $current_cpt->id], '', 'id, grade');

	/* Constitution de la liste du compte de grade pour chaque possibilité. */
	$grade_scale_counter = array();
	$count_total_grades = 0;
	foreach ($current_cpt->scale as $key => $scale_item) {
		$grade_scale_counter[$key] = 0;
	}
	foreach ($bd_grades as $bd_grade) {
		foreach ($grade_scale_counter as $grade_scale_item => $item_count) {
			if ( $grade_scale_item + 1 == $bd_grade->grade ) {
				$grade_scale_counter[$grade_scale_item]++;
				$count_total_grades++;
				break;
			}
		}
	}
	$grade_scale_counter[] = $count_students - $count_total_grades;
	$scale_for_labels = $current_cpt->scale;
	$scale_for_labels[] = "Non évalués";
	/* Graphique MOODLE */
	$chart = new core\chart_bar();
	$grade_serie = new core\chart_series('', $grade_scale_counter);
	$chart->add_series($grade_serie);
	$chart->set_labels($scale_for_labels);
	echo $OUTPUT->render($chart);
	echo "</div>"; /* grade section end */

	/* <<< TO REVIEW SECTION >>> */
	echo "<div class='col-12'>";
Thomas Fradet's avatar
Thomas Fradet committed
160 161 162 163 164 165 166 167 168 169

	list($in_sql_stud_ids, $params_stud_ids) = $DB->get_in_or_equal($student_ids);
	$sql = "SELECT * FROM {competency_usercomp} 
	WHERE userid {$in_sql_stud_ids} AND competencyid = ? AND status = ?";
	$params_rev = array();
	$params_rev = array_merge($params_rev, $params_stud_ids);
	$params_rev[] = $current_cpt->id;
	$params_rev[] = 1;
	$reviews_data = $DB->get_records_sql($sql, $params_rev);
	$reviews_count = count($reviews_data);
170 171 172 173 174 175 176

	echo "<h2 class='h4'>Demandes d'évaluations <span class='badge badge-pill badge-primary' style='    border-radius: 0.15rem;'>$reviews_count</span></h2>";
	echo "</div>"; /* to review section end */

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

	/* ===== FILTERS ===== */
Thomas Fradet's avatar
Thomas Fradet committed
177
	/* There is 2 forms witch use data from each other while submitting. */
178

Thomas Fradet's avatar
Thomas Fradet committed
179
	echo "<div class='alert alert-secondary row'>"; /* Début filtres. */
180 181
	echo "<div class='col-12'>";

Thomas Fradet's avatar
Thomas Fradet committed
182
	echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competency_students_2.php#dash-container' class='form-inline'>";
Thomas Fradet's avatar
Thomas Fradet committed
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
	echo "<input type='text' hidden name='courseid' value='{$COURSE->id}'>";
	echo "<input type='text' hidden name='competencyid' value='{$current_cpt->id}'>";

	echo "<label>Évaluation</label><select name='grade' class='custom-select mr-3'>";

	$form_grade = isset($_GET['grade']) ? $_GET['grade'] : 'all';
	if ( $form_grade == 'all' ) { echo "<option value='all' selected>Tous</option>"; } else { echo "<option value='all'>Tous</option>"; }
	if ( $form_grade == 'no' ) { echo "<option value='no' selected>Non évalués</option>"; } else { echo "<option value='no'>Non évalués</option>"; }
	foreach ($current_cpt->scale as $key => $scale_item) {
		$strkey = strval($key + 1);
		echo "<option value='{$strkey}'";
		if ( $form_grade == $strkey ) { echo "selected"; }
		echo ">{$scale_item}</option>";
	}
	
	echo "</select>";

	$form_proficiency = isset($_GET['proficiency']) ? $_GET['proficiency'] : 'all';
	echo "<label>Validé</label><select name='proficiency' class='custom-select mr-3'>
	<option value='all'";
	if ( $form_proficiency == 'all' ) { echo 'selected'; }
	echo ">Tous</option>
	<option value='no'";
	if ( $form_proficiency == 'no' ) { echo 'selected'; }
	echo ">Non</option>
	<option value='yes'";
	if ( $form_proficiency == 'yes' ) { echo 'selected'; }
	echo ">Oui</option>
	</select>";

	$form_review = isset($_GET['review']) ? $_GET['review'] : 'all';
	echo "<label>Évaluation demandée</label><select name='review' class='custom-select mr-3'><option value='all'";
	if ( $form_review == 'all' ) { echo 'selected'; }
	echo ">Tous</option>
Thomas Fradet's avatar
Thomas Fradet committed
217 218
	<option value='no'";
	if ( $form_review == 'no' ) { echo 'selected'; }
Thomas Fradet's avatar
Thomas Fradet committed
219
	echo ">Non</option>
Thomas Fradet's avatar
Thomas Fradet committed
220 221
	<option value='yes'";
	if ( $form_review == 'yes' ) { echo 'selected'; }
Thomas Fradet's avatar
Thomas Fradet committed
222 223 224
	echo ">Oui</option>
	</select>";
	
225 226 227 228 229 230 231 232
	echo "<button type='submit' class='btn btn-primary'>Chercher</button>";
	echo "</form>";

	echo "</div>";
	echo "</div>"; /* Fin filtres. */

	/* ===== STUDENT LIST ===== */

Thomas Fradet's avatar
Thomas Fradet committed
233
	/* NB : un étudiant n'existe pas en base competency_usercompcourse tant que personne n'a accédé à une page de compétence le concernant. */
Thomas Fradet's avatar
Thomas Fradet committed
234 235 236 237

	/* IF all params are NULL => do not search students, just display dashboard. */
	if ( isset($_GET['grade']) || isset($_GET['proficiency']) || isset($_GET['review']) ) {

Thomas Fradet's avatar
Thomas Fradet committed
238
		$sql = "SELECT id, userid, proficiency, grade FROM {competency_usercompcourse} 
Thomas Fradet's avatar
Thomas Fradet committed
239
		WHERE courseid = ?
Thomas Fradet's avatar
Thomas Fradet committed
240
		AND userid {$in_sql_stud_ids} AND competencyid = ?";
Thomas Fradet's avatar
Thomas Fradet committed
241 242 243 244 245 246
		$params = array();
		$params[] = $courseid;
		$params = array_merge($params, $params_stud_ids);
		$params[] = $current_cpt->id;
		$course_cpts = $DB->get_records_sql($sql, $params);

Thomas Fradet's avatar
Thomas Fradet committed
247
		$cpt_studs = array();
Thomas Fradet's avatar
Thomas Fradet committed
248
		foreach ($students as $student) {
Thomas Fradet's avatar
Thomas Fradet committed
249 250 251 252 253 254 255
			$cpt_stud = new stdClass();
			$cpt_stud->id = $student->id;
			$cpt_stud->firstname = $student->firstname;
			$cpt_stud->lastname = $student->lastname;
			$cpt_stud->proficiency = NULL;
			$cpt_stud->grade = NULL;
			$cpt_stud->review = NULL;
Thomas Fradet's avatar
Thomas Fradet committed
256 257
			foreach ($course_cpts as $course_cpt) {
				if ( $course_cpt->userid == $student->id ) {
Thomas Fradet's avatar
Thomas Fradet committed
258 259 260 261 262 263 264 265
					$cpt_stud->proficiency = $course_cpt->proficiency;
					$cpt_stud->grade = $course_cpt->grade;
					foreach ($reviews_data as $review) {
						if ( $review->userid == $student->id ) {
							$cpt_stud->review = $review->status;
							break;
						}
					}
Thomas Fradet's avatar
Thomas Fradet committed
266 267 268
					break;
				}
			}
Thomas Fradet's avatar
Thomas Fradet committed
269
			array_push($cpt_studs, $cpt_stud);
Thomas Fradet's avatar
Thomas Fradet committed
270 271
		}

Thomas Fradet's avatar
Thomas Fradet committed
272 273 274 275 276 277 278 279 280
		if ( isset($_GET['review']) && $_GET['review'] == 'yes' ) {
			$cpt_studs = array_filter($cpt_studs, function ($stud) {
				return $stud->review == 1;
			});
		} elseif ( isset($_GET['review']) && $_GET['review'] == 'no' ) {
			$cpt_studs = array_filter($cpt_studs, function ($stud) {
				return $stud->review != 1;
			});
		}
Thomas Fradet's avatar
Thomas Fradet committed
281

Thomas Fradet's avatar
Thomas Fradet committed
282 283 284 285 286 287 288 289 290
		if ( isset($_GET['proficiency']) && $_GET['proficiency'] == 'yes' ) {
			$cpt_studs = array_filter($cpt_studs, function ($stud) {
				return $stud->proficiency == 1;
			});
		} elseif ( isset($_GET['proficiency']) && $_GET['proficiency'] == 'no' ) {
			$cpt_studs = array_filter($cpt_studs, function ($stud) {
				return $stud->proficiency != 1;
			});
		}
Thomas Fradet's avatar
Thomas Fradet committed
291

Thomas Fradet's avatar
Thomas Fradet committed
292 293 294 295 296 297 298 299 300
		if ( isset($_GET['grade']) && $_GET['grade'] == 'no' ) {
			$cpt_studs = array_filter($cpt_studs, function ($stud) {
				return $stud->grade == NULL;
			});
		} elseif ( isset($_GET['grade']) && $_GET['grade'] != 'all' ) {
			$cpt_studs = array_filter($cpt_studs, function ($stud) {
				return $stud->grade == $_GET['grade'];
			});
		}
Thomas Fradet's avatar
Thomas Fradet committed
301

302 303 304
		echo "<div class='row'>"; /* Début student list. */
		echo "<div class='col-12' style='padding: 0;'>";

Thomas Fradet's avatar
Thomas Fradet committed
305 306 307 308 309 310 311 312 313 314 315 316
		if ( count($cpt_studs) == 0 ) {
			echo "<div class='alert alert-warning'>Aucun étudiant ne correspond à la sélection. </div>";
		} else {
			foreach ($cpt_studs as $cpt_stud) {
				$proficient_class = $cpt_stud->proficiency == 1 ? " list-group-item-success" : "";
				$grade_d = $cpt_stud->grade == NULL ? "-" : $current_cpt->scale[$cpt_stud->grade - 1];
				$proficiency_d = $cpt_stud->proficiency == 1 ? "Oui" : "Non";
				echo "
				<a href='#?courseid={$courseid}&studentid={$cpt_stud->id}&competencyid={$current_cpt->id}' class='list-group-item list-group-item-action{$proficient_class}'>
				<div class='d-flex w-100 justify-content-between'>
				<h3 class='mb-1 iena-cpt-action-title'>{$cpt_stud->firstname} {$cpt_stud->lastname}</h3>";
				if ($cpt_stud->review == 1) {
317
					echo "<div><small class='review-badge'>Évaluation demandée</small></div>";
Thomas Fradet's avatar
Thomas Fradet committed
318 319 320 321 322 323 324
				}
				echo "</div>
				<p class='' style='margin-bottom: 0;'>Évaluation : <em>{$grade_d}</em></p>
				<small class=''>Acquis : {$proficiency_d}</small>
				</a>";
			}
		}
Thomas Fradet's avatar
Thomas Fradet committed
325 326 327 328 329 330 331

		echo "</div>";
		echo "</div>"; /* Fin student list. */

	} else {
		/* if all filters are not set ( ! isset GET... ) dont display the stud list */
	}
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349


	echo "</div>"; /* Fin du container bootstrap. */



	/* L'état des compétences du cours pour un utilisateur */
	// $user_course_competencies = \core_competency\api::list_user_competencies_in_course($COURSE->id, 4);
	// $user_course_competencies = \core_competency\api::get_user_competency_in_course($COURSE->id, 4, 1);




	/* ATTENTION : pour les deux vues */

	/* ATTENTION : Les reviews demandées à lister, voire dans l'api list_user_competencies_to_review ou trouver si c'est dans l'objet de base */

	/* ATTENTION : la compétence dans l'absolut versus dans le cours : ça apparait où ??? */
350

351 352 353
	/* list_course_modules_using_competency */
	/* list_course_module_competencies_in_course_module */
	/* list_course_module_competencies */
354

355 356
	echo $OUTPUT->footer();
}