Exemplo n.º 1
0
 /**
  * Creates a new PaginInfo object which sorts by the given column.
  * Records per page is set to a large-enough number.
  * This method can be used when you need a certain finder method to sort
  * by a specific field.
  *
  * @param String $orderByColumn
  * @param Boolean $orderByAscending
  * @return PagingInfo
  */
 public static function newSorter($orderByColumn, $orderByAscending = true)
 {
     $pagingInfo = new PagingInfo();
     $pagingInfo->limit(1000);
     $pagingInfo->setOrderByColumn($orderByColumn);
     $pagingInfo->setOrderByAscending($orderByAscending);
     return $pagingInfo;
 }
Exemplo n.º 2
0
 /**
  * @covers QueryPager::getQuery
  * @covers QueryPager::__construct
  */
 public function testGetQueryWithFilter()
 {
     $sql = "SELECT * FROM office";
     $this->paging->setOrderByColumn('officeName');
     $this->paging->setOrderByAscending(false);
     $excepted = "select SQL_CALC_FOUND_ROWS * from (SELECT * FROM office) _x order by officeName desc limit 0, 5";
     $pager = new \QueryPager($sql, $this->paging);
     $this->assertEquals($excepted, $pager->getQuery());
 }
Exemplo n.º 3
0
 /**
  * Set the default sorting order for the PaginInfo of this table. This will
  * apply only if the order was not yet assigned.
  *
  * @param String $column the column by which to order
  * @param boolean $asc whether the sorting order is ascending or not. Default is false (descending)
  */
 public function setDefaultOrder($column, $asc = true)
 {
     if ($this->pagingInfo->getOrderByColumn() != '') {
         return;
     }
     $this->pagingInfo->setOrderByColumn($column);
     $this->pagingInfo->setOrderByAscending($asc);
 }
Exemplo n.º 4
0
 /**
  * Return the query, with the paging applied to it.
  * @return String the sql query
  */
 public function getQuery()
 {
     if ($this->paging == null) {
         return $this->sql;
     }
     $search = $this->paging->getSearchInfo();
     if ($search != null && $this->includeFilter) {
         $this->applySearchFilter($search);
     }
     $newSql = "select SQL_CALC_FOUND_ROWS * from (" . $this->sql . ") _x";
     if ($this->paging->getOrderByColumn()) {
         $newSql .= " order by " . $this->paging->getOrderByColumn();
         $newSql .= $this->paging->isOrderByAscending() ? ' asc' : ' desc';
     }
     $newSql .= " limit " . $this->paging->getFirstRecord() . ", " . $this->paging->getRecordsPerPage();
     return $newSql;
 }
Exemplo n.º 5
0
 /**
  * Get the actual content published by this datatable.
  * This includes metadata regarding the total number of records, as well as
  * the actual content to be shown on the current page.
  *
  * @return Map - an associative array.
  */
 public function getDocument()
 {
     $doc = array('sEcho' => $this->sEcho, 'iTotalRecords' => $this->totalRecords, 'iTotalDisplayRecords' => $this->pagingInfo->getTotalRows(), 'aaData' => $this->entries);
     return $doc;
 }
Exemplo n.º 6
0
 /**
  * @covers PagingInfo::isOrderByAscending
  */
 public function testIsOrderByAscending()
 {
     $this->paging->setOrderByAscending(false);
     $this->assertFalse($this->paging->isOrderByAscending());
 }