protected function findModel($id) { if (($model = Shift::find()->where(['id' => $id])->with('participants')->one()) !== 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 = Shift::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'team_id' => $this->team_id, 'length' => $this->length, 'start_time' => $this->start_time, 'participant_num' => $this->participant_num, 'active' => $this->active, 'requirement_id' => $this->requirement_id]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Displays a single Team model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); $event = $model->event; $start = new MDateTime($event->start, new \DateTimeZone('EST5EDT')); $start->subToStart('D'); $days = []; while ($start->timestamp < $event->end) { $days[$start->timestamp] = $model->getDayDataProvider($start->timestamp); $start->add(new \DateInterval('P1D')); } $dp = new ActiveDataProvider(['query' => Shift::find()->where(['team_id' => $id]), 'pagination' => false]); $shift = new Shift(); $shift->team_id = $model->id; $shift->active = true; if ($shift->load(Yii::$app->request->post())) { $shift->save(); } $requirements = Requirement::find()->orderBy('name ASC')->all(); $event = $model->event; return $this->render('view', ['model' => $model, 'shift' => $shift, 'event' => $event, 'dataProvider' => $dp, 'days' => $days, 'requirements' => $requirements]); }
public function getScheduleDataProvider() { return new ActiveDataProvider(['query' => Shift::find()->joinWith(['team', 'participants.user'])->where(['shift.team_id' => $this->id])->orderBy(['start_time' => SORT_ASC, 'title' => SORT_ASC]), 'pagination' => false, 'sort' => false]); }