本文整理汇总了PHP中Author::getAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Author::getAll方法的具体用法?PHP Author::getAll怎么用?PHP Author::getAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Author
的用法示例。
在下文中一共展示了Author::getAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: find
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;
}
示例2: testDelete
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());
}
示例3: test_delete
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);
}
示例4: findByName
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;
}
示例5: find
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;
}
示例6: testDeleteAll
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);
}
示例7: testDeleteAll
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);
}
示例8: testDeleteAll
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);
}
示例9: search
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;
}
示例10: findByAuthor
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;
}
示例11: function
//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'];
示例12: testDeleteOne
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());
}
示例13: testDeleteAuthor
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());
}
示例14: array
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']);
示例15: testDeleteOne
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());
}