Commit ebd9c558 authored by Thomas Fradet's avatar Thomas Fradet

cpt x users refact ok

parent 708205d9
......@@ -176,10 +176,10 @@ if (count($course_cpts) === 0) {
/* ===== FILTERS ===== */
/* There is 2 forms witch use data from each other while submitting. */
echo "<div class='alert alert-secondary row' id='stud_filters'>"; /* Début filtres. */
echo "<div class='alert alert-secondary row'>"; /* Début filtres. */
echo "<div class='col-12'>";
echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competency_students_2.php#stud_filters' class='form-inline'>";
echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/competency_iena_competency_students_2.php' class='form-inline'>";
echo "<input type='text' hidden name='courseid' value='{$COURSE->id}'>";
echo "<input type='text' hidden name='competencyid' value='{$current_cpt->id}'>";
......@@ -214,11 +214,11 @@ if (count($course_cpts) === 0) {
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>
<option value='0'";
if ( $form_review == '0' ) { echo 'selected'; }
<option value='no'";
if ( $form_review == 'no' ) { echo 'selected'; }
echo ">Non</option>
<option value='1'";
if ( $form_review == '1' ) { echo 'selected'; }
<option value='yes'";
if ( $form_review == 'yes' ) { echo 'selected'; }
echo ">Oui</option>
</select>";
......@@ -230,126 +230,98 @@ if (count($course_cpts) === 0) {
/* ===== STUDENT LIST ===== */
/* NB : un étudiant n'existe pas en base competency_usercompcourse tant que personne n'a accédé à une page de compétence le concernant. Donc pour afficher des données, il faut boucler sur les utilisateurs et pour chaque utilisateur sur les données en base : si correspondance, on peut afficher de "vraies" données (p.ex. "Compétent"), sinon, afficher des données vides car de toutes façon elles n'existent pas (p.ex. "Non évalué"). */
/* NB : un étudiant n'existe pas en base competency_usercompcourse tant que personne n'a accédé à une page de compétence le concernant. */
/* IF all params are NULL => do not search students, just display dashboard. */
if ( isset($_GET['grade']) || isset($_GET['proficiency']) || isset($_GET['review']) ) {
if ( !isset($_GET['grade']) || $_GET['grade'] == 'all' ) {
$sql_grade = "";
} elseif ( $_GET['grade'] == 'no' ) {
$sql_grade = " AND grade IS NULL";
} else {
$sql_grade = " AND grade = ?";
}
if ( !isset($_GET['proficiency']) || $_GET['proficiency'] == 'all' ) {
$sql_proficiency = "";
} elseif ($_GET['proficiency'] == 'no') {
/* not proficient is "= 0" => "NULL && 0" */
$sql_proficiency = " AND (proficiency = ? OR proficiency IS NULL)";
} else {
$sql_proficiency = " AND proficiency = ?";
}
echo "<div class='row'>"; /* Début student list. */
echo "<div class='col-12'>";
/* $course_cpts_ids IN sql (idem pour studs) */
$course_cpts_ids = array();
foreach ($course_cpts as $key => $cpt) {
$course_cpts_ids[] = intval($cpt->get('id'));
}
/* $in_sql => string "IN (?, ?, etc.) // $params array(1, 2, etc.) */
/* already defined list($in_sql_stud_ids, $params_stud_ids) = $DB->get_in_or_equal($student_ids);*/
list($in_sql_cpts_ids, $params_cpts_ids) = $DB->get_in_or_equal($course_cpts_ids);
$sql = "SELECT * FROM {competency_usercompcourse}
$sql = "SELECT id, userid, proficiency, grade FROM {competency_usercompcourse}
WHERE courseid = ?
AND userid {$in_sql_stud_ids} AND competencyid = ?{$sql_grade}{$sql_proficiency}";
AND userid {$in_sql_stud_ids} AND competencyid = ?";
$params = array();
$params[] = $courseid;
$params = array_merge($params, $params_stud_ids);
$params[] = $current_cpt->id;
if ( isset($_GET['grade']) && $_GET['grade'] !== 'all' && $_GET['grade'] !== 'no' ) {
$params[] = $_GET['grade'];
}
if ( isset($_GET['proficiency']) && $_GET['proficiency'] !== 'all' ) {
$params[] = $_GET['proficiency'] == 'no' ? 0 : 1;
}
$course_cpts = $DB->get_records_sql($sql, $params);
/* LIST PRINT */
$include_all_studs = false;
if ( isset($_GET['grade']) && isset($_GET['proficiency']) ) {
if ( $_GET['grade'] == 'all' && $_GET['proficiency'] == 'all' ) {
$include_all_studs = true;
}
if ( $_GET['grade'] == 'all' && $_GET['proficiency'] == 'no' ) {
$include_all_studs = true;
}
if ( $_GET['grade'] == 'no' && $_GET['proficiency'] == 'all' ) {
$include_all_studs = true;
}
if ( $_GET['grade'] == 'no' && $_GET['proficiency'] == 'no' ) {
$include_all_studs = true;
}
}
$list_count = 0;
$cpt_studs = array();
foreach ($students as $student) {
$grade_d = "-";
$proficiency_d = "Non";
$display = false;
$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;
foreach ($course_cpts as $course_cpt) {
if ( $course_cpt->userid == $student->id ) {
$display = true;
$grade_d = $course_cpt->grade == NULL ? "-" : $current_cpt->scale[$course_cpt->grade - 1];
$proficiency_d = $course_cpt->proficiency == 1 ? "Oui" : "Non";
echo "<p>$grade_d</p>";
echo "<p>$proficiency_d</p>";
$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;
}
}
break;
}
}
if ( $display || $include_all_studs ) {
$list_count++;
$color = $proficiency_d == "Oui" ? "success" : "secondary";
echo "<div class='alert alert-{$color}'>";
echo "<h4>{$student->firstname} {$student->lastname} ({$student->id})</h4>";
echo "<p>Évaluation : {$grade_d}</p>";
echo "<p>Acquis : {$proficiency_d}</p>";
echo "<p>Demande d'évaluation : {OUI/NON}</p>";
echo "</div>";
}
array_push($cpt_studs, $cpt_stud);
}
echo "$list_count";
echo "<pre>";
// echo "<h1>review data</h1>";
// var_dump($reviews_data);
// echo "<h1>course user comp list</h1>";
// foreach ($course_cpts as $key => $course_cpt) {
// var_dump($course_cpt);
// echo "<hr>";
// }
// echo "<h1>students</h1>";
// var_dump($students);
echo "</pre>";
/* AFFICHER */
/* Pour chaque étudiant du cours */
/* Pour chaque étudiant résultat de la requête */
/* Si l'étudiant correspond */
/* Afficher données */
/* Sinon */
/* Afficher ligne standard vide car étu pas en base car jamais accédé à la page cpt */
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;
});
}
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;
});
}
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'];
});
}
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) {
echo "<small class=''>Évaluation demandée</small>";
}
echo "</div>
<p class='' style='margin-bottom: 0;'>Évaluation : <em>{$grade_d}</em></p>
<small class=''>Acquis : {$proficiency_d}</small>
</a>";
}
}
echo "</div>";
echo "</div>"; /* Fin student list. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment