public function add($params) { 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) { 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.'])); } else { $response = new Response(); $response->setHeader('Location', "http://" . $_SERVER['HTTP_HOST'] . "/Consultations.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->send(); $response = new Response(); $response->setHeader('Location', "http://" . $_SERVER['HTTP_HOST'] . "/Consultations.php?type=error"); } } } 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 paramètre', 'message' => 'Date incorrecte'])); } else { $response = new Response(); $response->setHeader('Location', "http://" . $_SERVER['HTTP_HOST'] . "/Consultations.php?type=error"); $response->send(); } } }
<?php /** * Created by PhpStorm. * User: seekdasky * Date: 03/12/15 * Time: 11:52 */ require_once 'autoloader.php'; $jsonP = json_decode(file_get_contents('Docs/PatientExemple.json'), true); $jsonM = json_decode(file_get_contents('Docs/MedecinExemple.json'), true); $jsonR = json_decode(file_get_contents('Docs/RDVExemple.json'), true); var_dump(StaticRepo::testConnexion()); $repo = new PatientRepo(); $repoM = new MedecinRepo(); foreach ($jsonM as $patient) { $repoM->add($patient['Civilite'], $patient['Prenom'], $patient['Nom']); } foreach ($jsonP as $patient) { $repo->add($patient['Civilite'], $patient['Prenom'], $patient['Nom'], $patient['Adresse'], NULL, $patient['Ville'], $patient['CodePostal'], $patient['DateNaissance'], $patient['LieuNaissance'], $patient['NumSecuriteSociale'], $patient['MedecinTraitant']); } foreach ($jsonR as $rdv) { RDVRepo::add($rdv['DateRDV'], $rdv['Duree'], $rdv['Patient_Id'], $rdv['Medecin_Id']); }