Ejemplo n.º 1
0
 /**
  * Constructor.
  * @param TList the data to be iterated through
  * @param integer start index
  * @param integer number of items to be iterated through
  */
 public function __construct(TList $list, $startIndex, $count)
 {
     $this->_list = $list;
     $this->_index = 0;
     $this->_startIndex = $startIndex;
     if ($startIndex + $count > $list->getCount()) {
         $this->_count = $list->getCount() - $startIndex;
     } else {
         $this->_count = $count;
     }
 }
Ejemplo n.º 2
0
 public function testConstruct()
 {
     $a = array(1, 2, 3);
     $list = new TList($a);
     $this->assertEquals(3, $list->getCount());
     $list2 = new TList($this->list);
     $this->assertEquals(2, $list2->getCount());
 }
Ejemplo n.º 3
0
 /**
  * @return integer the number of items in current page
  */
 public function getCount()
 {
     if ($this->_customPaging) {
         return parent::getCount();
     } else {
         if ($this->_currentPageIndex === $this->getPageCount() - 1) {
             return parent::getCount() - $this->_pageSize * $this->_currentPageIndex;
         } else {
             return $this->_pageSize;
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Restores datagrid content from viewstate.
  */
 protected function restoreGridFromViewState()
 {
     $this->reset();
     $allowPaging = $this->getAllowPaging();
     $itemCount = $this->getViewState('ItemCount', 0);
     $dsIndex = $this->getViewState('DataSourceIndex', 0);
     $columns = new TList($this->getColumns());
     $columns->mergeWith($this->_autoColumns);
     $this->_allColumns = $columns;
     $items = $this->getItems();
     if ($columns->getCount()) {
         foreach ($columns as $column) {
             $column->initialize();
         }
         $selectedIndex = $this->getSelectedItemIndex();
         $editIndex = $this->getEditItemIndex();
         for ($index = 0; $index < $itemCount; ++$index) {
             if ($index === 0) {
                 if ($allowPaging) {
                     $this->_topPager = $this->createPager();
                 }
                 $this->_header = $this->createItemInternal(-1, -1, TListItemType::Header, false, null, $columns);
             }
             if ($index === $editIndex) {
                 $itemType = TListItemType::EditItem;
             } else {
                 if ($index === $selectedIndex) {
                     $itemType = TListItemType::SelectedItem;
                 } else {
                     if ($index % 2) {
                         $itemType = TListItemType::AlternatingItem;
                     } else {
                         $itemType = TListItemType::Item;
                     }
                 }
             }
             $items->add($this->createItemInternal($index, $dsIndex, $itemType, false, null, $columns));
             $dsIndex++;
         }
         if ($index > 0) {
             $this->_footer = $this->createItemInternal(-1, -1, TListItemType::Footer, false, null, $columns);
             if ($allowPaging) {
                 $this->_bottomPager = $this->createPager();
             }
         }
     }
     if (!$dsIndex && $this->_emptyTemplate !== null) {
         $this->_useEmptyTemplate = true;
         $this->_emptyTemplate->instantiateIn($this);
     }
 }