/**
  * Using the supplied \Dewdrop\Fields and \Dewdrop\Db\Select, modify the
  * Select to include only the current page with the correct number of
  * records.  The DB driver is used to ensure we can get the total number
  * of records that _would_ have been returned had no pagination been applied
  * after the query has been executed (using whatever facility is provided
  * for that use in the specific RDBMS).
  *
  * @param Fields $fields
  * @param Select $select
  * @return Select
  * @throws Exception
  */
 public function modifySelect(Fields $fields, Select $select)
 {
     if ($this->request->getQuery($this->prefix . 'disable-pagination')) {
         $this->disable();
     }
     $driver = $select->getAdapter()->getDriver();
     $this->page = (int) $this->request->getQuery($this->prefix . 'listing-page', 1);
     $driver->prepareSelectForTotalRowCalculation($select);
     if (!$this->enabled) {
         return $select;
     }
     return $select->limit($this->getPageSize(), $this->getPageSize() * ($this->page - 1));
 }
 /**
  * Using the supplied \Dewdrop\Fields and \Dewdrop\Db\Select, modify the
  * Select to include only the current page with the correct number of
  * records.  The DB driver is used to ensure we can get the total number
  * of records that _would_ have been returned had no pagination been applied
  * after the query has been executed (using whatever facility is provided
  * for that use in the specific RDBMS).
  *
  * @param Fields $fields
  * @param Select $select
  * @return Select
  * @throws Exception
  */
 public function modifySelect(Fields $fields, Select $select)
 {
     if (!$this->isEnabled()) {
         return $select;
     }
     $column = $select->quoteWithAlias($this->field->getTable()->getTableName(), $this->field->getName());
     $this->showingDeletedRecords = (bool) $this->request->getQuery($this->getQueryParameterName());
     if ($this->isShowingDeletedRecords()) {
         return $select->where("{$column} = true");
     } else {
         return $select->where("{$column} = false");
     }
 }
Beispiel #3
0
 /**
  * Given the supplied $fields and \Dewdrop\Request object, find the field
  * referenced in the query string and apply its sort callback to the query.
  *
  * @param Fields $fields
  * @param Select $select
  * @throws \Dewdrop\Fields\Exception
  * @return Select
  */
 public function modifySelect(Fields $fields, Select $select)
 {
     $this->sortedField = null;
     $this->sortedDirection = null;
     /* @var $field FieldInterface */
     foreach ($fields->getSortableFields() as $field) {
         if ($field->getQueryStringId() === urlencode($this->request->getQuery($this->prefix . 'sort'))) {
             if ('ASC' === $this->defaultDirection) {
                 $dir = 'DESC' === strtoupper($this->request->getQuery($this->prefix . 'dir')) ? 'DESC' : 'ASC';
             } else {
                 $dir = 'ASC' === strtoupper($this->request->getQuery($this->prefix . 'dir')) ? 'ASC' : 'DESC';
             }
             $select = call_user_func($this->getFieldAssignment($field), $select, $dir);
             if (!$select instanceof Select) {
                 throw new Exception('Your SelectSort callback must return the modified Select object.');
             }
             $this->sortedField = $field;
             $this->sortedDirection = $dir;
             return $select;
         }
     }
     // Sort by the first visible field that is also sortable, if no other sort was performed
     foreach ($fields->getVisibleFields() as $field) {
         if ($field->isSortable() && (null === $this->defaultField || $this->defaultField === $field)) {
             $this->sortedField = $field;
             $this->sortedDirection = $this->defaultDirection;
             return call_user_func($this->getFieldAssignment($field), $select, $this->defaultDirection);
         }
     }
     return $select;
 }