當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ActiveQuery::andWhere方法代碼示例

本文整理匯總了PHP中yii\db\ActiveQuery::andWhere方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActiveQuery::andWhere方法的具體用法?PHP ActiveQuery::andWhere怎麽用?PHP ActiveQuery::andWhere使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\db\ActiveQuery的用法示例。


在下文中一共展示了ActiveQuery::andWhere方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: oneOrManyModelComparison

 /**
  * Configures the query as such, that you can filter by a model, its id or an array of both. It is also
  * possible to invert the query. This means all but the one(s) provided.
  *
  * @param \yii\db\ActiveQuery $query the query to modify
  * @param integer|integer[]|\yii\db\ActiveRecord|\yii\db\ActiveRecord[] $param the id(s) or the model(s). If
  * an array is provided, it can be a mix of both
  * @param string $attribute the attribute name to compare (defaults to `id`)
  * @param bool $invert if true t, the query will be inverted (NOT LIKE, NOT, ...)
  */
 public function oneOrManyModelComparison(&$query, $param, $attribute = 'id', $invert = false)
 {
     //get data from array
     if (is_array($param)) {
         $data = [];
         foreach ($param as $p) {
             if ($p instanceof \yii\db\ActiveRecord) {
                 $data[] = $p->{$attribute};
             } else {
                 $data[] = $p;
             }
         }
         $param = $data;
     } else {
         if ($param instanceof \yii\db\ActiveRecord) {
             $param = $param->{$attribute};
         }
     }
     //modify query
     if (!$invert) {
         $query->andWhere([$attribute => $param]);
     } else {
         $query->andWhere(['not', [$attribute => $param]]);
     }
 }
開發者ID:asinfotrack,項目名稱:yii2-toolbox,代碼行數:35,代碼來源:QueryHelper.php

示例2: setParams

 /**
  * @param array $params
  */
 public function setParams($params = [])
 {
     foreach ($params as $col => $value) {
         $this->query->andWhere(['like', $col, [$value]]);
         $this->countQuery->orWhere([$col => $value]);
     }
 }
開發者ID:pbabilas,項目名稱:bcode,代碼行數:10,代碼來源:Searcher.php

示例3: getDataprovider

 public function getDataprovider()
 {
     $query = new ActiveQuery($this::className());
     if ($this->airport_id) {
         $query->andWhere(['airport_id' => $this->airport_id]);
     }
     $query->andWhere(['isarrival' => $this->isarrival]);
     $query->orderBy($this->isarrival == 1 ? "timeto" : "timefrom");
     return new ActiveDataProvider(['query' => $query]);
 }
開發者ID:bth2008,項目名稱:rferu,代碼行數:10,代碼來源:Flights.php

示例4: addAttributesSearchConditions

 /**
  * Use a distinct compare value for each column. Primary and foreign keys support multiple values.
  * @param \yii\db\ActiveQuery $query
  * @return \yii\db\ActiveQuery
  */
 protected function addAttributesSearchConditions(\yii\db\ActiveQuery $query)
 {
     $tablePrefix = $this->getDb()->getSchema()->quoteSimpleTableName('t');
     $conditions = ['and'];
     $formats = $this->attributeFormats();
     $attributes = $this->attributes();
     $relations = $this->relations();
     $validAttributes = array_diff($attributes, array_keys($this->getErrors()));
     $attributeValues = $this->getAttributes($validAttributes);
     $formatter = Yii::$app->formatter;
     /** @var EnumCollection $enums */
     $enums = $formatter instanceof Formatter ? $formatter->getEnums() : null;
     foreach ($validAttributes as $attribute) {
         $value = $attributeValues[$attribute];
         if ($value === null || !isset($formats[$attribute]) || $enums !== null && !is_array($formats[$attribute]) && $enums->has($formats[$attribute])) {
             continue;
         }
         if (in_array($attribute, $relations)) {
             // only hasMany relations should be ever marked as valid attributes
             $conditions[] = $this->getRelationCondition($this->getRelation($attribute), $value);
         } else {
             $conditions[] = $this->getAttributeCondition($attribute, $value, $formats, $tablePrefix, $this->getDb());
         }
     }
     // don't clear attributes to allow rendering filled search form
     //$this->setAttributes(array_fill_keys($attributes, null));
     if ($conditions !== ['and']) {
         $query->andWhere($conditions);
     }
     return $query;
 }
開發者ID:netis-pl,項目名稱:yii2-crud,代碼行數:36,代碼來源:AttributeSearchTrait.php

示例5: getActiveToken

 public static function getActiveToken($token)
 {
     $activeQuery = new ActiveQuery(self::className());
     $activeQuery->where('access_token = :token', [':token' => $token]);
     $activeQuery->andWhere('expires > now()');
     $token = $activeQuery->one();
     return $token;
 }
開發者ID:portalsway2,項目名稱:APEDevices,代碼行數:8,代碼來源:OauthAccessTokens.php

示例6: filterQuery

 public function filterQuery(ActiveQuery $query)
 {
     if ($this->type) {
         $query->innerJoinWith('type');
         $query->andWhere(['{{death_reason_type}}.[[key]]' => $this->type]);
     }
     return $query;
 }
開發者ID:Bochozkar,項目名稱:stat.ink,代碼行數:8,代碼來源:DeathReasonGetForm.php

示例7: addCondition

 /**
  * @param ActiveQuery $query
  * @param string $attribute
  * @param bool $partialMath
  */
 private function addCondition($query, $attribute, $partialMath = false)
 {
     if (isset($this->relationAttributes[$attribute])) {
         $attributeName = $this->relationAttributes[$attribute];
     } else {
         $attributeName = call_user_func([$this->modelClassName, 'tableName']) . '.' . $attribute;
     }
     $value = $this->{$attribute};
     if ($value === '') {
         return;
     }
     if ($partialMath) {
         $query->andWhere(['like', $attributeName, $value]);
     } else {
         $query->andWhere([$attributeName => $value]);
     }
 }
開發者ID:tqsq2005,項目名稱:dotplant2,代碼行數:22,代碼來源:SearchModel.php

示例8: addCondition

 /**
  * @param ActiveQuery $query
  * @param $attribute
  * @param bool|false $partialMatch
  */
 protected function addCondition(ActiveQuery $query, $attribute, $partialMatch = false)
 {
     if (($pos = strrpos($attribute, '.')) !== false) {
         $modelAttribute = substr($attribute, $pos + 1);
     } else {
         $modelAttribute = $attribute;
     }
     $value = $this->{$modelAttribute};
     if (trim($value) === '') {
         return;
     }
     $attribute = "books.{$attribute}";
     if ($partialMatch) {
         $query->andWhere(['like', $attribute, $value]);
     } else {
         $query->andWhere([$attribute => $value]);
     }
 }
開發者ID:kocapb,項目名稱:library,代碼行數:23,代碼來源:BookSearch.php

示例9: filterQuery

 public function filterQuery(ActiveQuery $query)
 {
     if ($this->weapon) {
         $query->andWhere(['{{weapon}}.[[key]]' => $this->weapon]);
     }
     if ($this->type) {
         $query->innerJoinWith('type');
         $query->andWhere(['{{weapon_type}}.[[key]]' => $this->type]);
     }
     if ($this->sub) {
         $query->innerJoinWith('subweapon');
         $query->andWhere(['{{subweapon}}.[[key]]' => $this->sub]);
     }
     if ($this->special) {
         $query->innerJoinWith('special');
         $query->andWhere(['{{special}}.[[key]]' => $this->special]);
     }
     return $query;
 }
開發者ID:ExceptionError,項目名稱:stat.ink,代碼行數:19,代碼來源:WeaponGetForm.php

示例10: filter

 public function filter(ActiveQuery $query, &$cacheKeyAppend)
 {
     $get = Yii::$app->request->post();
     if (isset($get['changeValue']) && is_array($get['changeValue'])) {
         foreach ($get['changeValue'] as $propertyId => $isActive) {
             if ($isActive && isset($get[$this->minValueAttribute][$propertyId]) && isset($get[$this->maxValueAttribute][$propertyId]) && is_numeric($get[$this->minValueAttribute][$propertyId]) && is_numeric($get[$this->maxValueAttribute][$propertyId])) {
                 $property = Property::findById($propertyId);
                 if ($property->has_static_values) {
                     $query->innerJoin('{{%object_static_values}} as osvf' . $propertyId, '{{%product}}.id=osvf' . $propertyId . '.object_model_id');
                     $query->innerJoin('{{%property_static_values}} as psvf' . $propertyId, 'psvf' . $propertyId . '.id=osvf' . $propertyId . '.property_static_value_id');
                     $query->andWhere('psvf' . $propertyId . '.value >= :minData ')->andWhere('psvf' . $propertyId . '.value <= :maxData ')->andWhere(['psvf' . $propertyId . '.property_id' => $propertyId])->addParams([':minData' => (int) $get[$this->minValueAttribute][$propertyId], ':maxData' => (int) $get[$this->maxValueAttribute][$propertyId]]);
                 } elseif ($property->is_eav) {
                     $query->innerJoin('{{%product_eav}} as peav' . $propertyId, '{{%product}}.id=peav' . $propertyId . '.object_model_id');
                     $query->andWhere(['peav' . $propertyId . '.property_group_id' => $property->property_group_id, 'peav' . $propertyId . '.key' => $property->key]);
                     $query->andWhere(['>=', 'peav' . $propertyId . '.value', (int) $get[$this->minValueAttribute][$propertyId]]);
                     $query->andWhere(['<=', 'peav' . $propertyId . '.value', (int) $get[$this->maxValueAttribute][$propertyId]]);
                 }
                 $cacheKeyAppend .= 'FilterRangeProperty:propertyId' . $propertyId . ':[min:' . (int) $get[$this->minValueAttribute][$propertyId] . ':max' . (int) $get[$this->maxValueAttribute][$propertyId] . ']';
             }
         }
     }
     return $query;
 }
開發者ID:lzpfmh,項目名稱:dotplant2,代碼行數:23,代碼來源:FilterRangeProperty.php

示例11: filter

 public function filter(ActiveQuery $query, &$cacheKeyAppend)
 {
     $get = Yii::$app->request->post();
     if (isset($get['changeValue']) && is_array($get['changeValue'])) {
         foreach ($get['changeValue'] as $propertyId => $isActive) {
             if ($isActive && isset($get[$this->minValueAttribute][$propertyId]) && isset($get[$this->maxValueAttribute][$propertyId]) && is_numeric($get[$this->minValueAttribute][$propertyId]) && is_numeric($get[$this->maxValueAttribute][$propertyId])) {
                 $query->innerJoin('object_static_values as osvf' . $propertyId, 'product.id=osvf' . $propertyId . '.object_model_id');
                 $query->innerJoin('property_static_values as psvf' . $propertyId, 'psvf' . $propertyId . '.id=osvf' . $propertyId . '.property_static_value_id');
                 $query->andWhere('psvf' . $propertyId . '.value >= :minData ')->andWhere('psvf' . $propertyId . '.value <= :maxData ')->andWhere(['psvf' . $propertyId . '.property_id' => $propertyId])->addParams([':minData' => (int) $get[$this->minValueAttribute][$propertyId], ':maxData' => (int) $get[$this->maxValueAttribute][$propertyId]]);
                 $cacheKeyAppend .= 'FilterRangeProperty[min:' . (int) $get[$this->minValueAttribute][$propertyId] . ':max' . (int) $get[$this->maxValueAttribute][$propertyId] . ']';
             }
         }
     }
     return $query;
 }
開發者ID:tqsq2005,項目名稱:dotplant2,代碼行數:15,代碼來源:FilterRangeProperty.php

示例12: setupFilters

 /**
  * Setup additional filters
  */
 public function setupFilters()
 {
     if (in_array('entry_files', $this->filters)) {
         $fileSelector = (new \yii\db\Query())->select(["id"])->from('file')->where('file.object_model=content.object_model AND file.object_id=content.object_id')->limit(1);
         $fileSelectorSql = Yii::$app->db->getQueryBuilder()->build($fileSelector)[0];
         $this->activeQuery->andWhere('(' . $fileSelectorSql . ') IS NOT NULL');
     }
     // Setup Post specific filters
     if (in_array('posts_links', $this->filters)) {
         $this->activeQuery->leftJoin('post', 'content.object_id=post.id AND content.object_model=:postModel', ['postModel' => \humhub\modules\post\models\Post::className()]);
         $this->activeQuery->andWhere("post.url is not null");
     }
     // Only apply archived filter when we should load more than one entry
     if ($this->limit != 1) {
         if (!in_array('entry_archived', $this->filters)) {
             $this->activeQuery->andWhere("(content.archived != 1 OR content.archived IS NULL)");
         }
     }
     // Show only mine items
     if (in_array('entry_mine', $this->filters) && $this->user !== null) {
         $this->activeQuery->andWhere(['content.created_by' => $this->user->id]);
     }
     // Show only items where the current user is involed
     if (in_array('entry_userinvoled', $this->filters) && $this->user !== null) {
         $this->activeQuery->leftJoin('user_follow', 'content.object_model=user_follow.object_model AND content.object_id=user_follow.object_id AND user_follow.user_id = :userId', ['userId' => $this->user->id]);
         $this->activeQuery->andWhere("user_follow.id IS NOT NULL");
     }
     if (in_array('model_posts', $this->filters)) {
         $this->activeQuery->andWhere(["content.object_model" => \humhub\modules\post\models\Post::className()]);
     }
     // Visibility filters
     if (in_array('visibility_private', $this->filters)) {
         $this->activeQuery->andWhere(['content.visibility' => Content::VISIBILITY_PRIVATE]);
     }
     if (in_array('visibility_public', $this->filters)) {
         $this->activeQuery->andWhere(['content.visibility' => Content::VISIBILITY_PUBLIC]);
     }
 }
開發者ID:VasileGabriel,項目名稱:humhub,代碼行數:41,代碼來源:Stream.php

示例13: _run

 protected function _run()
 {
     $key = $this->getCacheKey() . 'run';
     $dependency = new TagDependency(['tags' => [$this->className() . (string) $this->namespace, (new Tree())->getTableCacheTag()]]);
     $result = \Yii::$app->cache->get($key);
     if ($result === false || $this->enabledRunCache == Cms::BOOL_N) {
         $this->activeQuery = Tree::find();
         if ($this->treePid) {
             $this->activeQuery->andWhere(['pid' => $this->treePid]);
         }
         if ($this->level) {
             $this->activeQuery->andWhere(['level' => $this->level]);
         }
         if ($this->active) {
             $this->activeQuery->andWhere(['active' => $this->active]);
         }
         if ($this->site_codes) {
             $this->activeQuery->andWhere(['site_code' => $this->site_codes]);
         }
         if ($this->enabledCurrentSite == Cms::BOOL_Y && ($currentSite = \Yii::$app->cms->site)) {
             $this->activeQuery->andWhere(['site_code' => $currentSite->code]);
         }
         if ($this->orderBy) {
             $this->activeQuery->orderBy([$this->orderBy => (int) $this->order]);
         }
         if ($this->tree_type_ids) {
             $this->activeQuery->andWhere(['tree_type_id' => $this->tree_type_ids]);
         }
         /**
          *
          */
         if ($this->with) {
             $this->activeQuery->with($this->with);
         }
         if ($this->activeQueryCallback && is_callable($this->activeQueryCallback)) {
             $callback = $this->activeQueryCallback;
             $callback($this->activeQuery);
         }
         $result = parent::_run();
         \Yii::$app->cache->set($key, $result, (int) $this->runCacheDuration, $dependency);
     }
     return $result;
 }
開發者ID:Liv1020,項目名稱:cms,代碼行數:43,代碼來源:TreeMenuCmsWidget.php

示例14: buildElementsQuery

 /**
  * Конфигурирование объекта запроса поиска по элементам.
  *
  * @param \yii\db\ActiveQuery $activeQuery
  * @param null $modelClassName
  * @return $this
  */
 public function buildElementsQuery(\yii\db\ActiveQuery $activeQuery)
 {
     $where = [];
     //Нужно учитывать связанные дополнительные данные
     if ($this->enabledElementProperties == Cms::BOOL_Y) {
         $activeQuery->joinWith('cmsContentElementProperties');
         //Нужно учитывать настройки связанные дополнительные данных
         if ($this->enabledElementPropertiesSearchable == Cms::BOOL_Y) {
             $activeQuery->joinWith('cmsContentElementProperties.property');
             $where[] = ['and', ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false], [CmsContentProperty::tableName() . ".searchable" => Cms::BOOL_Y]];
         } else {
             $where[] = ['like', CmsContentElementProperty::tableName() . ".value", '%' . $this->searchQuery . '%', false];
         }
     }
     //Поиск по основному набору полей
     if ($this->searchElementFields) {
         foreach ($this->searchElementFields as $fieldName) {
             $where[] = ['like', CmsContentElement::tableName() . "." . $fieldName, '%' . $this->searchQuery . '%', false];
         }
     }
     if ($where) {
         $where = array_merge(['or'], $where);
         $activeQuery->andWhere($where);
     }
     //Отфильтровать только конкретный тип
     if ($this->searchElementContentIds) {
         $activeQuery->andWhere([CmsContentElement::tableName() . ".content_id" => (array) $this->searchElementContentIds]);
     }
     return $this;
 }
開發者ID:Liv1020,項目名稱:cms,代碼行數:37,代碼來源:CmsSearchComponent.php

示例15: where

 /**
  * Adds an additional WHERE condition to the existing one.
  * 
  * @inheritdoc
  * 
  * @param type $condition
  * @param type $params
  * @return type
  */
 public function where($condition, $params = array())
 {
     return parent::andWhere($condition, $params);
 }
開發者ID:kreativmind,項目名稱:humhub,代碼行數:13,代碼來源:ActiveQueryContent.php


注:本文中的yii\db\ActiveQuery::andWhere方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。