find() public static method

public static find ( ) : ActiveQuery
return ActiveQuery the newly created [[ActiveQuery]] instance.
 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;
 }
Exemplo n.º 2
0
 public static function find()
 {
     if (array_key_exists('deleted', static::getTableSchema()->columns)) {
         return parent::find()->onCondition(static::tableName() . '.deleted = 0');
     } else {
         return parent::find();
     }
 }
Exemplo n.º 3
0
 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;
 }
Exemplo n.º 4
0
 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;
 }
Exemplo n.º 5
0
 public static function getItems()
 {
     $items = [];
     $models = parent::find()->all();
     foreach ($models as $model) {
         $items[] = ['label' => $model->title, 'url' => $model->slug];
     }
     return $items;
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 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();
     }
 }
Exemplo n.º 8
0
Arquivo: Map.php Projeto: promo-pr/cms
 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;
 }
Exemplo n.º 9
0
 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]);
 }
Exemplo n.º 11
0
 /**
  * @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]);
 }
Exemplo n.º 14
0
 public static function find()
 {
     return parent::find()->with('type');
 }
Exemplo n.º 15
0
 /**
  * @inherit
  */
 public static function find()
 {
     return parent::find()->where(['status' => self::STATUS_ACTIVE, 'type' => static::TYPE]);
 }
Exemplo n.º 16
0
 public static function find()
 {
     return parent::find()->select('log_main.*, INET_NTOA(log_main.ip) as ip');
 }
Exemplo n.º 17
0
 public static function find()
 {
     return parent::find()->orderBy('{{timezone}}.[[order]] ASC');
 }
Exemplo n.º 18
0
 public static function find()
 {
     return parent::find()->joinWith('translations');
 }
Exemplo n.º 19
0
 /**
  * @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]);
 }
Exemplo n.º 20
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public static function findWithTranslations()
 {
     return parent::find()->with('translation');
 }
Exemplo n.º 21
0
 /**
  * @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;
 }
Exemplo n.º 22
0
 public static function find()
 {
     return parent::find()->orderBy('sort_index ASC');
 }
Exemplo n.º 23
0
 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;
 }
Exemplo n.º 24
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public static function find()
 {
     return parent::find()->andWhere('"status" <> \'delete\'');
 }
Exemplo n.º 25
0
 public static function find()
 {
     return parent::find()->with(['group']);
 }
Exemplo n.º 26
0
 public static function find()
 {
     return parent::find()->where([static::tableName() . ".deleted" => 0]);
 }
Exemplo n.º 27
0
 public static function find()
 {
     return parent::find()->andWhere(['<>', 'is_status', 2]);
 }
Exemplo n.º 28
0
 /**
  * @
  */
 public static function findIdentity($id)
 {
     //自动登陆时会调用
     $temp = parent::find()->where(['id' => $id])->one();
     return isset($temp) ? new static($temp) : null;
 }
Exemplo n.º 29
0
 public static function find()
 {
     return parent::find()->where(['type' => self::TYPE_ROLE]);
 }
Exemplo n.º 30
0
 /**
  * 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']);
 }