示例#1
0
文件: app.php 项目: bborealis/library
    Book::deleteAll();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->patch("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $title = $_POST['title'];
    $book->update($title);
    $authors = $book->getAuthors();
    $copies = Copy::findCopies($id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $authors, 'all_authors' => Author::getAll(), 'copies' => $copies));
});
$app->post("/add_authors", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $author = Author::find($_POST['author_id']);
    $book->addAuthor($author);
    $copies = Copy::findCopies($_POST['book_id']);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll(), 'copies' => $copies));
});
//book search result page
$app->get("/search_books", function () use($app) {
    $search = Book::search($_GET['search']);
    return $app['twig']->render('search_books.html.twig', array('search' => $search, 'search_book' => $_GET['search']));
});
//author search result page
$app->get("/search_authors", function () use($app) {
    $search = Author::search($_GET['search']);
    return $app['twig']->render('search_authors.html.twig', array('search' => $search, 'search_author' => $_GET['search']));
});
//authors
$app->get("/authors", function () use($app) {
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
示例#2
0
 function testFindCopies()
 {
     //Arrange
     $due_date = '2015-10-10';
     $book_id = 1;
     $id = 1;
     $test_copy = new Copy($due_date, $book_id, $id);
     $test_copy->save();
     $due_date2 = '2015-11-11';
     $book_id2 = 1;
     $id2 = 2;
     $test_copy2 = new Copy($due_date2, $book_id2, $id2);
     $test_copy2->save();
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     //Act
     $result = Copy::findCopies($book_id);
     //var_dump($result);
     //Assert
     $this->assertEquals([$test_copy, $test_copy2], $result);
 }
示例#3
0
    $book->addAuthor($author);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => Copy::getAll(), 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
$app->get("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $author = $book->getAuthors();
    $copies = Copy::findCopies($id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => $copies, 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
$app->post("/add_copy", function () use($app) {
    $book_id = $_POST['book_id'];
    $book = Book::find($book_id);
    $author = $book->getAuthors();
    $copy = new Copy($book_id);
    $copy->save();
    $copies = Copy::findCopies($book_id);
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => $copies, 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
$app->patch("/checkout_copy/{id}", function ($id) use($app) {
    $checkout = new Checkout($_POST['copy_id'], $_POST['patron_id'], $_POST['due_date']);
    $checkout->save();
    $book_id = $_POST['book_id'];
    $book = Book::find($book_id);
    $author = $book->getAuthors();
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author, 'copies' => Copy::getAll(), 'patrons' => Patron::getAll(), 'checkouts' => Checkout::getAll()));
});
// $app->patch("/checkout_copy/{id}", function($id) use ($app) {
//     $book = Book::find($id);
//     $author = $book->getAuthors();
//     $copy_id = $_POST['copy_id'];
//     $copy = Copy::find($copy_id);