diff --git a/src/helpers/Page.php b/src/helpers/Page.php index 59d95fc..88efa53 100755 --- a/src/helpers/Page.php +++ b/src/helpers/Page.php @@ -8,7 +8,8 @@ namespace helpers; -class Page { +class Page +{ /** * Get all details of the given page number. @@ -17,9 +18,8 @@ class Page { * @param int $pageNumber * @return bool */ - public function getPage($pageNumber) - { - $path = $this->getPathToFile($pageNumber); + public function getPage($pageNumber) { + $path = $this->getPathToFile($pageNumber); $content = file_get_contents($path); return json_decode($content, true); @@ -30,8 +30,7 @@ class Page { * @param int $pageNumber * @return bool */ - public function exists($pageNumber) - { + public function exists($pageNumber) { $path = $this->getPathToFile($pageNumber); return file_exists($path); @@ -41,10 +40,9 @@ class Page { * Persist the given page on the file system. * * @param array $issues - * @param int $numIssuesPerPage + * @param int $numIssuesPerPage */ - public function save($issues, $numIssuesPerPage) - { + public function save($issues, $numIssuesPerPage) { if (empty($issues)) { return; } @@ -55,11 +53,11 @@ class Page { $pageNumber = $index + 1; $page = array( - 'numPages' => count($pages), + 'numPages' => count($pages), 'previousPage' => $pageNumber - 1, - 'currentPage' => $pageNumber, - 'nextPage' => $pageNumber + 1, - 'issues' => $this->formatIssues($issuesInPage) + 'currentPage' => $pageNumber, + 'nextPage' => $pageNumber + 1, + 'issues' => $this->formatIssues($issuesInPage) ); $path = $this->getPathToFile($pageNumber); @@ -67,21 +65,19 @@ class Page { } } - private function getPathToFile($pageNumber) - { + private function getPathToFile($pageNumber) { return sprintf('%s/../data/pages/%d.json', dirname(__FILE__), $pageNumber); } - private function formatIssues($issuesInPage) - { + private function formatIssues($issuesInPage) { $formatted = array(); foreach ($issuesInPage as $issue) { $formatted[] = array( 'number' => $issue['number'], - 'title' => $issue['title'], - 'state' => $issue['state'], - 'user' => array( + 'title' => $issue['title'], + 'state' => $issue['state'], + 'user' => array( 'login' => $issue['user']['login'] ), 'created_at' => $issue['created_at'], @@ -92,4 +88,22 @@ class Page { return $formatted; } + public function getPaginationArray($numPages, $page, $padding = 2) { + $pages = [1]; + $i = 2; + while ($i <= $numPages) { + if ($i < ($page - $padding - 1)) { + $pages[] = "d"; + $i = $page - $padding; + } elseif (($i > ($page + $padding)) && ($numPages > ($page + $padding + 2))) { + # Wenn ( + $pages[] = "d"; + $i = $numPages; + } + $pages[] = $i; + $i++; + } + return $pages; + } + } \ No newline at end of file diff --git a/src/helpers/Twig.php b/src/helpers/Twig.php index d1341b4..c55b6ef 100755 --- a/src/helpers/Twig.php +++ b/src/helpers/Twig.php @@ -18,6 +18,7 @@ class Twig public static function registerFilter(\Twig_Environment $environment) { $environment->addFilter(static::getMarkdownFilter()); $environment->addFilter(static::getColorFilter()); + $environment->addFunction(static::getPaginationFunction()); } private static function getMarkdownFilter() { @@ -41,6 +42,24 @@ class Twig $yiq = (($r * 299) + ($g * 587) + ($b * 114)) / 1000; return ($yiq >= 128) ? 'black' : 'white'; }); + } + private static function getPaginationFunction() { + return new \Twig_Function('paginationFunction', function ($numPages, $page, $padding = 2) { + $pages = [1]; + $i = 2; + while ($i <= $numPages) { + if ($i < ($page - $padding - 1)) { + $pages[] = "d"; + $i = $page - $padding; + } elseif (($i > ($page + $padding)) && ($numPages > ($page + $padding + 2))) { + $pages[] = "d"; + $i = $numPages; + } + $pages[] = $i; + $i++; + } + return $pages; + }); } } \ No newline at end of file diff --git a/src/scss/style.scss b/src/scss/style.scss index 1dc7446..8db579b 100644 --- a/src/scss/style.scss +++ b/src/scss/style.scss @@ -64,6 +64,12 @@ h1 a { } } +.pagination { + svg { + height: 18px; + } +} + blockquote { // bootstrap 3 like styling padding: 10px 20px; margin: 0 0 20px; diff --git a/src/templates/macros.twig b/src/templates/macros.twig index 16f77b0..6f70f52 100755 --- a/src/templates/macros.twig +++ b/src/templates/macros.twig @@ -12,4 +12,60 @@ style="background: {{ '#' ~ label.color }}">{{ label.name }} {% endfor %} {% endif %} +{% endmacro %} + +{% macro pagination(num_pages, page) %} + {% import _self as m %} + {% set pagearray = paginationFunction(num_pages, page,5) %} + + +{% endmacro %} + +{% macro printpage(i,active) %} +
  • + {{ i }} +
  • {% endmacro %} \ No newline at end of file diff --git a/src/templates/page.twig b/src/templates/page.twig index eafea17..f91c49a 100644 --- a/src/templates/page.twig +++ b/src/templates/page.twig @@ -32,7 +32,7 @@
    - + {{ macro.pagination(numPages, currentPage) }}
    {% for issue in issues %}
    @@ -53,35 +53,7 @@
    {% endfor %}
    - - + {{ macro.pagination(numPages, currentPage) }}
    {% endblock %} \ No newline at end of file