Beispiel #1
0
 public function search($params)
 {
     $query = Stock::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new \yii\data\Sort(['attributes' => ['name', 'id']])]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'address', $this->address]);
     return $dataProvider;
 }
Beispiel #2
0
 public static function getAvailable($userId = null)
 {
     $userId = $userId ? $userId : \Yii::$app->user->id;
     $stockIds = StockToUser::find()->where(['user_id' => $userId])->all();
     $stockIds = ArrayHelper::getColumn($stockIds, 'user_id');
     return Stock::find()->where(['id' => $stockIds])->all();
 }