From c0d17b2c73ca2ad9ee2fb31839f2e5fd9d87741d Mon Sep 17 00:00:00 2001 From: rookiered Date: Sat, 9 Jan 2016 16:02:30 +0100 Subject: [PATCH] =?UTF-8?q?Recherche=20=C3=A9tudiant=20fonctionnelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API.php | 7 ++++-- manager/database.php | 40 +++++++++++++++++++++++++++++++ manager/repo/user.php | 28 ++++++++++++++++++++++ manager/search.php | 55 +++++++++++++++++++++++++++++++++++++++++++ manager/user.php | 26 ++++++++++++++++++++ test.php | 11 ++++++++- 6 files changed, 164 insertions(+), 3 deletions(-) create mode 100644 manager/search.php diff --git a/API.php b/API.php index d4e18b4..c306ecf 100755 --- a/API.php +++ b/API.php @@ -1,4 +1,4 @@ -"; + print_r($answer); + echo ""; } diff --git a/manager/database.php b/manager/database.php index 56c21fb..b212f16 100755 --- a/manager/database.php +++ b/manager/database.php @@ -1317,6 +1317,46 @@ class DataBase{ } + /*************************************************************************************************** + + ** ad88888ba 88888888888 db 88888888ba ,ad8888ba, 88 88 ** + ** d8" "8b 88 d88b 88 "8b d8"' `"8b 88 88 ** + ** Y8, 88 d8'`8b 88 ,8P d8' 88 88 ** + ** `Y8aaaaa, 88aaaaa d8' `8b 88aaaaaa8P' 88 88aaaaaaaa88 ** + ** `"""""8b, 88""""" d8YaaaaY8b 88""""88' 88 88""""""""88 ** + ** `8b 88 d8""""""""8b 88 `8b Y8, 88 88 ** + ** Y8a a8P 88 d8' `8b 88 `8b Y8a. .a8P 88 88 ** + ** "Y88888P" 88888888888 d8' `8b 88 `8b `"Y8888Y"' 88 88 ** + + *****************************************************************************************************/ + + public static function searchForUsers($nom){ + + $retour = userRepo::search($nom); + if (!$retour || $retour === array()) { + return false; + } + else { + //On classe les résultats en fonction de si c'est un étudiant ou bien un professeur + $etudiants = array(); + foreach ($retour as $num => $user) { + //On supprime tous les administrateurs des résultats + if($user['droits'] == 'admin'){ + unset($retour[$num]); + } + //On récupère les étudiants dans un tableau différent et on efface les entrées dans le tableau retour + elseif ($user['droits'] == 'student') { + $etudiants[] = $user; + unset($retour[$num]); + } + } + $retour[] = $etudiants; + return array_values($retour); + } + } + + + } ?> diff --git a/manager/repo/user.php b/manager/repo/user.php index 36bf8df..cee0cc7 100755 --- a/manager/repo/user.php +++ b/manager/repo/user.php @@ -498,4 +498,32 @@ class userRepo{ } + + + + + /** + * Fonction search : recherche dans la bae de données un utilisateur + * Pour se faire on recherche un mot clé contenu dans le nom ou le prénom de l'utilisateur + * + * @param $mot: le mot clé de la recherche associée + * @return le tableau des résultats, ou false en cas d'erreur + *==================================================================================================> + */ + public static function search($mot){ + //Vérification du paramètre: + if (! checkParam($mot, '')) { + return false; + } + //On recherche dans la table utilisateur dans les noms et prénoms qui contiendraient une ccurence de "mot" + $statement = DataBase::getPDO()->prepare("SELECT * FROM utilisateur". + " WHERE nom LIKE :nom OR :prenom OR nom = :mot OR prenom = :mot ;"); + $ret = $statement->execute(array(':nom' => '%'.$mot.'%', + ':prenom' => '%'.$mot.'%', + ':mot' => $mot)); + if($ret) + return $statement->fetchAll(); + return false; + } + } \ No newline at end of file diff --git a/manager/search.php b/manager/search.php new file mode 100644 index 0000000..da1ab57 --- /dev/null +++ b/manager/search.php @@ -0,0 +1,55 @@ +keywords) || $request->keywords == '' || !checkParam($request->keywords, '') { + $answer->request = 'error_keyword'; + return null; + } + + //Récupération des mots clés envoyés + $key = explode(' ', $request->keywords); + + //Cas d'utilisation 1 : ADMINISTRATEUR + if (permission('admin') || permission('master')) { + //Préparation de la variable contenant les résultats + $resultats = array('prof' => array(), 'etudiant' => array(),'module' => array(), 'groupe' => array()); + + //Recherche du nom de l'étudiant - prénom de l'étudiant (dans les deux ordres) + $etudiants = Database:: + + //Recherche du nom de l'enseignant - prénom de l'enseignant + $profs = Database::listeUtilisateursRole(); + foreach ($profs as $prof) { + foreach ($key as $mot) { + //On regarde s'il y a correspondance avec les différents paramètres de recherche + if (strpos(strtolower($prof['prenom']), strtolower($mot)) !== false + || strpos(strtolower($prof['nom']), strtolower($mot)) !== false ) { + $resultats['prof'][] = $prof; + } + } + } + + //Recherche dans le nom du module - numéro module + $modules = Database::getExhaustiveModuleList(); + foreach ($mud as $mod) { + if (strpos(strtolower($mod['prenom']), strtolower($mot)) !== false) { + $resultats['prof'][] = $prof; + } + } + + //Recherche dans le nom du groupe + $groupes + } + + + } +} + + + +?> \ No newline at end of file diff --git a/manager/user.php b/manager/user.php index c17ec9d..b7a1d4d 100755 --- a/manager/user.php +++ b/manager/user.php @@ -184,7 +184,33 @@ class userManager{ break; + /***********************/ + /* MOTEUR DE RECHERCHE */ + /***********************/ + case 'search': + //On vérifie qu'on a bien les mots clés + if (isset($request->keywords) && $request->keywords != '') { + //On explode les mots clés + $keys = explode(' ', $request->keywords); + //Pour chaque mot clé on lance une recherche dans la bdd + foreach ($keys as $mot) { + $retour = null; + //On cherche d'abord en fonction du nom... + $retour = DataBase::searchForUsers($mot); + //Si il y a un résultat de recherche alors on le stock dans résultat + if ($retour === false) { + $answer->results = null; + } + else { + $answer->results = $retour; + } + } + } + else { + $answer->request = 'no_keywords'; + } + break; /***********/ /* DEFAULT */ diff --git a/test.php b/test.php index 2455ce3..5a1f026 100755 --- a/test.php +++ b/test.php @@ -425,10 +425,19 @@ require_once __ROOT__.'/manager/security.php'; +$req = new stdClass(); +$ans = new stdClass(); + +$req->level_0 = 'user'; +$req->level_1 = 'search'; +$req->keywords = 'nometu Etud11'; + +$_POST['json'] = json_encode($req); +include 'API.php'; +?> -?> \ No newline at end of file