andWhere() public method

The new condition and the existing one will be joined using the 'AND' operator.
See also: where()
See also: orWhere()
public andWhere ( string | array $condition )
$condition string | array the new WHERE condition. Please refer to [[where()]] on how to specify this parameter.
 /**
  * Set the page-from-pk option
  * @param QueryInterface $query
  */
 protected function setPageFrom(QueryInterface $query)
 {
     if ($this->pageFromPk) {
         $class = $this->query->modelClass;
         $pks = $class::primaryKey();
         if (count($pks) > 1) {
             throw new NotSupportedException('The "page-from-pk" filter can not be apply for composite primary key.');
         }
         $query->andWhere(['<', $pks[0], $this->pageFromPk]);
     }
     return $query;
 }
Beispiel #2
0
 /**
  * @param \yii\db\QueryInterface $query
  * @param array $params
  * @return \yii\db\QueryInterface
  */
 public function refine($query, $params)
 {
     $where = ['or'];
     $bind = [];
     foreach ($params as $key => $val) {
         $name = ":{$this->name}_{$key}";
         $where[] = "{$this->columnName} LIKE {$name}";
         $bind[$name] = $val . '%';
     }
     $query->andWhere($where, $bind);
     return parent::refine($query, $params);
 }
 /**
  * Adds primary key filter/s to the Query object.
  * 
  * @param QueryInterface $query
  * @return QueryInterface
  */
 protected function addPrimaryKeyCriteria(QueryInterface $query)
 {
     $class = get_class($this->getOwner());
     $pks = (array) $class::primaryKey();
     foreach ($pks as $pk) {
         $query->andWhere([$pk => $this->getOwner()->{$pk}]);
     }
     return $query;
 }
Beispiel #4
0
 /**
  * @param QueryInterface $query
  * @param array $filter
  */
 public function defaultFilter($query, $filter)
 {
     $field = $filter['field'];
     if (isset($this->fieldMap[$field])) {
         $field = $this->fieldMap[$field];
     }
     $op = isset($filter['op']) ? $filter['op'] : 'contains';
     $value = isset($filter['value']) ? $filter['value'] : '';
     if ($value === '' && $op != 'equal') {
         return;
     }
     switch ($op) {
         case 'contains':
             $query->andFilterWhere([$field => $value]);
             break;
         case 'equal':
             $query->andWhere([$field => $value]);
             break;
         case 'notequal':
             $query->andWhere(['<>', $field, $value]);
             break;
         case 'beginwith':
             $query->andWhere(['like', $field, $value . '%']);
             break;
         case 'endwith':
             $query->andWhere(['like', $field, '%' . $value]);
             break;
         case 'less':
             $query->andWhere(['<', $field, $value]);
             break;
         case 'lessorequal':
             $query->andWhere(['<=', $field, $value]);
             break;
         case 'greater':
             $query->andWhere(['>', $field, $value]);
             break;
         case 'greaterorequal':
             $query->andWhere(['>=', $field, $value]);
             break;
     }
 }