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; }
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(); }
public function getStock($id) { return StockModel::findOne($id); }
/** * Finds the Stock model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Stock the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Stock::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }