<?php

interface Publication 
{
    public function open();
    public function close();
    public function setPageNumber($page);
    public function getPageNumber();
    public function getDailyRate($days = 1);
    public function getCategory();
    public function getPageCount();
}



class TitleAdapter implements Publication
{
    protected $title;
    public function __construct(Title $title)
    {
        $this->title = $title;
    }

    public function open()
    {
        $this->title->setClosed(Title::TITLE_OPEN);
    }

    public function close()
    {
        $this->setPageNumber(0);
        $this->title->setClosed(Title::TITLE_CLOSE);
    }

    public function getCategory()
    {
        return $this->title->getInfo(Title::INFO_CATEGORY);
    }

    public function getPageCount()
    {
        return $this->title->getInfo(Title::INFO_PAGECOUNT);
    }

    public function getDailyRate($days = 1)
    {
        return 12;
    }

    public function getPageNumber()
    {
        try {
            return $this->title->getCurrentPage();
        } catch (ClosedException $e) {
            return 0;
        }
    }

    public function setPageNumber($page)
    {
        $this->title->setCurrentPage($page);
        return true;
    }
}


$title = new Title(100, 'PC');
$book = new TitleAdapter($title);
$book->open();
$book->setPageNumber(48);
$book->getPageNumber();

// bude stejne jako instance Title
print "Hodnoty instance třídy TitleAdapter\n";
printf("Kategorie: %s\n", $book->getCategory());
printf("Počet stran: %d\n", $book->getPageCount());
printf(
"Kniha je otevřena na %d. straně\n", $book->getPageNumber()
);

// bude stejne viz vyse
print "\nHodnoty instance třídy Title\n";
printf("Kategorie: %s\n", $title->getInfo(Title::INFO_CATEGORY));
printf("Počet stran: %d\n", $title->getInfo(Title::INFO_PAGECOUNT));
printf(
"Kniha je otevřena na %d. straně\n", $title->getCurrentPage()
);