public function search($params) { /* @var $query \yii\db\ActiveQuery */ $query = $this->baseModel->find(); $table_inheritance_joined = false; $dataProvider = new ActiveDataProvider(['query' => &$query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); if (!$this->load($params)) { return $dataProvider; } $object = Object::getForClass($this->baseModel->className()); $baseModelTableName = $this->baseModel->tableName(); $eavJoinsCount = 0; $osvJoinsCount = 0; foreach ($this->propertyGroups as $groupId => $properties) { foreach ($properties as $key => $propertyValue) { /** @var \app\properties\PropertyValue $propertyValue */ $prop = Property::findById($propertyValue->property_id); if (empty($this->{$prop->key}) === true && $this->{$prop->key} !== '0') { continue; } // determine property storage type and join needed table if needed if ($prop->is_column_type_stored) { if ($table_inheritance_joined === false) { $table_inheritance_joined = true; $query->join('INNER JOIN', $object->column_properties_table_name . ' ti', 'ti.object_model_id = ' . $baseModelTableName . '.id'); } if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) { $query->andFilterWhere(['like', 'ti.' . $prop->key, $this->{$prop->key}]); } else { $query->andFilterWhere(['ti.' . $prop->key => $this->{$prop->key}]); } } elseif ($prop->is_eav) { $eavJoinsCount++; $eavTableName = 'eav' . $eavJoinsCount; $key = 'key' . $eavJoinsCount; $query->join('INNER JOIN', "{$object->eav_table_name} {$eavTableName}", $eavTableName . '.object_model_id = ' . $baseModelTableName . ".id AND {$eavTableName}.key=:{$key}", [$key => $prop->key]); if ($prop->value_type === 'STRING' && $prop->property_handler_id !== 3) { $query->andFilterWhere(['like', $eavTableName . '.value', $this->{$prop->key}]); } else { // numeric - direct match $query->andFilterWhere([$eavTableName . '.value' => $this->{$prop->key}]); } } elseif ($prop->has_static_values) { $osvJoinsCount++; $osvTableName = 'osv' . $osvJoinsCount; $query->join('INNER JOIN', "object_static_values {$osvTableName}", "{$osvTableName}.object_id={$object->id} AND {$osvTableName}.object_model_id={$baseModelTableName}.id"); // numeric - direct match $query->andFilterWhere(["{$osvTableName}.property_static_value_id", $this->{$prop->key}]); } } } return $dataProvider; }
public static function find() { if (array_key_exists('deleted', static::getTableSchema()->columns)) { return parent::find()->onCondition(static::tableName() . '.deleted = 0'); } else { return parent::find(); } }
public static function find() { $user_id = Yii::$app->user->id; $find = parent::find(); $find->andWhere('user_id=:user_id', [':user_id' => $user_id]); // $find->andFilterWhere(['=', 'user_id', $user_id]); return $find; }
public static function find() { $return = parent::find(); if (in_array('deleted_at', parent::attributes())) { $tableName = static::getTableSchema()->name; $return->andWhere([$tableName . '.deleted_at' => null]); } return $return; }
public static function getItems() { $items = []; $models = parent::find()->all(); foreach ($models as $model) { $items[] = ['label' => $model->title, 'url' => $model->slug]; } return $items; }
public static function find() { $city_id = Yii::$app->request->cookies['city']; $p['store_id'] = 109; $query = parent::find(); // $query->where('(store_id=:store_id) and not(title is null) and (value_char != \'\')',$p); $query->where('(store_id=:store_id)', $p); return $query; }
public static function find($onlyDeleted = null) { if (is_null($onlyDeleted)) { return parent::find()->where([self::tableName() . '.delete' => 0]); } elseif ($onlyDeleted === true) { return parent::find()->where([self::tableName() . '.delete' => 1]); } elseif ($onlyDeleted === false) { return parent::find(); } }
public static function getPoints() { $points = parent::find()->all(); if (count($points) > 0) { $geoObject = ['type' => 'FeatureCollection']; foreach ($points as $point) { $geoObject['features'][] = ['type' => 'Feature', 'id' => $point->id, 'geometry' => ['type' => 'Point', 'coordinates' => explode(',', $point->point)], 'properties' => ['balloonContent' => $point->body, 'iconContent' => $point->title], 'options' => ['preset' => $point->preset]]; } } else { $geoObject = false; } return $geoObject; }
public static function find() { $tenantTableName = '{{%tenant}}'; $field = ''; $model = parent::find(); if (parent::tableName() == $tenantTableName) { $field = '.id'; } else { $field = '.tenant_id'; } $model->where([parent::tableName() . $field => Yii::$app->session['tenant']]); return $model; }
public static function find($tables = null) { $aWhere = []; if ($tables) { if (!is_array($tables)) { $tables = [$tables]; } foreach ($tables as $table) { $aWhere[$table . '.disabled'] = self::STATUS_ENABLE; } return parent::find()->where($aWhere); } return parent::find()->where(['disabled' => self::STATUS_ENABLE]); }
/** * @param ActiveRecord $model * @param array $opts * @return ActiveQuery | array */ static function searchQuery($model, $opts = []) { $opts = ArrayHelper::merge(['data' => null, 'query' => null, 'columns' => [], 'filters' => []], $opts); $columns = $opts['columns']; $filters = $opts['filters']; $data = $opts['data']; if (null === $data) { $data = \Yii::$app->request->get(); } $query = $opts['query']; if (is_string($query)) { $query = call_user_func([$model, $opts['query']]); } elseif (null === $query) { $query = $model->find(); foreach (array_filter($model->getAttributes()) as $prop => $val) { $query->andWhere([$prop => $val]); } } if ($model->load($data) && $model->validate()) { foreach ($model->getAttributes($model->safeAttributes()) as $name => $value) { if ($model->isAttributeChanged($name)) { $attributeTypes = []; if (method_exists($model, 'attributeTypes')) { $attributeTypes = $model->attributeTypes(); } $type = null; if (isset($attributeTypes[$name])) { $type = $attributeTypes[$name]; } // Default filter function $filterFunc = isset($filters[$name]) && is_callable($filters[$name]) ? $filters[$name] : function (ActiveQuery $query, $name, $value, $type) { /** * @var string $name * @var string|array $value * @var string $type */ $query->andFilterWhere(static::searchAttribute($name, $value, $type)); }; if (isset($columns[$name])) { $name = $columns[$name]; } call_user_func($filterFunc, $query, $name, $value, $type); } } } return $query; }
/** * Default sort on find command. * * @return ActiveQuery */ public static function find() { return parent::find()->orderBy(['sort_index' => SORT_ASC]); }
public static function findNonDeleted($param) { return parent::find()->where(['and', ['deleted' => false], $param]); }
public static function find() { return parent::find()->with('type'); }
/** * @inherit */ public static function find() { return parent::find()->where(['status' => self::STATUS_ACTIVE, 'type' => static::TYPE]); }
public static function find() { return parent::find()->select('log_main.*, INET_NTOA(log_main.ip) as ip'); }
public static function find() { return parent::find()->orderBy('{{timezone}}.[[order]] ASC'); }
public static function find() { return parent::find()->joinWith('translations'); }
/** * @inheritdoc * @return ActiveQuery the newly created [[ActiveQuery]] instance. */ public static function find() { return parent::find()->andWhere([Yii::$app->getModule('user-management')->auth_item_table . '.type' => static::ITEM_TYPE]); }
/** * @return \yii\db\ActiveQuery */ public static function findWithTranslations() { return parent::find()->with('translation'); }
/** * @return TagQuery */ public static function find() { $query = parent::find(); $query->attachBehavior('taxonomy-tag', ['class' => \nkostadinov\taxonomy\behaviors\TagQuery::className(), 'taxonomy' => \Yii::$app->taxonomy->getTerm('test-tag')]); return $query; }
public static function find() { return parent::find()->orderBy('sort_index ASC'); }
public function getId() { $row = parent::find()->select('max(PROJECT_ID) as PROJECT_ID')->one(); $id = empty($row['PROJECT_ID']) ? 0 : intval($row['PROJECT_ID']) + 1; return $id; }
/** * @return \yii\db\ActiveQuery */ public static function find() { return parent::find()->andWhere('"status" <> \'delete\''); }
public static function find() { return parent::find()->with(['group']); }
public static function find() { return parent::find()->where([static::tableName() . ".deleted" => 0]); }
public static function find() { return parent::find()->andWhere(['<>', 'is_status', 2]); }
/** * @ */ public static function findIdentity($id) { //自动登陆时会调用 $temp = parent::find()->where(['id' => $id])->one(); return isset($temp) ? new static($temp) : null; }
public static function find() { return parent::find()->where(['type' => self::TYPE_ROLE]); }
/** * We can not global set is_deleted=0 to the where condition cause in some parts of the storage we want * to access the name_new_compound to rebuild old image paths. * * @return \yii\db\$this */ public static function find() { return parent::find()->orderBy(['name_original' => 'ASC']); }