sid/manager/repo/semestre.php

303 lines
10 KiB
PHP
Raw Normal View History

<?php require_once __ROOT__.'/manager/security.php';
/**************************************************************************************/
/* ____ _____ __ __ _____ ____ _____ ____ _____ ____ _____ ____ ___ */
/* / ___|| ____| \/ | ____/ ___|_ _| _ \| ____| | _ \| ____| _ \ / _ \ */
/* \___ \| _| | |\/| | _| \___ \ | | | |_) | _| | |_) | _| | |_) | | | | */
/* ___) | |___| | | | |___ ___) || | | _ <| |___ | _ <| |___| __/| |_| | */
/* |____/|_____|_| |_|_____|____/ |_| |_| \_\_____| |_| \_\_____|_| \___/ */
/* */
/**************************************************************************************/
/*
* CONTENU DU REPO
*
* [1] UID(formation, rang, annee)
* retourne l'UID d'un semestre pour un rang et une année donnée
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
class semestreRepo extends DBAccess{
/* VERIFIE L'EXISTENCE D'UN SEMESTRE DANS LA BDD
*
* @formation<int> l'UID de la formation en question
* @rang<int> le rang du semestre dans le parcours (1<=>S1, 2<=>S2, ..)
* @annee<int> l'année du début du parcours
*
*
* @return UID<int> si le semestre est dans la BDD, retourne son UID (auto_incr)
* @return FALSE<Boolean> FAUX si aucun semestre avec ce rang et annee n'est pas présent dans la BDD
*
*/
public static function UID($formation, $rang, $annee){
/*** on cherche un semestre avec ce rang et cette année (qui est forcément unique) ***/
$getSemestreUID = DataBase::getPDO()->prepare("SELECT s.id_semestre as id
FROM semestre as s, formation as f
WHERE s.id_formation = f.id_formation
AND s.id_formation = :formation
AND s.rang = :rang
AND s.annee = :annee");
$getSemestreUID->execute(array(
':formation' => $formation,
':rang' => $rang,
':annee' => $annee
));
// on retourne le résultat : FAUX si aucun résultat, sinon la valeur de l'UID du semestre
return $getSemestreUID->fetch()['id'];
}
/* RENVOIE LES INFORMATIONS D'UN SEMESTRE D'UID DONNÉ
*
* @semestreUID<int> l'UID du semestre duquel on veut les infos
*
* @return semestre<Array> tableau associatif contenant tout les champs de la BDD pour ce semestre
*
*/
public static function info($semestreUID){
// on considère que le semestre existe
$getSemestreInfo = DataBase::getPDO()->prepare("SELECT s.id_semestre as id, s.nom, s.rang, s.annee, f.id_formation, f.code as formation, f.nom as nom_formation
FROM semestre as s, formation as f
WHERE s.id_formation = f.id_formation
AND s.id_semestre = :semestreUID");
2015-11-11 14:50:05 +00:00
$getSemestreInfo->execute(array( ':semestreUID' => $semestreUID ));
// on retourne le résultat en supprimant les doublons à indices numériques
2015-11-11 14:50:05 +00:00
return $getSemestreInfo->fetch();
}
/* RENVOIE LA LISTE DES ANNÉES PRÉSENTES DANS LA BDD
*
* @return annees<Array> retourne la liste des années contenues dans la bdd
* @return FALSE<Boolean> retourne FALSE si aucune année n'est trouvée
*
*/
public static function getAnnees(){
$getAnneesList = DataBase::getPDO()->query("SELECT DISTINCT annee FROM semestre ORDER BY annee DESC");
return DataBase::delNumeric( $getAnneesList->fetchAll() );
}
/* retourne le semestre courant d'un étudiant
*
* @etudiant<String> l'identifiant (UID) de l'étudiant en question
* @semestre_pair<Boolean> VRAI si le semestre courant est pair
* @annee<String> l'année en cours
*
* @return etudie<Boolean> FALSE si l'étudiant n'est dans aucun semestre en cours
* @return semestre<Array> retourne les données relatives au semestre
*
*/
public static function forStudent($etudiant, $semestre_pair, $annee){
// on formate les variables
$semestre_pair = ($semestre_pair) ? '0' : '1';
$getSemestreUID = DataBase::getPDO()->prepare("SELECT s.id_semestre as id, f.id_formation, f.code as formation, f.nom as nom_formation
FROM semestre as s, appartenance as app, formation as f
WHERE s.id_formation = f.id_formation
AND app.id_semestre = s.id_semestre
AND app.id_etudiant = :etudiant
AND s.annee = :annee
AND s.rang % 2 = :semestre_pair
ORDER BY s.rang DESC");
$getSemestreUID->execute(array(
':etudiant' => $etudiant,
':annee' => $annee,
':semestre_pair' => $semestre_pair
));
// on retourne les infos du semestre courant
return $getSemestreUID->fetch();
}
/* retourne la liste des semestres qu'à un enseignant
*
* @enseignant<String> l'UID de l'enseignant en question
* @semestre_pair<Boolean> VRAI si le semestre en cours est pair
* @annee<int> l'année en question
*
*
* @return semestres<Array> retourne la liste des semestres répondant aux critères
* @return FALSE<Boolean> retourne FALSE si aucun semestre ne correspond aux critères
*
*/
public static function forTeacher($enseignant, $semestre_pair, $annee){
$getSemestreList = DataBase::getPDO()->prepare("SELECT DISTINCT s.id_semestre as id, f.id_formation, f.code as formation, f.nom as nom_formation, s.nom, s.rang, s.annee
FROM semestre as s, formation as f, enseignement as ens, mcc_module as mcc_m, mcc_ue
WHERE s.id_semestre = mcc_ue.id_semestre
AND s.id_formation = f.id_formation
AND mcc_ue.id_mcc_ue = mcc_m.id_mcc_ue
AND mcc_m.id_mcc_module = ens.id_mcc_module
AND ens.id_enseignant = :enseignant
AND s.rang % 2 = :semestre_pair
AND s.annee = :annee
ORDER BY s.rang ASC");
$getSemestreList->execute(array( ':enseignant' => $enseignant, ':semestre_pair' => ($semestre_pair) ? '0' : '1', ':annee' => $annee ));
return DataBase::delNumeric( $getSemestreList->fetchAll() );
}
/* retourne la liste des semestres d'une année
*
* @annee<int> l'année en question
*
*
* @return semestres<Array> retourne la liste des semestres de cette année
* @return FALSE<Boolean> retourne FALSE si aucun semestre ne correspond aux critères
*
*/
public static function forYear($annee){
$getSemestreList = DataBase::getPDO()->prepare("SELECT DISTINCT s.id_semestre as id, f.id_formation, f.code as formation, f.nom as nom_formation, s.nom, s.rang, s.annee
FROM semestre as s, formation as f
WHERE s.id_formation = f.id_formation
AND annee = :annee
ORDER BY rang ASC");
$getSemestreList->execute(array( ':annee' => $annee ));
return DataBase::delNumeric( $getSemestreList->fetchAll() );
}
/* RETOURNE LE NOMBRE D'ÉLÈVES D'UN SEMESTRE
*
* @semestre<int> l'UID du semestre en question
*
*
* @return nbEtu<int> retourne le nombre d'étudiants du semestre
*
*/
public static function nbEtuForSemestre($semestre){
$getNbEtu = DataBase::getPDO()->prepare("SELECT count(distinct id_appartenance) as nb_etudiants
FROM appartenance
WHERE id_semestre = :semestre");
$getNbEtu->execute(array( ':semestre' => $semestre ));
if( !($nb = $getNbEtu->fetch()) )
return 0; // si on en trouve pas, on retourne 0
else
return (int) $nb['nb_etudiants']; // sinon on retourne le nombre
}
/* retourne l'UID d'un semestre s'il existe sinon créé tout ce qui a besoin et on retourne l'UID
*
* @codeFormation<String> le code/nom de la formation
* @nomFormation<String> le libellé de la formation
* @nomSemestre<String> le nom/libellé du semestre
* @rangSemestre<int> le rang du semestre dans la formation
* @annee<int> l'année du semestre
*
*
* @return UID<int> retourne l'UID du semestre si tout s'est bien passé
* @return FALSE<Boolean> retourne FALSE s'il y a eu une erreur
*
*/
public static function creer($codeFormation, $nomFormation, $nomSemestre, $rangSemestre, $annee){
$count = 0; $maxLoop = 2;
/* [1] On vérifie l'existence de la formation (code uniquement)
====================================================================================*/
$getFormationUID = DataBase::getPDO()->prepare("SELECT f.id_formation as id
FROM formation as f
WHERE f.code = :code");
$getFormationUID->execute(array( ':code' => $codeFormation ));
while( !($formationUID=$getFormationUID->fetch()['id']) ){
/* [2] on créé la formation car elle n'existe pas
================================================================================*/
$creerFormation = DataBase::getPDO()->prepare("INSERT INTO formation(id_formation, code, nom, nb_semestres)
VALUES(DEFAULT, :code, :nom, 2)");
$creerFormation->execute(array( ':code' => $codeFormation, ':nom' => $nomFormation ));
if( $count >= $maxLoop ) return false;
$count++;
$getFormationUID = DataBase::getPDO()->prepare("SELECT f.id_formation as id
FROM formation as f
WHERE f.code = :code");
$getFormationUID->execute(array( ':code' => $codeFormation ));
}
/* [3] On vérifie l'existence du semestre (rang, annee, nom, formation)
====================================================================================*/
$getSemestreUID = DataBase::getPDO()->prepare("SELECT s.id_semestre as id
FROM semestre as s, formation as f
WHERE s.id_formation = f.id_formation
AND f.id_formation = :formationUID
AND s.nom = :nom
AND s.rang = :rang
AND s.annee = :annee");
$getSemestreUID->execute(array( ':formationUID' => $formationUID, ':nom' => $nomSemestre, ':rang' => $rangSemestre, ':annee' => $annee ));
while( !($semestreUID = $getSemestreUID->fetch()['id']) ){
/* [4] on créé le semestre car il n'existe pas
================================================================================*/
$creerSemestre = DataBase::getPDO()->prepare("INSERT INTO semestre(id_semestre, id_formation, nom, rang, annee)
VALUES(DEFAULT, :formationUID, :nom, :rang, :annee)");
$creerSemestre->execute(array( ':formationUID' => $formationUID, ':nom' => $nomSemestre, ':rang' => $rangSemestre, ':annee' => $annee ));
if( $count >= $maxLoop ) return false;
$count++;
$getSemestreUID = DataBase::getPDO()->prepare("SELECT s.id_semestre as id
FROM semestre as s, formation as f
WHERE s.id_formation = f.id_formation
AND f.id_formation = :formationUID
AND s.nom = :nom
AND s.rang = :rang
AND s.annee = :annee");
$getSemestreUID->execute(array( ':formationUID' => $formationUID, ':nom' => $nomSemestre, ':rang' => $rangSemestre, ':annee' => $annee ));
}
return $semestreUID;
}
}