/** * @param int $authorId */ function addAuthor($authorId) { $link = new BookHasAuthor(); $link->book_id = $this->id; $link->author_id = (int) $authorId; Registry::persistenceDriver()->save($link); }
function __construct($viewParams = NULL) { //Путь к файлам css js ... для подключения в браузере $this->sitePath = 'http://' . $_SERVER['HTTP_HOST'] . '/'; // Возврат полученных параметров в view скрипт $this->params = $viewParams; // Подключается необходимый view файл include Registry::getTemplate(); }
function indexAction() { var_dump($_POST); die; // Проверка Валидности данных $data = $this->validate(); /* Если не проходит валюдацию возвращается массив data * с данными и массив error с полями которые не прошли валюдацию */ if (count($data['validate_error'])) { \Library\Registry::setTemplate('../views/register/index.phtml'); return new ViewBase(array('data' => $data['data'], 'validate_error' => $data['validate_error'])); } // Проверяем на наличие регистрации пользователя с таким username или email // Если такой есть, возвращаются все данные // и массив error с указанием данных которые уже зарегистрированны $model = new registerModel(); $checkRegister = $model->checkRegister($data['data']); if ($checkRegister) { \Library\Registry::setTemplate('../views/register/index.phtml'); return new ViewBase(array('data' => $data['data'], 'check_error' => $checkRegister)); } else { // File upload $newmame = 'not_avatar.jpg'; if ($_FILES['upload']['size'] > 0) { if (is_uploaded_file($_FILES["upload"]["tmp_name"])) { $newname = rand(0, 1000) . time() . '.png'; move_uploaded_file($_FILES["upload"]["tmp_name"], "images/" . $newname); } } // FIle Upload $user = array('data' => $data['data'], 'img' => $newname); if ($model->save($user)) { $this->redirect('/'); } } /* * РЕГИСТРАЦИЯ */ }
<?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; error_reporting(E_ALL); ini_set("display_errors", "On"); ini_set("log_errors", "Off"); define("TODOLIST_ROOT", __DIR__ . "/"); // tinyorm autoload include_once TODOLIST_ROOT . "../../lib/autoload.inc"; // application autoload include_once TODOLIST_ROOT . "lib/autoload.inc"; // configuration $config = (include TODOLIST_ROOT . "etc/config.base.php"); $override = TODOLIST_ROOT . "etc/config.override.php"; if (is_file($override)) { $config = array_merge($config, include $override); } Registry::loadConfig($config); Select::setDefaultConnection(Registry::db());
<?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");