Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\controllers;
- use app\models\Timetable;
- use Yii;
- use app\models\Events;
- use app\models\EventsSearch;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- use yii\filters\VerbFilter;
- use yii2fullcalendar\models\Event;
- /**
- * EventsController implements the CRUD actions for Events model.
- */
- class EventsController extends Controller
- {
- /**
- * @inheritdoc
- */
- public function behaviors()
- {
- return [
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'delete' => ['POST'],
- ],
- ],
- ];
- }
- /**
- * Lists all Events models.
- * @return mixed
- */
- public function actionIndex()
- {
- $lessons = Events::find()->all();
- foreach ($lessons as $lesson)
- {
- $time = Timetable::findOne($lesson->timetable_id);
- $event = new Event();
- $event->id = $lesson->id;
- $event->title = $lesson->topic;
- $event->start = $lesson->date . 'T' . $time->start;
- $event->end = $lesson->date . 'T' . $time->finish;
- // $event->url = 'events/view?id=' . $event->id;
- $events[] = $event;
- }
- return $this->render('index', [
- 'events' => $events
- ]);
- }
- /**
- * Displays a single Events model.
- * @param integer $id
- * @return mixed
- */
- public function actionView($id)
- {
- return $this->render('view', [
- 'model' => $this->findModel($id),
- ]);
- }
- /**
- * Creates a new Events model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- * @param $date
- * @return mixed
- */
- public function actionCreate($date)
- {
- $model = new Events();
- $model->date = $date;
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['index']);
- } else {
- return $this->renderAjax('create', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * Updates an existing Events model.
- * If update is successful, the browser will be redirected to the 'view' page.
- * @param integer $id
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['view', 'id' => $model->id]);
- } else {
- return $this->renderAjax('update', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * Deletes an existing Events model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- * @param integer $id
- * @return mixed
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- /**
- * Finds the Events model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- * @param integer $id
- * @return Events the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- protected function findModel($id)
- {
- if (($model = Events::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement