예제 #1
0
파일: Book.php 프로젝트: jschold/Library
 static function find($searchId)
 {
     $books = Book::getAll();
     foreach ($books as $book) {
         if ($searchId = $book->getId()) {
             return $book;
         }
     }
 }
예제 #2
0
 function testUpdate()
 {
     $book_name = "Siddhartha";
     $test_book = new Book($book_name);
     $test_book->save();
     $test_book->setTitle("Peace Train");
     $test_book->update();
     $result = Book::getAll();
     $this->assertEquals($test_book, $result[0]);
 }
예제 #3
0
 function testDelete()
 {
     $title = "Anathem";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Snow Crash";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_book->delete();
     $this->assertEquals([$test_book2], Book::getAll());
 }
예제 #4
0
 function test_delete()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_book->delete();
     $result = Book::getAll();
     $this->assertEquals([$test_book2], $result);
 }
예제 #5
0
 static function search($search_title)
 {
     $found_books = array();
     $books = Book::getAll();
     foreach ($books as $book) {
         $book_title = $book->getTitle();
         if ($book_title == $search_title) {
             array_push($found_books, $book);
         }
     }
     return $found_books;
 }
예제 #6
0
 function testDeleteOne()
 {
     $book_name = "Rum diaries";
     $test_book = new Book($book_name);
     $test_book->save();
     $book_name = "Yer not a wizard harry";
     $test_book2 = new Book($book_name);
     $test_book2->save();
     $test_book->deleteOne();
     $result = Book::getAll();
     $this->assertEquals([$test_book2], $result);
 }
예제 #7
0
 static function find($search_id)
 {
     $found_book = null;
     $books = Book::getAll();
     foreach ($books as $book) {
         $book_id = $book->getId();
         if ($book_id == $search_id) {
             $found_book = $book;
         }
     }
     return $found_book;
 }
예제 #8
0
파일: BookTest.php 프로젝트: bdspen/library
 function testDeleteAll()
 {
     //Arrange
     $title = "Title";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "New Title";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     Book::deleteAll();
     $result = Book::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
예제 #9
0
 function testDeleteAll()
 {
     //Arrange
     $book_name = "Intro to Art";
     $test_book = new Book($book_name);
     $test_book->save();
     $book_name2 = "Intro to Spanish";
     $book_author2 = "SPN101";
     $test_book2 = new Book($book_name2);
     $test_book2->save();
     //Act
     Book::deleteAll();
     $result = Book::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
예제 #10
0
 function testDeleteAll()
 {
     //Arrange
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Moby Dick";
     $id2 = 2;
     $test_book2 = new Book($title, $id);
     $test_book2->save();
     //Act
     Book::deleteAll();
     $result = Book::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
예제 #11
0
 function testDeleteAll()
 {
     //Arrange
     $title = "Speaker for the Dead";
     $date = "1987";
     $id = null;
     $test_book = new Book($title, $date, $id);
     $test_book->save();
     $title2 = "Frankenstein";
     $date2 = "1750";
     $id2 = null;
     $test_book2 = new Book($title2, $date2, $id2);
     $test_book2->save();
     //Act
     Book::deleteAll();
     //Assert
     $result = Book::getAll();
     $this->assertEquals([], $result);
 }
예제 #12
0
파일: Book.php 프로젝트: jtorrespdx/library
 static function searchByTitle($search_string)
 {
     $clean_search_string = preg_replace('/[^A-Za-z0-9\\s]/', '', $search_string);
     $lower_clean_search_string = strtolower($clean_search_string);
     $exploded_lower_clean_search_string = explode(' ', $lower_clean_search_string);
     $books = Book::getAll();
     $matches = array();
     foreach ($exploded_lower_clean_search_string as $word) {
         foreach ($books as $book) {
             $title = $book->getTitle();
             $clean_title = preg_replace('/[^A-Za-z0-9\\s]/', '', $title);
             $lower_clean_title = strtolower($clean_title);
             $explode_lower_clean_title = explode(' ', $lower_clean_title);
             foreach ($explode_lower_clean_title as $title_pieces) {
                 if ($title_pieces == $word) {
                     array_push($matches, $book);
                 }
             }
         }
     }
     return $matches;
 }
예제 #13
0
파일: app.php 프로젝트: bdspen/library_day1
});
$app->patch("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    if (!empty($_POST['title'])) {
        $new_title = $_POST['title'];
        $book->updateTitle($new_title);
    }
    if (!empty($_POST['author'])) {
        $author_name = $_POST['author'];
        $book->updateAuthor($book->checkAuthor($author_name));
    }
    if (!empty($_POST['add_author'])) {
        $author_name = $_POST['add_author'];
        $book->addAuthor($book->checkAuthor($author_name));
    }
    if (!empty($_POST['add_copies'])) {
        $add_copies = $_POST['add_copies'];
        $book->updateCopies($add_copies);
    }
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->post("/delete_all_books", function () use($app) {
    Book::deleteAll();
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->delete("/book/{id}/delete_author", function ($id) use($app) {
    $book = Book::find($id);
    $book->deleteAuthor($_POST['author_id']);
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
return $app;
예제 #14
0
 function testDeleteOne()
 {
     //Arrange
     $title = "The Cat in the Hat";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Misery";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_book->deleteOne();
     $result = Book::getAll();
     //Assert
     $this->assertEquals($test_book2, $result[0]);
 }
예제 #15
0
파일: app.php 프로젝트: CaseyH33/Library
require_once __DIR__ . "/../src/Author.php";
require_once __DIR__ . "/../src/Book.php";
$app = new Silex\Application();
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=library';
$username = '******';
$password = '******';
$DB = new PDO($server, $username, $password);
use Symfony\Component\HttpFoundation\Request;
Request::enableHttpMethodParameterOverride();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig', array('authors' => Author::getAll(), 'books' => Book::getAll()));
});
$app->post("/author_book", function () use($app) {
    $title = $_POST['title'];
    $book = new Book($title, $id = null);
    $book->save();
    $name = $_POST['name'];
    $author = new Author($name, $id = null);
    $author->save();
    $result = $author->addBook($book);
    return $app['twig']->render('index.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->post("/delete_all", function () use($app) {
    $GLOBALS['DB']->exec("DELETE FROM authors_books_t;");
    Author::deleteAll();
    Book::deleteAll();
    return $app['twig']->render('index.html.twig', array('authors' => Author::getAll(), 'books' => Book::getAll()));
});
return $app;
예제 #16
0
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('index.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->get("/books", function () use($app) {
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->post("/books", function () use($app) {
    $book_title = $_POST['book_title'];
    $book = new Book($book_title);
    $book->save();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->post("/delete_books", function () use($app) {
    Book::deleteAll();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->get("/authors", function () use($app) {
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
});
$app->post("/authors", function () use($app) {
    $name = $_POST['name'];
    $author = new Author($name);
    $author->save();
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
});
$app->post("/delete_authors", function () use($app) {
    Author::deleteAll();
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
});
return $app;
예제 #17
0
파일: app.php 프로젝트: jlbethel/Library
    $new_book->save();
    return $app['twig']->render('books.html.twig', array('books' => Book::getAll()));
});
$app->post("/authors", function () use($app) {
    $new_author = new Author($_POST['name']);
    $new_author->save();
    return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll()));
});
$app->post("/patrons", function () use($app) {
    $new_patron = new Patron($_POST['name']);
    $new_patron->save();
    return $app['twig']->render('patrons.html.twig', array('patrons' => Patron::getAll()));
});
$app->post("/add_author", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $author = Author::find($_POST['author_id']);
    $book->addAuthor($author);
    return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll()));
});
$app->post("/add_book", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $author = Author::find($_POST['author_id']);
    $author->addBook($book);
    return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $author->getBooks(), 'all_books' => Book::getAll()));
});
$app->post("/add_copy", function () use($app) {
    $book = Book::find($_POST['book_id']);
    $book->addCopy();
    return $app['twig']->render('book.html.twig', array('copies' => $book->getCopies(), 'book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll()));
});
return $app;
예제 #18
0
 function test_updateTitle()
 {
     //Arrange
     $title = "History of whatever";
     $test_book = new Book($title);
     $test_book->save();
     //Act
     $new_title = "Future of him";
     $test_book->updateTitle($new_title);
     //Assert
     $result = Book::getAll();
     $this->assertEquals($new_title, $result[0]->getTitle());
 }
예제 #19
0
 function test_delete()
 {
     //Arrange
     $title = "Revenge of the Martians";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Star Wars";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_book->delete();
     $result = Book::getAll();
     //Assert
     $this->assertEquals([$test_book2], $result);
 }
예제 #20
0
 function testDeleteBook()
 {
     //Arrange
     $title = "Little Cat";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Little Dog";
     $id2 = 2;
     $test_book2 = new Book($title2, $id2);
     $test_book2->save();
     //Act
     $test_book->delete();
     //Assert
     $this->assertEquals([$test_book2], Book::getAll());
 }
예제 #21
0
    $book = Book::find($id);
    $book_authors = $book->getAuthors();
    return $app['twig']->render("book.html.twig", array('book' => $book, 'authors' => $book_authors));
});
$app->post("/book_added", function () use($app) {
    // create new book from user entry "add book"
    $title = $_POST['title'];
    $new_book = new Book($title);
    $new_book->save();
    // create new author from user entry "add book"
    // possibly check that the author is already in the database - NOT NOW
    $name = $_POST['name'];
    $new_author = new Author($name);
    $new_author->save();
    $new_book->addAuthor($new_author);
    $books = Book::getAll();
    $authors = Author::getAll();
    //var_dump($authors);
    return $app['twig']->render("main_admin.html.twig", array('books' => $books, 'authors' => $authors));
});
$app->patch("/book/{id}/update_title", function ($id) use($app) {
    $new_title = $_POST['title'];
    $book_to_update = Book::find($id);
    $book_to_update->updateTitle($new_title);
    $book_authors = $book_to_update->getAuthors();
    return $app['twig']->render("book.html.twig", array('book' => $book_to_update, 'authors' => $book_authors));
});
$app->post("/book/{id}/add_author", function ($id) use($app) {
    $author_to_add = new Author($_POST['name']);
    $author_to_add->save();
    var_dump(Author::find($author_to_add->getId()));
예제 #22
0
 function test_delete()
 {
     //Arrange
     $title = "Whimsical Fairytales...and other stories";
     $genre = "Fantasy";
     $test_book = new Book($title, $genre);
     $test_book->save();
     $title2 = "The Secret Life of Garden Gnomes";
     $genre2 = "Nonfiction";
     $test_book2 = new Book($title2, $genre2);
     $test_book2->save();
     //Act
     $test_book->delete();
     //Assert
     $result = Book::getAll();
     $this->assertEquals($test_book2, $result[0]);
 }
예제 #23
0
 function testDeleteOne()
 {
     //Arrange
     $title = "Grapes of Wrath";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Cannery Row";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_book->deleteOne();
     //Assert
     $this->assertEquals([$test_book2], Book::getAll());
 }
예제 #24
0
 function testDelete()
 {
     //Arrange
     $book_title = "Snow Crash";
     $id = null;
     $test_book = new Book($book_title, $id);
     $test_book->save();
     $book_title2 = "Ready Player One";
     $id2 = null;
     $test_book2 = new Book($book_title2, $id2);
     $test_book2->save();
     //Act
     $test_book->delete();
     //Assert
     $this->assertEquals([$test_book2], Book::getAll());
 }
예제 #25
0
파일: app.php 프로젝트: r-hills/Library
//update a book name and return to the librarian route
$app->patch("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $book->updateTitle($_POST['title']);
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll()));
});
//delete an individual book and return to the librarian route
$app->delete("/book/{id}/delete", function ($id) use($app) {
    $book = Book::find($id);
    $book->delete();
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll()));
});
//displays results of user search by book title
$app->post("/book_title_search_results", function () use($app) {
    $user_query = $_POST['title'];
    $all_books = Book::getAll();
    $matching_books = array();
    foreach ($all_books as $book) {
        if (strpos(strtolower($book->getTitle()), strtolower($user_query)) !== false) {
            array_push($matching_books, $book);
        }
    }
    return $app['twig']->render("book_search_results.html.twig", array('results' => $matching_books));
});
$app->post("/book_author_search_results", function () use($app) {
    $user_query = $_POST['author'];
    $all_authors = Author::getAll();
    $matching_authors = array();
    foreach ($all_authors as $author) {
        if (strpos(strtolower($author->getName()), strtolower($user_query)) !== false) {
            array_push($matching_authors, $author);
예제 #26
0
 function testDeleteBook()
 {
     $title = "BRING ON THE PAIN";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $title2 = "Oh Yeah";
     $id2 = 2;
     $test_book2 = new Book($title2, $id2);
     $test_book2->save();
     $test_book->deleteBook();
     $this->assertEquals([$test_book2], Book::getAll());
 }
예제 #27
0
 function testDeleteBook()
 {
     //Arrange
     $book_name = "Gattica";
     $id = 1;
     $test_book = new Book($book_name, $id);
     $test_book->save();
     $book_name2 = "How to run";
     $id2 = 2;
     $test_book2 = new Book($book_name2, $id2);
     $test_book2->save();
     //Act
     $test_book->deleteOne();
     //Assert
     $this->assertEquals([$test_book2], Book::getAll());
 }
예제 #28
0
 function testDeleteOne()
 {
     //Arrange
     $author_first = "Dr.";
     $author_last = "Seuss";
     $title = "The Cat in the Hat";
     $test_book = new Book($author_first, $author_last, $title);
     $test_book->save();
     $author_first2 = "Stephen";
     $author_last2 = "King";
     $title2 = "Misery";
     $test_book2 = new Book($author_first2, $author_last2, $title2);
     $test_book2->save();
     //Act
     $test_book->deleteOne();
     $result = Book::getAll();
     //Assert
     $this->assertEquals($test_book2, $result[0]);
 }
예제 #29
0
    return $app['twig']->render("main_admin.html.twig", array('books' => Book::getAll()));
});
//INDIVIDUAL AUTHOR PAGE
$app->get("/author/{id}", function ($id) use($app) {
    $author = Author::find($id);
    $books = $author->getBooks();
    return $app['twig']->render('author.html.twig', array('author' => $author, "books" => $books));
});
//Add book on the individual author page
$app->post("/author/{id}/add_book", function ($id) use($app) {
    $find_author = Author::find($id);
    $title = $_POST['title'];
    $new_book = new Book($title);
    $new_book->save();
    $find_author->addBook($new_book);
    $books = $find_author->getBooks();
    return $app['twig']->render('author.html.twig', array('author' => $find_author, 'books' => $books));
});
//Update author's name
$app->patch("/author/{id}", function ($id) use($app) {
    $author = Author::find($id);
    $author->update($_POST['title']);
    $books = $author->getBooks();
    return $app['twig']->render('author.html.twig', array('author' => $author, 'books' => $books));
});
$app->delete("/author/{id}", function ($id) use($app) {
    $author = Author::find($id);
    $author->delete();
    return $app['twig']->render('main_admin.html.twig', array('author' => $author, 'books' => Book::getAll()));
});
return $app;
예제 #30
0
파일: Book.php 프로젝트: alexMcosta/library
 static function searchByAuthorLast($search_string)
 {
     $clean_search_string = preg_replace('/[^A-Za-z0-9\\s]/', '', $search_string);
     $lower_clean_search_string = strtolower($clean_search_string);
     $books = Book::getAll();
     $matches = array();
     foreach ($books as $book) {
         $author = $book->getAuthorLast();
         $clean_author = preg_replace('/[^A-Za-z0-9\\s]/', '', $author);
         $lower_clean_author = strtolower($clean_author);
         $title = $book->getTitle();
         if ($lower_clean_author == $lower_clean_search_string) {
             array_push($matches, $book);
         }
     }
     return $matches;
 }