diff --git a/manager/database.php b/manager/database.php index ac766d3..de4da0f 100755 --- a/manager/database.php +++ b/manager/database.php @@ -112,8 +112,8 @@ class DataBase{ foreach($module['controles'] as $controle){ - // $controle = controleRepo::forMCC($mcc_module, $controle['nom'], $controle['libelle'], $controle['coefficient']); - + $controle_uid = controleRepo::forMCC($mcc_module, $controle['nom'], $controle['libelle'], $controle['coefficient']); + // var_dump( $controle_uid ); // echo '    '.$controle['nom'].'
'; } diff --git a/manager/repo/controle.php b/manager/repo/controle.php index c190e43..3f5ed4d 100755 --- a/manager/repo/controle.php +++ b/manager/repo/controle.php @@ -128,4 +128,66 @@ class controleRepo extends DBAccess{ return DataBase::delNumeric( $getControleList->fetchAll() ); } + + + + + + + + + /* retourne l'UID d'un contrôle s'il existe sinon créé tout ce qui a besoin et on retourne l'UID + * + * @mcc_module l'UID du mcc_module en question + * @nom le code du contrôle en question + * @libelle le libellé du contrôle en question + * @coefficient le coefficient du contrôle en question dans le mcc_module en question + * + * + * @return UID retourne l'UID du CONTRÔLE si tout s'est bien passé + * @return FALSE retourne FALSE s'il y a eu une erreur + * + */ + public static function forMCC($mcc_module, $nom, $libelle, $coefficient){ + $count = 0; $maxLoop = 2; + + /* ON VÉRIFIE QUE L'UE EN LUI-MÊME (NOM/LIBELLÉ) EXISTE DANS LA BDD */ + $getControleUID = DataBase::getPDO()->prepare("SELECT ctrl.id_controle as id + FROM mcc_module as mcc_m, controle as ctrl + WHERE ctrl.id_mcc_module = mcc_m.id_mcc_module + AND mcc_m.id_mcc_module = :mcc_module + AND ctrl.nom = :nom + AND ctrl.libelle = :libelle + AND ctrl.coefficient = :coefficient"); + $getControleUID->execute(array( ':mcc_module' => $mcc_module, ':nom' => $nom, ':libelle' => $libelle, ':coefficient' => $coefficient )); + + while( !$controleUID = $getControleUID->fetch()['id'] ){ // on vérifie l'existence de ce contrôle + + /* [1] SI LE CONTRÔLE N'EXISTE PAS => ON LE CRÉÉ + =====================================================*/ + echo "$mcc_module|$nom|$libelle|$coefficient
"; + $creerControle = DataBase::getPDO()->prepare("INSERT INTO controle(id_controle, id_mcc_module, nom, libelle, coefficient, date_publication) + VALUES(DEFAULT, :mcc_module, :nom, :libelle, :coefficient, NOW())"); + $creerControle->execute(array( ':mcc_module' => $mcc_module, ':nom' => $nom, ':libelle' => $libelle, ':coefficient' => $coefficient )); + + /* ON VÉRIFIE QUE LE MODULE APPARTIENT AU MCC DE CE MCC_UE */ + $getControleUID = DataBase::getPDO()->prepare("SELECT ctrl.id_controle as id + FROM mcc_module as mcc_m, controle as ctrl + WHERE ctrl.id_mcc_module = mcc_m.id_mcc_module + AND mcc_m.id_mcc_module = :mcc_module + AND ctrl.nom = :nom + AND ctrl.libelle = :libelle + AND ctrl.coefficient = :coefficient"); + $getControleUID->execute(array( ':mcc_module' => $mcc_module, ':nom' => $nom, ':libelle' => $libelle, ':coefficient' => $coefficient )); + + if( $count >= $maxLoop ) return false; + $count++; + + } + + // on retourne enfin l'UID du mcc_ue en question + return $controleUID; + + } + } \ No newline at end of file diff --git a/manager/repo/module.php b/manager/repo/module.php index 24b3444..379a403 100755 --- a/manager/repo/module.php +++ b/manager/repo/module.php @@ -205,7 +205,7 @@ class moduleRepo extends DBAccess{ $getModuleUID = DataBase::getPDO()->prepare("SELECT id_module as id FROM module WHERE nom = :nom AND libelle = :libelle"); $getModuleUID->execute(array( ':nom' => $nom, ':libelle' => $libelle )); - while( !$moduleUID = $getModuleUID->fetch()['id'] ){ // on vérifie l'existence de cet UE + while( !$moduleUID = $getModuleUID->fetch()['id'] ){ // on vérifie l'existence de ce module /* [1] SI LE MODULE N'EXISTE PAS => ON LE CRÉÉ =====================================================*/ diff --git a/page/modules.php b/page/modules.php index 9b134fa..8886d51 100755 --- a/page/modules.php +++ b/page/modules.php @@ -490,7 +490,7 @@ if( permission('admin') ){ // si l'utilisateur est un admin -if( false && permission('admin') ){ +if( permission('admin') ){ require_once __ROOT__.'/manager/phpExcel.php'; require_once __ROOT__.'/manager/database.php'; @@ -509,7 +509,7 @@ if( false && permission('admin') ){ $semestre = 1; - // var_dump( DataBase::getInstance()->setMCC($semestre, $answer->mcc) ); + var_dump( DataBase::getInstance()->setMCC($semestre, $answer->mcc) ); echo ""; }else