<?php session_start(); include 'library.php'; $op = $_GET['op']; $lib = new Library(); if ($op == "add") { $lib->addBook($_GET['title'], $_GET['author']); } else { if ($op == "add_existing") { $lib->addBook_existing($_GET['id']); } else { if ($op == "delete") { $book = new Book($_GET['copyId'], 'copy'); $book->delete(); } else { if ($op == "shelves") { $lib = new Library(); $html = $lib->get_shelves_tableview('librarian'); echo $html; } } } }
} $t = Timer::instance(); $t->newTimePoint('Begin of requuest'); VehicleFactory::create(VehicleFactory::TYPE_CAR)->move(); echo '<br />'; $t->newTimePoint('After "Car" creation'); VehicleFactory::create(VehicleFactory::TYPE_PLANE)->move(); echo '<br />'; $t->newTimePoint('After "Plane" creation'); $bookAdapter = new BookAdapter(new Book('Nikolay D.', 'It woluld be nice to have my own book :]')); echo "{$bookAdapter->getAuthorAndTitle()}<br />"; $t->newTimePoint('Prepare library.'); $booksDb = array(new Book('A 1', 'T 1'), 1, new Book('A 1', 'T 2'), 2, new Book('A 2', 'T 1'), 3, new Book('A 3', 'T 1'), 4, new Book('A 3', 'T 2'), 5); $library = new Library('FMI Library'); for ($i = 0; $i < count($booksDb); $i += 2) { $library->addBook($booksDb[$i], $booksDb[$i + 1]); } echo "Library content: total => {$library->getBooksCount()}, distinct => {$library->getDistinctBooksCount()}<br />"; $book = $booksDb[0]; $t->newTimePoint('Library - prepared, testing proxy implementation.'); echo 'Proxy test...<br />'; $proxy = new LibraryProxy($library); if ($proxy->hasQuantityFor($book)) { } echo "{$book} is in the library.<br />"; $ticket = $proxy->lendBook($book); if (!$proxy->hasQuantityFor($book)) { } echo "{$book} is not in the library.<br />"; echo "Proxy library content: total => {$proxy->booksCount}, distinct => {$proxy->distinctBooksCount}<br />"; if (!$ticket->isReturned) {
{ var $books = array(); public function count() { $num = count($this->books); return $num; } public function addBook(Book $instance) { $this->books[$instance->get_id()] = $instance; } } class Book { private $id; private $name; public function __construct($id, $name) { $this->id = $id; $this->name = $name; } public function get_id() { return $this->id; } } $lib = new Library(); $lib->addBook(new Book(1, 'Java')); $lib->addBook(new Book(2, 'PHP')); $lib->addBook(new Book(3, 'Moodle')); echo count($lib);
<?php /** * Created by PhpStorm. * User: just * Date: 17.02.16 * Time: 15:30 */ require_once 'class/autoload.php'; $library = new Library(); $book = new Book('Book', '22.01.06', 'testPublisher', 'Science', 'softCovers', 'testAuthor'); $book1 = new Book('Q', '01.01.06', 'testPublisher1', 'Science', 'hard', 'testAuthor1'); $learnBook = new LearnBook('A', '22.12.96', 20, 'testPublisher', 'Science', 'testAuthor'); $magazine = new Magazine('Magazine', '19.02.16', 20, 'testPublisher', 'Science', 'softCovers', 'testAuthor'); $library->addBook($book); $library->addBook($book1); $library->addLearnBook($learnBook); $library->addMagazine($magazine); $allInLibrary = $library->getAll(); usort($allInLibrary, function ($a, $b) { if ($a->getGenre() < $b->getGenre()) { return -1; } else { if ($a->getGenre() > $b->getGenre()) { return 1; } } if ($a->getTitle() < $b->getTitle()) { return -1; } else { if ($a->getTitle() > $b->getTitle()) {