competency_iena_competency_students_2.php 15 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
/* 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'));
55
	$PAGE->requires->js("/blocks/competency_iena/js/dropdown.js");
56 57 58 59 60 61 62 63
	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
64
		$student_ids[] = intval($stud->id);
65 66
	}

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

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

Thomas Fradet's avatar
css fix  
Thomas Fradet committed
72
	echo "<div class='alert row' style='padding: 0; background-color: inherit; color: inherit;'>"; /* Début change competency. */
73
	echo "<div class='col-12' style='padding-left: 0;'>";
74
	echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competency_students_2.php' id='change_cpt_form' class='form-inline' autocomplete='off' style='display: block;height: 1.5rem;'>";
75
	echo "<input type='text' hidden name='courseid' value='{$COURSE->id}'>";
Thomas Fradet's avatar
Thomas Fradet committed
76 77 78 79 80 81 82 83 84
	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']}'>";
	}
85
	echo "<span hidden id='competencyid'>{$current_cpt->id}</span>";
86 87 88 89 90 91 92 93 94 95 96 97 98 99
	
	// 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 "<div id='student_dropdown' class='iena-dropdown' style='z-index: 1;'>";
	echo "<input type='text' hidden name='competencyid' id='competencyid_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='{$current_cpt->shortname}' autocomplete='nope'><button class='btn btn-secondary' id='prevCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button><button class='btn btn-secondary' id='nextCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button>";
	echo "<div class='iena-droplist' id='competency_list'>";
100
	foreach ($course_cpts as $course_cpt) {
101
		echo "<a href='#' data-value='{$course_cpt->get('id')}' class='iena-drop-item' style='display: none;'>{$course_cpt->get('shortname')}</a>";
102
	}
103 104 105
	echo "</div>";
	echo "</div>";
	
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
	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
124
	echo "<h2 class='h4'>Compétences validées</h2>";
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

	$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
170 171 172 173 174 175 176 177 178 179

	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);
180 181 182 183 184 185 186

	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
187
	/* There is 2 forms witch use data from each other while submitting. */
188

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

Thomas Fradet's avatar
Thomas Fradet committed
192
	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
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
	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
227 228
	<option value='no'";
	if ( $form_review == 'no' ) { echo 'selected'; }
Thomas Fradet's avatar
Thomas Fradet committed
229
	echo ">Non</option>
Thomas Fradet's avatar
Thomas Fradet committed
230 231
	<option value='yes'";
	if ( $form_review == 'yes' ) { echo 'selected'; }
Thomas Fradet's avatar
Thomas Fradet committed
232 233 234
	echo ">Oui</option>
	</select>";
	
235 236 237 238 239 240 241 242
	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
243
	/* 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
244 245 246 247

	/* 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
248
		$sql = "SELECT id, userid, proficiency, grade FROM {competency_usercompcourse} 
Thomas Fradet's avatar
Thomas Fradet committed
249
		WHERE courseid = ?
Thomas Fradet's avatar
Thomas Fradet committed
250
		AND userid {$in_sql_stud_ids} AND competencyid = ?";
Thomas Fradet's avatar
Thomas Fradet committed
251 252 253 254 255 256
		$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
257
		$cpt_studs = array();
Thomas Fradet's avatar
Thomas Fradet committed
258
		foreach ($students as $student) {
Thomas Fradet's avatar
Thomas Fradet committed
259 260 261 262 263 264 265
			$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
266 267
			foreach ($course_cpts as $course_cpt) {
				if ( $course_cpt->userid == $student->id ) {
Thomas Fradet's avatar
Thomas Fradet committed
268 269 270 271 272 273 274 275
					$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
276 277 278
					break;
				}
			}
Thomas Fradet's avatar
Thomas Fradet committed
279
			array_push($cpt_studs, $cpt_stud);
Thomas Fradet's avatar
Thomas Fradet committed
280 281
		}

Thomas Fradet's avatar
Thomas Fradet committed
282 283 284 285 286 287 288 289 290
		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
291

Thomas Fradet's avatar
Thomas Fradet committed
292 293 294 295 296 297 298 299 300
		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
301

Thomas Fradet's avatar
Thomas Fradet committed
302 303 304 305 306 307 308 309 310
		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
311

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

Thomas Fradet's avatar
Thomas Fradet committed
315 316 317 318 319 320 321 322
		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 "
Thomas Fradet's avatar
Thomas Fradet committed
323
				<a href='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php?courseid={$courseid}&studentid={$cpt_stud->id}&competencyid={$current_cpt->id}' class='list-group-item list-group-item-action{$proficient_class}'>
Thomas Fradet's avatar
Thomas Fradet committed
324 325 326
				<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) {
327
					echo "<div><small class='review-badge'>Évaluation demandée</small></div>";
Thomas Fradet's avatar
Thomas Fradet committed
328 329 330 331 332 333 334
				}
				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
335 336 337 338 339 340 341

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

	} else {
		/* if all filters are not set ( ! isset GET... ) dont display the stud list */
	}
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359


	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ù ??? */
360

361 362 363
	/* list_course_modules_using_competency */
	/* list_course_module_competencies_in_course_module */
	/* list_course_module_competencies */
364

365 366
	echo $OUTPUT->footer();
}