projet-php/managers/RDV.class.php

122 lines
5.8 KiB
PHP
Raw Normal View History

<?php
/**
* Created by PhpStorm.
* User: seekdasky
* Date: 10/12/15
* Time: 09:52
*/
class RDV
{
public function add($params){
2015-12-17 08:53:09 +00:00
if(StaticRepo::checkParam($params['date'],'Date')) {
$params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']);
if (RDVRepo::add($params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00', $params['duree'], $params['id_patient'], $params['id_medecin']) !== FALSE) {
2015-12-17 08:53:09 +00:00
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' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].' a bien été créée.'
]));
2015-12-17 08:53:09 +00:00
}else{
$response = new Response();
2015-12-17 08:53:09 +00:00
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=creation");
$response->send();
2015-12-17 08:53:09 +00:00
}
}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!'
]));
2015-12-17 08:53:09 +00:00
}else{
$response->send();
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
}
}
}else{
2015-12-17 08:53:09 +00:00
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur de paramètre',
'message' => 'Date incorrecte'
]));
2015-12-17 08:53:09 +00:00
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
$response->send();
}
}
}
public function delete($params){
if(RDVRepo::delete($params['id_consultation']) !==FALSE){
2015-12-17 08:53:09 +00:00
if( !empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Supression effectuée!',
'message' => 'La consultation a bien été supprimée.'
]));
2015-12-17 08:53:09 +00:00
}else{
$response = new Response();
2015-12-17 08:53:09 +00:00
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=supression");
$response->send();
2015-12-17 08:53:09 +00:00
}
}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!'
]));
2015-12-17 08:53:09 +00:00
}else{
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
$response->send();
}
}
}
public function update($params){
if(StaticRepo::checkParam($params['date_naissance'],'Date')) {
$params['date'] = DateTime::createFromFormat('d/m/Y', $params['date']);
if (RDVRepo::updateDateTime($params['id_consultation'], $params['date']->format('Y-m-d') . ' ' . $params['heure'] . ':00') !== FALSE) {
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=maj");
$response->send();
}else{
Response::quickResponse(200, json_encode([
'status' => 'success',
'title' => 'Modification effectuée!',
'message' => 'La consultation du '.$params['date']->format('d/m/Y').' à '.$params['heure'].'a bien été mis àjour.'
]));
}
}else{
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
$response->send();
}else{
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur de mise a jour!'
]));
}
}
}else{
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ){
$response = new Response();
$response->setHeader('Location',"http://".$_SERVER['HTTP_HOST']."/Consultations.php?type=error");
$response->send();
}else{
Response::quickResponse(200, json_encode([
'status' => 'error',
'title' => 'Erreur de paramètre',
'message' => 'Date incorrecte'
]));
}
}
}
}