/** * Finds the WeekStats model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return WeekStats the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = WeekStats::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = WeekStats::find(); if (!Yii::$app->request->isConsoleRequest) { $query->where(['user_id' => Yii::$app->user->id]); } if (!isset($params['sort'])) { $query->orderBy('end_date DESC, weighing_day'); } $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['start_date' => $this->startDate, 'end_date' => $this->endDate, 'weight' => $this->weight, 'calories' => $this->calories, 'average_weight' => $this->averageWeight, 'average_calories' => $this->averageCalories, 'body_weight' => $this->bodyWeight, 'weighing_day' => $this->weighingDay]); $dataProvider->sort = ['attributes' => ['startDate' => ['asc' => ['start_date' => SORT_ASC], 'desc' => ['start_date' => SORT_DESC]], 'endDate' => ['asc' => ['end_date' => SORT_ASC], 'desc' => ['end_date' => SORT_DESC]], 'calories', 'averageCalories' => ['asc' => ['average_calories' => SORT_ASC], 'desc' => ['average_calories' => SORT_DESC]], 'weighingDay' => ['asc' => ['weighing_day' => SORT_ASC], 'desc' => ['weighing_day' => SORT_DESC]], 'bodyWeight' => ['asc' => ['body_weight' => SORT_ASC], 'desc' => ['body_weight' => SORT_DESC]]]]; return $dataProvider; }
/** * @param array $params * @return ArrayDataProvider */ public function search($params = []) { $dataProvider = new ArrayDataProvider(['allModels' => $this->week->getDays(), 'sort' => ['attributes' => ['date', 'day', 'weight', 'calories'], 'defaultOrder' => ['date' => SORT_ASC]], 'pagination' => false]); return $dataProvider; }