Exemplo n.º 1
0
 public static function getInstance()
 {
     if (!isset(self::$singleton)) {
         self::$singleton = new GuestService();
     }
     return self::$singleton;
 }
Exemplo n.º 2
0
<?php

require 'vendor/autoload.php';
require 'guest/GuestService.php';
$app = new \Slim\Slim();
$app->post('/guests', function () use($app) {
    $guestJson = $app->request()->getBody();
    $guest = json_decode($guestJson, true);
    if ($guest) {
        $return = GuestService::addGuest($guest);
        echo $return;
    } else {
        echo 'malfomat json';
    }
});
$app->get('/guests/', function () use($app) {
    $guests = GuestService::getGuests();
    echo json_encode($guests);
});
$app->delete('/guests/:id', function ($id) use($app) {
    $return = GuestService::deleteGuest($id);
    if ($return) {
        $app->response()->header('Content-Type', 'application/json');
        echo '{"status": "true","message": "Guest deleted!"}';
    } else {
        $app->response()->header('Content-Type', 'application/json');
        echo '{"status": "false", "message": "Guest with $id does not exit"}';
    }
});
$app->run();
 private static function updateUserData()
 {
     self::$singleton->setUser(GuestService::getInstance()->getTrustedUser(self::$singleton->user->id));
 }
Exemplo n.º 4
0
        $app->response()->header('Content-Type', 'application/json');
        $app->response()->setStatus(200);
        echo json_encode($guests);
    } else {
        $app->response()->setStatus(204);
    }
});
/*
HTTP DELETE /api/guests/:id
RESPONSE 200 OK 
{
  "status": "true",
  "message": "Guest deleted!"
}

HTTP DELETE /api/guests/x
RESPONSE 404 NOT FOUND 
{
  "status": "false",
  "message": "Guest with x does not exit"
}
*/
$app->delete('/guests/:id', function ($id) use($app) {
    if (GuestService::delete($id)) {
        echo "Guest with id = {$id} was deleted";
    } else {
        $app->response->setStatus('404');
        echo "Guest with id = {$id} not found";
    }
});
$app->run();
Exemplo n.º 5
0
 private static function saveRSVPForUser($rsvp_array)
 {
     global $session;
     $rsvpEvents = array();
     foreach ($rsvp_array["rsvpEvents"] as $rsvpEvent_array) {
         $rsvpEvents[] = RSVPEvent::createRSVPEvent($rsvpEvent_array);
     }
     $session->saveRSVP(GuestService::getInstance()->saveRSVP(self::getUser()->id, new RSVP($rsvp_array["Has RSVPed"], $rsvpEvents, GuestService::getInstance()->getRSVPDueDate(self::getUser()->id))));
     return self::getRSVP();
 }