コード例 #1
0
 /**
  * @return Paginator
  */
 public function getPaginator(Datagrid $datagrid)
 {
     $currentPage = $datagrid->getCriteria()->offset()->get('page');
     $perPageAmount = $datagrid->getCriteria()->offset()->get('amount');
     $elementsAmount = $datagrid->getCollection()->getAmount();
     $pageAmount = ceil($elementsAmount / $perPageAmount);
     $paginator = new Paginator();
     if ($pageAmount <= 1) {
         return $paginator;
     }
     for ($index = 1; $index <= $pageAmount; $index++) {
         $page = array('index' => $index, 'current' => $index == $currentPage ? true : false);
         $paginator->addPage($page);
     }
     return $paginator;
 }
コード例 #2
0
ファイル: Crud.php プロジェクト: phatj/CrudAbstractDataBundle
 /**
  * @param ObjectCriteria $criteria
  * @param ObjectCollection $collection
  * @return Datagrid
  */
 public function createDatagrid(ObjectCriteria $criteria, ObjectCollection $collection)
 {
     $fieldMapper = new FieldMapper();
     $this->configureListFields($fieldMapper);
     $datagrid = new Datagrid();
     $datagrid->setFieldMapper($fieldMapper);
     $datagrid->setCriteria($criteria);
     $datagrid->setFilter($fieldMapper);
     $datagrid->setCollection($collection);
     $table = $this->crudPool->getDatagridHandler()->generateDatagridTable($datagrid);
     $datagrid->setResults($table);
     $paginator = $this->crudPool->getPagination()->getPaginator($datagrid);
     $datagrid->setPaginator($paginator);
     return $datagrid;
 }