/** * @param int $authorId */ function addAuthor($authorId) { $link = new BookHasAuthor(); $link->book_id = $this->id; $link->author_id = (int) $authorId; Registry::persistenceDriver()->save($link); }
<?php use library\Registry, library\Book; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["id"])) { die("No book ID provided"); } /** @var Book $book */ $book = Registry::persistenceDriver()->find((int) $_GET["id"], new Book()); if (!$book) { die("Book #" . (int) $_GET["id"] . " not found"); } $editionCount = $book->getEditions()->count(); if ($book->getEditions()->count()) { die("Cannot delete this book because it still has {$editionCount} edition(s) listed!"); } Registry::persistenceDriver()->delete($book); header("Location: books.php");
<?php use library\Registry, library\Author; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["id"])) { die("No author ID provided"); } else { $author = Registry::persistenceDriver()->find((int) $_GET["id"], new Author()); if (!$author) { die("Author ID #" . (int) $_GET["id"] . " not found"); } } echo \library\View::render("header.php", ["title" => "Tinyorm Library: Edit author", "description" => \library\View::render("sidebar/author_edit.html")]); echo \library\View::render("author_edit.php", ["author" => $author]); echo \library\View::render("footer.php");
<?php use library\Author, library\Registry; include __DIR__ . "/../bootstrap.php"; $author = new Author($_POST); $author->id = (int) $author->id ?: null; $author->name = trim((string) $author->name); if ($author->name) { Registry::persistenceDriver()->save($author); header("Location: authors.php"); exit; } else { echo "Empty name"; }
<?php use library\Registry, library\Book; include __DIR__ . "/../bootstrap.php"; if (empty($_POST["id"])) { die("No book ID provided"); } $id = (int) $_POST["id"]; $book = Registry::persistenceDriver()->find($id, new Book()); if (!$book) { die("Book ID #" . (int) $_POST["id"] . " not found"); } $book->title = trim($_POST["title"]); if (!$book->title) { die("No book title provided"); } Registry::persistenceDriver()->save($book); header("Location: book_edit.php?id={$book->id}"); exit;
<?php use library\Registry, library\Book, tinyorm\Select; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["id"])) { die("No book ID provided"); } /** @var Book $book */ $book = Registry::persistenceDriver()->find((int) $_GET["id"], new Book()); if (!$book) { die("Book ID #" . (int) $_GET["id"] . " not found"); } echo \library\View::render("header.php", ["title" => "Tinyorm Library: Edit book", "description" => \library\View::render("sidebar/book_edit.html")]); $allAuthors = (new Select("author"))->orderBy("name")->execute()->fetchAll(\PDO::FETCH_KEY_PAIR); $bookAuthors = $book->getAuthors()->execute()->fetchAll(); $bookEditions = $book->getEditions()->execute()->fetchAll(); echo \library\View::render("book_edit.php", ["book" => $book, "allAuthors" => $allAuthors, "bookAuthors" => $bookAuthors, "bookEditions" => $bookEditions]); echo \library\View::render("footer.php");
<?php use library\Registry, library\scaffold\Edition; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["id"])) { die("No edition ID provided"); } $edition = Registry::persistenceDriver()->find((int) $_GET["id"], new Edition()); if (!$edition) { die("Edition #" . (int) $_GET["id"] . " not found"); } Registry::persistenceDriver()->delete($edition); header("Location: book_edit.php?id=" . $edition->book_id);
<?php use library\Registry, library\Book; include __DIR__ . "/../bootstrap.php"; if (empty($_POST["book_id"])) { die("No book ID provided"); } if (empty($_POST["author_id"])) { die("No author ID provided"); } /** @var Book $book */ $book = Registry::persistenceDriver()->find((int) $_POST["book_id"], new Book()); if (!$book) { die("Book ID #" . (int) $_POST["book_id"] . " not found"); } if ($book->hasAuthor($_POST["author_id"])) { die("This book already has this author"); } $book->addAuthor($_POST["author_id"]); header("Location: book_edit.php?id=" . (int) $_POST["book_id"]);
<?php use library\Registry, library\scaffold\Edition; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["id"])) { if (empty($_GET["book_id"])) { die("No book ID provided"); } $edition = new Edition(); $edition->book_id = (int) $_GET["book_id"]; } else { $edition = Registry::persistenceDriver()->find((int) $_GET["id"], new Edition()); if (!$edition) { die("Edition ID #" . (int) $_GET["id"] . " not found"); } } $title = $edition->id ? "Edit book edition" : "Add book edition"; echo \library\View::render("header.php", ["title" => "Tinyorm Library: {$title}", "description" => \library\View::render("sidebar/edition_edit.html")]); echo \library\View::render("edition_edit.php", ["edition" => $edition]); echo \library\View::render("footer.php");
<?php use library\Registry, tinyorm\Select, library\scaffold\BookHasAuthor; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["book_id"])) { die("No book ID provided"); } if (empty($_GET["author_id"])) { die("No author ID provided"); } $bookHasAuthor = (new Select("book_has_author"))->where("book_id = ?", (int) $_GET["book_id"])->where("author_id = ?", (int) $_GET["author_id"])->setFetchClass(BookHasAuthor::class)->execute()->fetch(); if (!$bookHasAuthor) { die("This author is not registered for this book"); } Registry::persistenceDriver()->delete($bookHasAuthor); header("Location: book_edit.php?id=" . (int) $_GET["book_id"]);
<?php use library\Registry, library\scaffold\Edition; include __DIR__ . "/../bootstrap.php"; $edition = new Edition($_POST); $edition->id = (int) $edition->id ?: null; $edition->book_id = (int) $edition->book_id; $edition->year = (int) $edition->year; $edition->isbn = (string) $edition->isbn; $edition->instance_count = (int) $edition->instance_count; Registry::persistenceDriver()->save($edition); header("Location: book_edit.php?id={$edition->book_id}"); exit;
<?php use library\Registry, library\Author; include __DIR__ . "/../bootstrap.php"; if (empty($_GET["id"])) { die("No author ID provided"); } /** @var Author $author */ $author = Registry::persistenceDriver()->find((int) $_GET["id"], new Author()); if (!$author) { die("Author #" . (int) $_GET["id"] . " not found"); } Registry::persistenceDriver()->delete($author); header("Location: authors.php");