protected function addPages(PaginationObject $pagination, $activePage, $neededPages)
    {
        // Add the pages
        for ($i = 1; $i <= $neededPages; $i++) {
            if ($i == $activePage) {
                $page = new ActivePage($i, $this->buildUrl($i));
                $pagination->addEntry($page);
            } else if ($i < 4 || $i > ($neededPages - 3) || ($i > ($activePage - 3) && $i < ($activePage + 3))) {
                $page = new Page($i, $this->buildUrl($i));
                $pagination->addEntry($page);
            } else if (!($pagination->getLatestEntry() instanceof Dots)) {
                $dots = new Dots();
                $pagination->addEntry($dots);
            }
        }
    }