Advertisement
Guest User

EventsController

a guest
May 31st, 2016
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.28 KB | None | 0 0
  1.     public function actionIndex()
  2.     {
  3.         $lessons = Events::find()->all();
  4.  
  5.         foreach ($lessons as $lesson)
  6.         {
  7.                 $time = Timetable::findOne($lesson->timetable_id);
  8.  
  9.                 $event = new Event();
  10.                 $event->id = $lesson->id;
  11.                 $event->title = $lesson->topic;
  12.                 $event->start = $lesson->date . 'T' . $time->start;
  13.                 $event->end = $lesson->date . 'T' . $time->finish;
  14.                 $events[] = $event;
  15.         }
  16.  
  17.         return $this->render('index', [
  18.             'events' => $events
  19.         ]);
  20.     }
  21.  
  22.     /**
  23.      * Displays a single Events model.
  24.      * @param integer $id
  25.      * @return mixed
  26.      */
  27.     public function actionView($id)
  28.     {
  29.         return $this->renderAjax('view', [
  30.             'model' => $this->findModel($id),
  31.         ]);
  32.     }
  33.  
  34.     /**
  35.      * Creates a new Events model.
  36.      * If creation is successful, the browser will be redirected to the 'view' page.
  37.      * @param $date
  38.      * @return mixed
  39.      */
  40.     public function actionCreate($date)
  41.     {
  42.         $model = new Events();
  43.         $model->date = $date;
  44.  
  45.         if ($model->load(Yii::$app->request->post()) && $model->save()) {
  46.             return $this->redirect(['/events']);
  47.         } else {
  48.             return $this->renderAjax('create', [
  49.                 'model' => $model,
  50.             ]);
  51.         }
  52.     }
  53.  
  54.     /**
  55.      * Updates an existing Events model.
  56.      * If update is successful, the browser will be redirected to the 'view' page.
  57.      * @param integer $id
  58.      * @return mixed
  59.      */
  60.     public function actionUpdate($id)
  61.     {
  62.         $model = $this->findModel($id);
  63.  
  64.         if ($model->load(Yii::$app->request->post()) && $model->save()) {
  65.             return $this->redirect('/web/events');
  66.         } else {
  67.             return $this->renderAjax('update', [
  68.                 'model' => $model,
  69.             ]);
  70.         }
  71.     }
  72.  
  73.     /**
  74.      * Deletes an existing Events model.
  75.      * If deletion is successful, the browser will be redirected to the 'index' page.
  76.      * @param integer $id
  77.      * @return mixed
  78.      */
  79.     public function actionDelete($id)
  80.     {
  81.         $this->findModel($id)->delete();
  82.  
  83.         return $this->redirect(['/events']);
  84.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement