X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=models%2FItemsSearch.php;h=b3dbe9a52096d3512347a47c09984214b4878cb5;hb=6a4e0c86e4e59436b1e52efd10fdf0cfdf345712;hp=ec6280c0a307ea81788c8cf490108857317e8d15;hpb=84a6dbe8fa2767ad2ac57d702ac587db42312760;p=invent%2Finvent.git diff --git a/models/ItemsSearch.php b/models/ItemsSearch.php index ec6280c..b3dbe9a 100644 --- a/models/ItemsSearch.php +++ b/models/ItemsSearch.php @@ -22,8 +22,8 @@ class ItemsSearch extends Items public function rules() { return [ - [['id', 'type_id'], 'integer'], - [['name', 'model', 'os', 'mac', 'serial', 'product', 'modelnumber', 'invent', 'date', 'comment', 'statusName', 'typeName', 'locationName', 'regionName'], 'safe'], + [['id', 'model_id'], 'integer'], + [['name', 'modelName', 'os', 'mac', 'serial', 'invent', 'date', 'comment', 'statusName', 'typeName', 'locationName', 'regionName'], 'safe'], ]; } @@ -62,12 +62,13 @@ class ItemsSearch extends Items $query = Items::find() ->select(Items::tableName() . '.*, ' . Locations::tableName() . '.name AS locationName, ' . + Models::tableName() . '.name AS modelName, ' . Types::tableName() . '.name AS typeName, ' . Regions::tableName() . '.name AS regionName, ' . Status::tableName() . '.name AS statusName ') - ->joinWith([ 'types', 'moving', 'status', 'locations', 'regions' ]) + ->joinWith([ 'types', 'moving', 'status', 'locations', 'regions', 'models', ]) ->where([ 'in', Moving::tableName() . '.id', $query ]) - ->andWhere([ 'checked' => false ]); + ->andWhere([ 'checked' => 0 ]); $dataProvider = new ActiveDataProvider([ 'query' => $query, @@ -77,6 +78,44 @@ class ItemsSearch extends Items 'id' => SORT_ASC, ], ]); + + $this->load($params); + if (!$this->validate()) + { + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + ])->andFilterWhere([ + 'ilike', Status::tableName() . '.name', $this->statusName + ])->andFilterWhere([ + 'ilike', Models::tableName() . '.name', $this->modelName + ])->andFilterWhere([ + 'ilike', Types::tableName() . '.name', $this->typeName + ])->andFilterWhere([ 'OR', [ + 'ilike', Locations::tableName() . '.name', $this->regionName + ], [ + 'ilike', Regions::tableName() . '.name', $this->regionName + ]])->andFilterWhere([ 'OR', [ + 'ilike', Locations::tableName() . '.name', $this->locationName + ], [ + 'ilike', Regions::tableName() . '.name', $this->locationName + ]]); + + $query->andFilterWhere(['ilike', 'name', $this->name]) + ->andFilterWhere( ['ilike', 'os', $this->os]) + ->andFilterWhere( ['ilike', 'mac', $this->mac]) + ->andFilterWhere( ['ilike', 'serial', $this->serial]) + ->andFilterWhere( ['ilike', 'invent', $this->invent]) + ->andFilterWhere( ['ilike', 'comment', $this->comment]); + + + $dataProvider->sort->attributes['modelName'] = [ + 'asc' => [ Models::tableName() . '.name' => SORT_ASC ], + 'desc' => [ Models::tableName() . '.name' => SORT_DESC ], + ]; $dataProvider->sort->attributes['statusName'] = [ 'asc' => [ Status::tableName() . '.name' => SORT_ASC ], 'desc' => [ Status::tableName() . '.name' => SORT_DESC ], @@ -114,17 +153,20 @@ class ItemsSearch extends Items $query = Items::find() ->select(Items::tableName() . '.*, ' . Locations::tableName() . '.name AS locationName, ' . -// Models::tableName() . '.name AS modelName' . + Models::tableName() . '.name AS modelName, ' . Types::tableName() . '.name AS typeName, ' . Regions::tableName() . '.name AS regionName, ' . Status::tableName() . '.name AS statusName ') - ->joinWith([ 'types', 'moving', 'status', 'locations', 'regions', /* 'models', */ ]) + ->joinWith([ 'types', 'moving', 'status', 'locations', 'regions', 'models', ]) ->where([ 'in', Moving::tableName() . '.id', $subQuery ]); // add conditions that should always apply here $dataProvider = new ActiveDataProvider([ 'query' => $query, + 'pagination' => [ + 'pageSize' => \Yii::$app->session['pageSize'] ?? 20, + ], ]); $dataProvider->setSort([ @@ -147,9 +189,11 @@ class ItemsSearch extends Items 'id' => $this->id, ])->andFilterWhere([ 'ilike', Status::tableName() . '.name', $this->statusName -// ])->andFilterWhere([ -// 'ilike', Models::tableName() . '.name', $this->modelName - ])->andFilterWhere([ + ])->andFilterWhere([ 'OR', [ + 'ilike', Models::tableName() . '.name', $this->modelName + ], [ + 'ilike', Items::tableName() . '.name', $this->modelName + ]])->andFilterWhere([ 'ilike', Types::tableName() . '.name', $this->typeName ])->andFilterWhere([ 'OR', [ 'ilike', Locations::tableName() . '.name', $this->regionName @@ -162,19 +206,16 @@ class ItemsSearch extends Items ]]); $query->andFilterWhere(['ilike', 'name', $this->name]) - ->andFilterWhere( ['ilike', 'model', $this->model]) ->andFilterWhere( ['ilike', 'os', $this->os]) ->andFilterWhere( ['ilike', 'mac', $this->mac]) ->andFilterWhere( ['ilike', 'serial', $this->serial]) - ->andFilterWhere( ['ilike', 'product', $this->product]) - ->andFilterWhere( ['ilike', 'modelnumber', $this->modelnumber]) ->andFilterWhere( ['ilike', 'invent', $this->invent]) ->andFilterWhere( ['ilike', 'comment', $this->comment]); -// $dataProvider->sort->attributes['modelName'] = [ -// 'asc' => [Models::tableName() . '.name' => SORT_ASC], -// 'desc' => [Models::tableName() . '.name' => SORT_DESC], -// ]; + $dataProvider->sort->attributes['modelName'] = [ + 'asc' => [Models::tableName() . '.name' => SORT_ASC], + 'desc' => [Models::tableName() . '.name' => SORT_DESC], + ]; $dataProvider->sort->attributes['statusName'] = [ 'asc' => [Status::tableName() . '.name' => SORT_ASC], 'desc' => [Status::tableName() . '.name' => SORT_DESC],