Пример #1
0
 /**
  * @return ArrayCollection|null
  */
 public function getIterator()
 {
     if (!$this->list instanceof ArrayCollection) {
         $this->list = new ArrayCollection();
         if ($this->getTotal() <= 1) {
             return $this->list;
         }
         // definition of offset to the left and to the right of the selected page
         $left_offset = floor(($this->config->getMaxNavigate() - 1) / 2);
         $right_offset = ceil(($this->config->getMaxNavigate() - 1) / 2);
         // adjustment, if the offset is too large left
         if ($this->config->getCurrentPage() - $left_offset < 1) {
             $offset = abs($this->config->getCurrentPage() - 1 - $left_offset);
             $left_offset = $left_offset - $offset;
             $right_offset = $right_offset + $offset;
         }
         // adjustment, if the offset is too large right
         if ($this->config->getCurrentPage() + $right_offset > $this->getTotal()) {
             $offset = abs($this->getTotal() - $this->config->getCurrentPage() - $right_offset);
             $left_offset = $left_offset + $offset;
             $right_offset = $right_offset - $offset;
         }
         // determining the first and last pages in paging based on the current page and offset
         $page_from = $this->config->getCurrentPage() - $left_offset;
         $page_to = $this->config->getCurrentPage() + $right_offset;
         $page_from = $page_from > 1 ? $page_from : 1;
         // build list
         for ($page = $page_from; $page <= $page_to; ++$page) {
             if ($page == $this->config->getCurrentPage()) {
                 $this->list->add($this->getCurrent());
             } else {
                 $this->list->add(new Node($page, $this->buildLink($page)));
             }
         }
     }
     return $this->list;
 }
Пример #2
0
 /**
  * @dataProvider getConfigs
  *
  * @param int $total_pages
  * @param int $current_page
  */
 public function testConstruct($total_pages, $current_page)
 {
     $config = new Configuration($total_pages, $current_page);
     $this->assertEquals($total_pages, $config->getTotalPages());
     $this->assertEquals($current_page, $config->getCurrentPage());
 }