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