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.');
     }
 }
 protected function isEventActive($shift_id)
 {
     if (($model = Shift::findOne($shift_id)) !== null) {
         return $model->team->event->active;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function addUser()
 {
     if (!$this->validate()) {
         return false;
     }
     if (Shift::findOne($this->shift_id === null) || User::findOne($this->user_id == null)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $participant = new Participant();
     $participant->shift_id = $this->shift_id;
     $participant->user_id = $this->user_id;
     return $participant->save();
 }
 /**
  * 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]);
 }
 /**
  * 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;
 }
 /**
  * Finds the Shift model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Shift the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Shift::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 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]);
 }
 public function getShift()
 {
     return $this->hasOne(Shift::className(), ['id' => 'shift_id']);
 }