Пример #1
0
});
/**************Individual Brand routes *******************/
/* [R] Display a Brand and its Stores.
 ** Allow user to add a new Store to this brand.
 ** Ze may add an existing Store to this brand (e.g. Burch's
 ** starts carrying Nike) or create a new Store which carries
 ** this brand. */
$app->get("/brand/{id}", function ($id) use($app) {
    $brand = Brand::find($id);
    return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'stores' => $brand->getStores(), 'all_stores' => Store::getAll()));
});
/* [C] Create a new Store associated with this Brand.
 ** Then display all stores for this brand. */
$app->post("/brand/{id}", function ($id) use($app) {
    $brand = Brand::find($id);
    $escaped_post = escapeCharsInArray($_POST);
    // If user chose to add an existing store, add it to the brand.
    if (!empty($escaped_post['existing_store'])) {
        $existing_store = Store::find($escaped_post['existing_store']);
        $brand->addStore($existing_store);
    } else {
        // Otherwise, create a new store and add it to the brand.
        $new_store = new Store($escaped_post['name'], $escaped_post['location'], $escaped_post['phone']);
        $new_store->save();
        $brand->addStore($new_store);
    }
    return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'stores' => $brand->getStores(), 'all_stores' => Store::getAll()));
});
/* [U] Update the info for this Brand.
 ** Then display all stores associated with it.
 ** This route is not necessary-- finish if time. */
Пример #2
0
// [D]elete all clients for a particular stylist
$app->delete("/stylists/{id}/deleteAll", function ($id) use($app) {
    $stylist = Stylist::find($id);
    // Get all clients for a particular stylist and delete them
    $matching_clients = $stylist->getClients();
    foreach ($matching_clients as $client) {
        $client->delete();
    }
    return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients()));
});
// Client routes
// [C]reate a Client associated with a particular Stylist
// (stylist_id will come from secret field in client entry form)
// Then display clients of current stylist.
$app->post("/clients", function () use($app) {
    $escaped_inputs = escapeCharsInArray($_POST);
    $new_client = new Client($escaped_inputs['name'], $escaped_inputs['phone'], $escaped_inputs['stylist_id']);
    $new_client->save();
    $stylist = Stylist::find($_POST['stylist_id']);
    return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients()));
});
// [U]pdate a particular Client
$app->patch("/clients/{id}", function ($id) use($app) {
    $client = Client::find($id);
    $client->updatePhone($_POST['phone']);
    //Get current stylist to display on feedback page
    $stylist_id = $client->getStylistId();
    $stylist = Stylist::find($stylist_id);
    return $app['twig']->render('stylist.html.twig', array('stylist' => $stylist, 'clients' => $stylist->getClients()));
});
// [D]elete a particular Client