Exemplo n.º 1
0
 static function find($search_id)
 {
     $found_author = null;
     $authors = Author::getAll();
     foreach ($authors as $author) {
         if ($author->getId() == $search_id) {
             $found_author = $author;
         }
     }
     return $found_author;
 }
Exemplo n.º 2
0
 function testDelete()
 {
     $name = "Stephen King";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Neal Stephenson";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $test_author->delete();
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 3
0
 function test_delete()
 {
     $name = "Jerry Garcia";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Frank Sinatra";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $test_author->delete();
     $result = Author::getAll();
     $this->assertEquals([$test_author2], $result);
 }
Exemplo n.º 4
0
 static function findByName($search_name)
 {
     $found_author = null;
     $authors = Author::getAll();
     foreach ($authors as $author) {
         $author_name = $author->getAuthorName();
         if ($author_name == $search_name) {
             $found_author = $author;
         }
     }
     return $found_author;
 }
Exemplo n.º 5
0
 static function find($search_id)
 {
     $found = null;
     $authors = Author::getAll();
     foreach ($authors as $author) {
         $author_id = $author->getId();
         if ($author_id == $search_id) {
             $found = $author;
         }
     }
     //end foreach
     return $found;
 }
Exemplo n.º 6
0
 function testDeleteAll()
 {
     //Arrange
     $name = "Name";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "New Name";
     $test_author2 = new Author($name2);
     $test_author2->save();
     //Act
     Author::deleteAll();
     $result = Author::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
 function testDeleteAll()
 {
     //Arrange
     $id = null;
     $name = "Lemony Snicket";
     $test_author = new Author($id, $name);
     $test_author->save();
     $name2 = "J.R.R. Tolkien";
     $test_author2 = new Author($id, $name2);
     $test_author2->save();
     //Act
     Author::deleteAll();
     //Assert
     $result = Author::getAll();
     $this->assertEquals([], $result);
 }
Exemplo n.º 8
0
 function testDeleteAll()
 {
     //Arrange
     $name = "JK Rowling";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "George RR Martin";
     $id2 = 2;
     $test_author2 = new Author($name, $id);
     $test_author2->save();
     //Act
     Author::deleteAll();
     $result = Author::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
Exemplo n.º 9
0
 static function search($search_name)
 {
     $found_authors = array();
     $authors = Author::getAll();
     foreach ($authors as $author) {
         $author_name = $author->getName();
         if ($author_name == $search_name) {
             array_push($found_authors, $author);
         }
     }
     $found_books = array();
     foreach ($found_authors as $author) {
         $books = $author->getBooks();
         array_push($found_books, $book);
     }
     return $found_books;
 }
Exemplo n.º 10
0
 static function findByAuthor($author_to_search)
 {
     $lower_search_author = strtolower($author_to_search);
     $found_books = [];
     $all_authors = Author::getAll();
     foreach ($all_authors as $author) {
         $author_name = strtolower($author->getName());
         // var_dump($author_name);
         // var_dump($lower_search_author);
         if ($author_name == $lower_search_author) {
             $books_by_author = $author->getBooks();
             var_dump($books_by_author);
             foreach ($books_by_author as $book) {
                 array_push($found_books, $book);
             }
         } else {
             return 0;
         }
     }
     return $found_books;
 }
Exemplo n.º 11
0
//Librarian Home
//Loads basic page
$app->get("/librarian_home", function () use($app) {
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll()));
});
//allows user to post new books and view them on the same page
$app->post("/librarian_home", function () use($app) {
    $title = $_POST['title'];
    $author_first = $_POST['author_first_name'];
    $author_last = $_POST['author_last_name'];
    $book = new Book($title);
    $book->save();
    $author = new Author($author_first, $author_last);
    $author->save();
    $author->addBook($book);
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
//Book page
$app->get("/books/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $author = $book->getAuthor();
    return $app['twig']->render('book.html.twig', array('book' => $book, 'author' => $author));
});
//Search for title or author
$app->post("/search/title", function () use($app) {
    $title = $_POST['search_title'];
    $books = Book::searchByTitle($title);
    return $app['twig']->render('search_results.html.twig', array('books' => $books));
});
$app->post("/search/author", function () use($app) {
    $author = $_POST['search_author'];
Exemplo n.º 12
0
 function testDeleteOne()
 {
     //Arrange
     $author_name = "J.K. Rowling";
     $id = 1;
     $test_author = new Author($author_name, $id);
     $test_author->save();
     $author_name2 = "John Steinbeck";
     $id2 = 2;
     $test_author2 = new Author($author_name2, $id2);
     $test_author2->save();
     //Act
     $test_author->deleteOne();
     //Assert
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 13
0
 function testDeleteAuthor()
 {
     $name = "Hogan";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "Koolaid Man";
     $id2 = 2;
     $test_author2 = new Author($name2, $id2);
     $test_author2->save();
     $test_author->deleteAuthor();
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 14
0
    return $app['twig']->render('post_new.html.twig', array('authors' => $authorsToDisplay));
})->bind('post_new');
$app->post('/post/add', function (Request $request) use($app) {
    $postModel = new Post($app['db']);
    $authorId = $request->request->get('author_id');
    if (!isset($authorId)) {
        $app->abort(404, 'Author has to be selected. Go back and select author');
    }
    $title = $request->request->get('title');
    $message = $request->request->get('message');
    $postModel->set($title, $message, $authorId);
    return $app->redirect($app["url_generator"]->generate("post_index"));
})->bind('post_add');
$app->get('/authors', function () use($app) {
    $authorModel = new Author($app['db']);
    $authorsToDisplay = $authorModel->getAll();
    return $app['twig']->render('author_index.html.twig', array('authors' => $authorsToDisplay));
})->bind('author_index');
$app->get('/author/{author_id}', function ($author_id) use($app) {
    $authorModel = new Author($app['db']);
    $authorToDisplay = $authorModel->get($author_id);
    if (!$authorToDisplay) {
        $app->abort(404, 'The article could not be found');
    }
    return $app['twig']->render('author_single.html.twig', array('author' => $authorToDisplay));
})->assert('author_id', '\\d+')->bind('author_single');
$app->get('/author/new', function () use($app) {
    return $app['twig']->render('author_new.html.twig');
})->bind('author_new');
$app->post('/author/add', function (Request $request) use($app) {
    $authorModel = new Author($app['db']);
Exemplo n.º 15
0
 function testDeleteOne()
 {
     //Arrange
     $first_name = "J.K.";
     $last_name = "Rowling";
     $test_author = new Author($first_name, $last_name);
     $test_author->save();
     $first_name2 = "John";
     $last_name2 = "Steinbeck";
     $test_author2 = new Author($first_name2, $last_name2);
     $test_author2->save();
     //Act
     $test_author->deleteOne();
     //Assert
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 16
0
});
//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);
        }
    }
    $author_book_search_results = array();
    foreach ($matching_authors as $author) {
        $matching_author_books = $author->getBooks();
        foreach ($matching_author_books as $book) {
            array_push($author_book_search_results, $book);
        }
    }
    return $app['twig']->render("author_search_results.html.twig", array('results' => $author_book_search_results));
});
Exemplo n.º 17
0
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;
Exemplo n.º 18
0
 function test_delete()
 {
     //Arrange
     $name = "Kurt Vonnegut";
     $test_author = new Author($name);
     $test_author->save();
     //Act
     $test_author->delete();
     $result = Author::getAll();
     //Assert
     $this->assertEquals([], $result);
 }
Exemplo n.º 19
0
 function testDelete()
 {
     //Arrange
     $name = "Nathan Young";
     $id = null;
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "Kyle Pratuch";
     $test_author2 = new Author($name2, $id);
     $test_author2->save();
     //Act
     $test_author->delete();
     //
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 20
0
 function test_delete()
 {
     //Arrange
     $name = "Ashlin Aronin";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Vincent Adultman";
     $test_author2 = new Author($name2);
     $test_author2->save();
     //Act
     $test_author->delete();
     //Assert
     $result = Author::getAll();
     $this->assertEquals($test_author2, $result[0]);
 }
Exemplo n.º 21
0
    $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;
Exemplo n.º 22
0
 function test_delete()
 {
     //Arrange
     $name = "Stephen King";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Clive Barker";
     $test_author2 = new Author($name2);
     $test_author2->save();
     //Act
     $test_author->delete();
     $result = Author::getAll();
     //Assert
     $this->assertEquals([$test_author2], $result);
 }
Exemplo n.º 23
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;
Exemplo n.º 24
0
 function test_delete()
 {
     //Arrange
     $name = "J.K. Rowling";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "C.S. Lewis";
     $test_author2 = new Author($name2);
     $test_author2->save();
     //Act
     $test_author->delete();
     $result = Author::getAll();
     //Assert
     $this->assertEquals($test_author2, $result[0]);
 }
Exemplo n.º 25
0
 function testDelete()
 {
     //Arrange
     $author_name = "Frank Herbert";
     $id = null;
     $test_author = new Author($author_name, $id);
     $test_author->save();
     $author_name2 = "Neal Stephenson";
     $id2 = null;
     $test_author2 = new Author($author_name2, $id2);
     $test_author2->save();
     //Act
     $test_author->delete();
     //Assert
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 26
0
 function testDeleteOne()
 {
     //Arrange
     //Arrange
     $author_first = "J.K.";
     $author_last = "Rowling";
     $test_author = new Author($author_first, $author_last);
     $test_author->save();
     $author_first2 = "John";
     $author_last2 = "Steinbeck";
     $test_author2 = new Author($author_first2, $author_last2);
     $test_author2->save();
     //Act
     $test_author->deleteOne();
     //Assert
     $this->assertEquals([$test_author2], Author::getAll());
 }
Exemplo n.º 27
0
 static function findByAuthorName($name_to_search)
 {
     $author_to_find = null;
     $lower_search_name = strtolower($name_to_search);
     $all_authors = Author::getAll();
     //var_dump($all_authors);
     foreach ($all_authors as $author) {
         //var_dump($author->getId());
         $name = strtolower($author->getName());
         //var_dump($name);
         if ($lower_search_name == $name) {
             $author_to_find = $author->getId();
             return $author_to_find;
         }
     }
 }
Exemplo n.º 28
0
 function test_getAll()
 {
     //Arrange
     $author_name = "Aristole";
     $id = null;
     $test_author = new Author($author_name, $id);
     $test_author->save();
     $author_name2 = "Plato";
     $test_author2 = new Author($author_name2, $id);
     $test_author2->save();
     //Act
     $result = Author::getAll();
     //Assert
     $this->assertEquals([$test_author, $test_author2], $result);
 }
Exemplo n.º 29
0
$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_array = explode(',', $_POST['name']);
    foreach ($name_array as $name) {
        $new_author = new Author($name);
        $new_author->save();
        $new_book->addAuthor($new_author);
    }
    $new_book->addCopies($_POST['copies']);
    $books = Book::getAll();
    $authors = Author::getAll();
    return $app['twig']->render("main_admin.html.twig", array('books' => $books, 'authors' => $authors));
});
//INDIVIDUAL BOOK PAGE - DISPLAYS BOOK INFORMATION
$app->get("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    $book_authors = $book->getAuthors();
    return $app['twig']->render("book.html.twig", array('book' => $book, 'authors' => $book_authors, 'copies' => count($book->getCopies())));
});
//ADD AUTHOR TO INDIVIDUAL BOOK PAGE
$app->post("/book/{id}/add_author", function ($id) use($app) {
    $find_book = Book::find($id);
    $name = $_POST['name'];
    $new_author = new Author($name);
    $new_author->save();
    $find_book->addAuthor($new_author);
Exemplo n.º 30
0
 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);
     $authors = Author::getAll();
     $matches = array();
     foreach ($authors as $author) {
         $author_last = $author->getAuthorLast();
         $clean_author = preg_replace('/[^A-Za-z0-9\\s]/', '', $author_last);
         $lower_clean_author = strtolower($clean_author);
         if ($lower_clean_author == $lower_clean_search_string) {
             $book = $author->getBook();
             array_push($matches, $book);
         }
     }
     return $matches;
 }