示例#1
0
        return err_general_error($response, "Venue Id {$id} not found");
    }
    $venue->delete();
    return success($response, "Venue deleted");
});
$app->get('/venues/{id}/contacts', function ($request, $response, $args) {
    $id = $request->getAttribute('id');
    $con = Propel::getWriteConnection('productionSource');
    $sql = "SELECT * FROM Contact WHERE id IN " . "(SELECT ContactAssignmentToVenue.ContactId FROM ContactAssignmentToVenue" . " WHERE ContactAssignmentToVenue.VenueId = :venueid)";
    $stmt = $con->prepare($sql);
    $stmt->execute(array(':venueid' => $id));
    $formatter = new ObjectFormatter();
    $formatter->setClass('\\Contact');
    //full qualified class name
    $contacts = $formatter->format($con->getDataFetcher($stmt));
    $response->getBody()->write(parseToJSONArray($contacts));
    return $response;
});
$app->post('/venues/{id}/contacts', function ($request, $response, $args) {
    $venueid = $request->getAttribute('id');
    $parsedBody = $request->getParsedBody();
    if ($parsedBody == null) {
        return err_general_error($response, "Provide a body to assign a contact to this venues");
    }
    $contact = new Contact();
    $contact->fromArray($parsedBody);
    $contact = ContactQuery::create()->findPK($contact->getId());
    if ($contact == null) {
        return err_general_error($response, "Venue Id " . $id . " not found");
    }
    $con = Propel::getWriteConnection('productionSource');
示例#2
0
    $gigid = $request->getAttribute('gigid');
    $assignment = ContactAssigmentToGigQuery::query()->filterByGigId($gigid)->filterByContactId($contactid);
    if ($assignment == null) {
        return err_general_error($response, "ContactAssignment with  ContactId {$contactid} and GigId {$gigid} not found");
    }
    $assignment->delete();
    return success($response, "ContactAssignmentToGig deleted");
});
$app->get('/contacts/{id}/venues', function ($request, $response, $args) {
    $id = $request->getAttribute('id');
    $con = Propel::getWriteConnection('productionSource');
    $sql = "SELECT * FROM Venue WHERE id IN " . "(SELECT ContactAssignmentToVenue.VenueId FROM ContactAssignmentToVenue" . " WHERE ContactAssignmentToVenue.ContactId = :contactid)";
    $stmt = $con->prepare($sql);
    $stmt->execute(array('contactid' => $id));
    $formatter = new ObjectFormatter();
    $formatter->setClass('\\Venue');
    //full qualified class name
    $venues = $formatter->format($con->getDataFetcher($stmt));
    $response->getBody()->write(parseToJSONArray($venues));
    return $response;
});
$app->delete('/contacts/{contactid}/venues/{venuesid}', function ($request, $response, $args) {
    $contactid = $request->getAttribute('contactid');
    $venueid = $request->getAttribute('venueid');
    $assignment = ContactAssigmentToVenueQuery::query()->filterByVenueId($venueid)->filterByContactId($contactid);
    if ($assignment == null) {
        return err_general_error($response, "ContactAssignment with  ContactId {$contactid} and VenueId {$venueid} not found");
    }
    $assignment->delete();
    return success($response, "ContactAssignmentToVenue deleted");
});
示例#3
0
<?php

/* ACCOUNT */
$app->get('/accounts', function ($request, $response, $args) {
    $accounts = AccountQuery::create()->find();
    /* hide password and telephonenumber */
    foreach ($accounts as $account) {
        $account->setPassword("hidden");
        $account->setSalt("hidden");
    }
    $response->getBody()->write(parseToJSONArray($accounts));
    return $response;
});
$app->post('/accounts', function ($request, $response, $args) {
    $parsedBody = $request->getParsedBody();
    if ($parsedBody == null) {
        return err_general_error($response, "Provide a body to create a new account");
    }
    $account = new Account();
    $account->fromArray($parsedBody);
    if ($account->validate()) {
        $account->save();
    } else {
        return err_general_error($response, "Validation failed");
    }
    /* Response with resulting account */
    $response->getBody()->write($account->toJSON());
    return $response;
});
$app->get('/accounts/{id}', function ($request, $response, $args) {
    $id = $request->getAttribute('id');