示例#1
0
 /**
  * @param string                $id
  * @param string[]              $classes
  * @param string[]              $data
  * @param QueryWrapperInterface $query
  * @param mixed                 $default
  * @param FilterInterface|null  $nextFilter
  */
 public function __construct($id, array $classes, array $data, QueryWrapperInterface $query, $default, FilterInterface $nextFilter = null)
 {
     $this->relationName = array_slice(explode('\\', $query->getPascalCasedObjectName()), -1)[0];
     $relations = $query->find();
     $relationOptions = [];
     foreach ($relations as $relation) {
         $key = $this->makeRelationKey($relation);
         $relationName = (string) $relation;
         $this->relations[$key] = $relation;
         $relationOptions[$key] = $relationName;
     }
     $this->options = array_merge([$default, ''], $relationOptions, [static::ALL, static::ANY, static::NONE]);
     if ($nextFilter === null) {
         $this->nextFilter = new DummyFilter();
     } else {
         $this->nextFilter = $nextFilter;
     }
     $this->id = $id;
     $this->statements = [];
     $this->classes = $classes;
     $this->data = $data;
 }
 /**
  * @param QueryWrapperInterface $query
  * @return QueryWrapperInterface
  */
 public function applyToQuery(QueryWrapperInterface $query)
 {
     $maxPerPage = $this->getCriterion();
     $page = $this->getControl();
     return $query->offset(($page - 1) * $maxPerPage)->limit($maxPerPage);
 }
 /**
  * @param QueryWrapperInterface $query
  * @return boolean
  */
 public function canApplyToQuery(QueryWrapperInterface $query)
 {
     return $query->canFilterBy($this->fieldName, $this->criterion, $this->condition);
 }
示例#4
0
 /**
  * @param QueryWrapperInterface $query
  * @return void
  */
 protected function setFeedbackByQuery(QueryWrapperInterface $query)
 {
     $page = $this->getStatements()[0]->getControl();
     $maxPerPage = $this->getMaxPerPage();
     $totalRows = $query->count();
     $firstRow = min($totalRows, ($page - 1) * $maxPerPage + 1);
     $lastRow = min($firstRow + $maxPerPage - 1, $query->count());
     $this->feedback = "Displaying results {$firstRow}-{$lastRow} of {$totalRows}.";
     $this->page = $page;
     $this->numPages = $this->getMaxPagesByQuery($query);
 }
 /**
  * @param QueryWrapperInterface $query
  * @return boolean
  */
 public function canApplyToQuery(QueryWrapperInterface $query)
 {
     return $query->canOrderBy($this->getFieldName(), $this->getCondition());
 }