projet-php/managers/Medecin.class.php

93 lines
3.9 KiB
PHP
Executable File

<?php
/**
* Created by PhpStorm.
* User: seekdasky
* Date: 10/12/15
* Time: 10:02
*/
class Medecin
{
public function add($params){
if(MedecinRepo::add($params['civilite'],strtolower($params['prenom']),strtolower($params['nom'])) !==FALSE){
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Création effectuée!',
'message' => 'Le médecin '.$params['prenom'].' '.$params['nom'].' a bien été créé.'
]));
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation");
$response->send();
}
}else{
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur de création!'
]));
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
$response->send();
}
}
}
public function search($params){
if( ($medList=MedecinRepo::search(strtolower($params['nom']), strtolower($params['prenom']))) !== FALSE ){
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'success',
'medecins' => $medList
]));
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=creation");
$response->send();
}
}else{
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Oups!',
'message' => 'Aucun médecin trouvé.'
]));
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
$response->send();
}
}
}
public function delete($params){
if(MedecinRepo::delete($params['id_medecin']) !==FALSE){
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Médecin supprimé!',
'message' => ''
]));
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=supression");
$response->send();
}
}else{
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur lors de la supression!'
]));
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Medecins.php?type=error");
$response->send();
}
}
}
}