Named scope to filter either archived or unarchived records

@param boolean $isArchived if set to true, only archived records will be
returned. other wise only unarchived records.
@return \yii\db\ActiveQuery
175493
public function isArchived($isArchived)
	{
		if ($this->modelInstance === null) {
			$this->modelInstance = new $this->owner->modelClass();
		}

		$column = sprintf('%s.%s', $this->modelInstance->tableName(), $this->modelInstance->archiveAttribute);
		$value = $isArchived ? $this->modelInstance->archivedValue : $this->modelInstance->unarchivedValue;

		$this->owner->andWhere([$column=>$value]);

		return $this->owner;
	}
330611
protected function filterInactive($data, $checkIfActive = false)
    {
        return $data && (!$checkIfActive || ($checkIfActive && $data['OXACTIVE']) == '1') ? $data : null;
    }
1220735
public function all($fields = [], $sorted = true, $sortBy = 'cn', $sortByDirection = 'asc')
    {
        $namingContext = $this->getConfigurationNamingContext();

        if ($namingContext) {
            $search = $this->adldap->search()
                ->setDn($namingContext)
                ->select($fields)
                ->where('objectCategory', '=', $this->serverObjectCategory);

            if ($sorted) {
                $search->sortBy($sortBy, $sortByDirection);
            }

            return $search->get();
        }

        return false;
    }
33119
public static function isActiveRecord($object, $throwException=false)
	{
		if ($object instanceof \yii\db\ActiveRecord) return true;
		if ($throwException) {
			$msg = Yii::t('app', 'Object {obj} does not extend ActiveRecord', ['obj'=>get_class($object)]);
			throw new InvalidConfigException($msg);
		}

		return false;
	}
1374115
public function search($params)
    {
        $query = SeoRedirect::find();
        $dataProvider = new ActiveDataProvider([
            'query' => $query,
            'sort' => [
                'defaultOrder' => ['id' => SORT_DESC],
            ],
        ]);
        $this->load($params);
        if (!$this->validate()) {
            return $dataProvider;
        }
        $query->andFilterWhere([
            SeoRedirect::tableName() . '.id' => $this->id,
            SeoRedirect::tableName() . '.code' => $this->code,
        ])->andFilterWhere(['LIKE', SeoRedirect::tableName() . '.from', $this->from])
            ->andFilterWhere(['LIKE', SeoRedirect::tableName() . '.to', $this->to]);
        return $dataProvider;
    }
670407
public function search($params)
    {
        $query = Category::find();
        $query->orderBy('position DESC, title');

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'parent_id' => $this->parent_id,
            'position' => $this->position,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'alias', $this->alias]);

        return $dataProvider;
    }
1109322
public function search($params)
    {
        /** @var ActiveRecord $owner */
        $owner = $this->owner;
        $query = $owner::find();
        $t = is_array($query->from) ? key($query->from) : $query->from;
        return $query
            ->filterWhere($params)
            ->andWhere(["$t.owner_id" => Yii::$app->user->identity->{$this->attribute}]);
    }
620990
private function getFilterFieldActive($isActive)
    {
        $request = $this->getRequest();

        if ($request->query->has('is_active')) {
            $isActive = $request->query->get('is_active');
        }

        $oViewRenderer = new ViewRenderer();
        $oViewRenderer->AddSourceObject('sInputClass', 'form-control input-sm submitOnSelect');
        $oViewRenderer->AddSourceObject('sName', 'is_active');
        $oViewRenderer->AddSourceObject('sLabelText', $this->getTranslation('chameleon_system_shop.list_manager_article.filter_active_label'));
        $oViewRenderer->AddSourceObject('sValue', $isActive);
        $oViewRenderer->AddSourceObject('autoWidth', true);

        $aValueList = array();
        $aValueList[] = array('sName' => $this->getTranslation('chameleon_system_shop.list_manager_article.filter_active_all'), 'sValue' => 'all');
        $aValueList[] = array('sName' => $this->getTranslation('chameleon_system_shop.list_manager_article.filter_active_only_active'), 'sValue' => '1');
        $aValueList[] = array('sName' => $this->getTranslation('chameleon_system_shop.list_manager_article.filter_active_only_inactive'), 'sValue' => '0');

        $oViewRenderer->AddSourceObject('aValueList', $aValueList);

        return $oViewRenderer->Render('userInput/form/select.html.twig', null, false);
    }
877732
public function isArchived()
    {
        $id = $this->owner->ID ?: $this->owner->OldID;
        return $id && !$this->isOnDraft() && !$this->isPublished();
    }
113762
public function search()
    {
        $query = Rubric::find()
            ->where('id>1')
            ->orderBy('lft ASC, position DESC');

        return new ActiveDataProvider([
            'query' => $query,
            'pagination' => [
                'pageSize' => Yii::$app->params['itemsPerPage'],
            ],
        ]);
    }
138488
protected function redirectAfterSave($isNewRecord)
    {
        $controller = $this->getToplevelController();
        if ($isNewRecord) {
            return $controller->redirect($this->Link());
        } elseif ($this->gridField->getList()->byID($this->record->ID)) {
            // Return new view, as we can't do a "virtual redirect" via the CMS Ajax
            // to the same URL (it assumes that its content is already current, and doesn't reload)
            return $this->edit($controller->getRequest());
        } else {
            // Changes to the record properties might've excluded the record from
            // a filtered list, so return back to the main view if it can't be found
            $url = $controller->getRequest()->getURL();
            $noActionURL = $controller->removeAction($url);
            $controller->getRequest()->addHeader('X-Pjax', 'Content');
            return $controller->redirect($noActionURL, 302);
        }
    }
907625
public function isActive($name = '', $value = self::ALL, $trueReturn = true, $falseReturn = false)
    {
        $currentFilters = $this->filters;
        if (!$name) {
            return $falseReturn;
        }
        if (!$currentFilters || !isset($currentFilters["$name"])) {
            if ($value === self::ALL) {
                return $trueReturn;
            } else {
                return $falseReturn;
            }
        }
        $valueArray = explode(',', $currentFilters["$name"]);
        if (in_array($value, $valueArray)) {
            return $trueReturn;
        } else {
            return $falseReturn;
        }
    }
1128457
protected function hasOne($associatedClass, $foreignKey = null, $mappingKeyInBaseTable = null)
    {
        return $this->findHasOneOrMany($associatedClass, $foreignKey, $mappingKeyInBaseTable);
    }
1002331
public function connect($shardId = null)
    {
        if ($shardId === null && $this->_conn) {
            return false;
        }

        if ($shardId !== null && $shardId === $this->activeShardId) {
            return false;
        }

        if ($this->getTransactionNestingLevel() > 0) {
            throw new ShardingException('Cannot switch shard when transaction is active.');
        }

        $activeShardId = $this->activeShardId = (int) $shardId;

        if (isset($this->activeConnections[$activeShardId])) {
            $this->_conn = $this->activeConnections[$activeShardId];

            return false;
        }

        $this->_conn = $this->activeConnections[$activeShardId] = $this->connectTo($activeShardId);

        if ($this->_eventManager->hasListeners(Events::postConnect)) {
            $eventArgs = new ConnectionEventArgs($this);
            $this->_eventManager->dispatchEvent(Events::postConnect, $eventArgs);
        }

        return true;
    }
308383
public function lazyFind($baseRecord)
	{
		if(is_string($this->_table->primaryKey))
			$this->records[$baseRecord->{$this->_table->primaryKey}]=$baseRecord;
		else
		{
			$pk=array();
			foreach($this->_table->primaryKey as $name)
				$pk[$name]=$baseRecord->$name;
			$this->records[serialize($pk)]=$baseRecord;
		}

		foreach($this->stats as $stat)
			$stat->query();

		if(!$this->children)
			return;

		$params=array();
		foreach($this->children as $child)
			if(is_array($child->relation->params))
				$params=array_merge($params,$child->relation->params);

		$query=new CJoinQuery($child);
		$query->selects=array($child->getColumnSelect($child->relation->select));
		$query->conditions=array(
			$child->relation->on,
		);
		$query->groups[]=$child->relation->group;
		$query->joins[]=$child->relation->join;
		$query->havings[]=$child->relation->having;
		$query->orders[]=$child->relation->order;
		$query->params=$params;
		$query->elements[$child->id]=true;
		if($child->relation instanceof CHasManyRelation)
		{
			$query->limit=$child->relation->limit;
			$query->offset=$child->relation->offset;
		}

		$child->applyLazyCondition($query,$baseRecord);

		$this->_joined=true;
		$child->_joined=true;

		$this->_finder->baseLimited=false;
		$child->buildQuery($query);
		$child->runQuery($query);
		foreach($child->children as $c)
			$c->find();

		if(empty($child->records))
			return;
		if($child->relation instanceof CHasOneRelation || $child->relation instanceof CBelongsToRelation)
			$baseRecord->addRelatedRecord($child->relation->name,reset($child->records),false);
		else // has_many and many_many
		{
			foreach($child->records as $record)
			{
				if($child->relation->index!==null)
					$index=$record->{$child->relation->index};
				else
					$index=true;
				$baseRecord->addRelatedRecord($child->relation->name,$record,$index);
			}
		}
	}
1371974
public static function findAllActiveByIds(array $arrIds, array $arrOptions = [])
	{
		$t    = static::$strTable;
		$time = \Date::floorToMinute();

		$arrColumns = ["$t.login='1' AND ($t.start='' OR $t.start<='$time') AND ($t.stop='' OR $t.stop>'" . ($time + 60) . "') AND $t.disable=''"];

		$arrColumns[] = \Database::getInstance()->findInSet('id', $arrIds);

		return static::findBy($arrColumns, null, $arrOptions);
	}
632285
public function get($archiverId, $isAvailable = null)
    {
        $this->has($archiverId, true);

        if ($isAvailable === null) {
            return $this->archivers[$archiverId];
        }

        if ($this->archivers[$archiverId]->isAvailable() === (bool) $isAvailable) {
            return $this->archivers[$archiverId];
        }

        return null;
    }