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
 /**
  * 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.');
     }
 }
Beispiel #3
0
 public function getStock($id)
 {
     return StockModel::findOne($id);
 }
Beispiel #4
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();
 }