Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\controllers;
- use app\models\Events;
- use app\models\SignupForm;
- use Yii;
- use yii\filters\AccessControl;
- use yii\web\Controller;
- use yii\web\Response;
- use yii\filters\VerbFilter;
- use app\models\LoginForm;
- use app\models\ContactForm;
- class SiteController extends Controller
- {
- /**
- * {@inheritdoc}
- */
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'only' => ['logout', 'index'],
- 'rules' => [
- [
- 'actions' => ['logout', 'index'],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- 'verbs' => [
- 'class' => VerbFilter::className(),
- 'actions' => [
- 'logout' => ['post'],
- ],
- ],
- ];
- }
- /**
- * {@inheritdoc}
- */
- public function actions()
- {
- return [
- 'error' => [
- 'class' => 'yii\web\ErrorAction',
- ],
- 'captcha' => [
- 'class' => 'yii\captcha\CaptchaAction',
- 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
- ],
- ];
- }
- /**
- * Displays homepage.
- *
- * @return string
- */
- public function actionIndex()
- {
- return $this->render('index');
- }
- /**
- * Login action.
- *
- * @return Response|string
- */
- public function actionLogin()
- {
- if (!Yii::$app->user->isGuest) {
- return $this->goHome();
- }
- $model = new LoginForm();
- if ($model->load(Yii::$app->request->post()) && $model->login()) {
- return $this->goBack();
- }
- $model->password = '';
- return $this->render('login', [
- 'model' => $model,
- ]);
- }
- public function actionSignup()
- {
- $model = new SignupForm();
- if ($model->load(Yii::$app->request->post())) {
- if ($user = $model->signup()) {
- if (Yii::$app->getUser()->login($user)) {
- return $this->goHome();
- }
- }
- }
- return $this->render('signup', [
- 'model' => $model,
- ]);
- }
- /**
- * Logout action.
- *
- * @return Response
- */
- public function actionLogout()
- {
- Yii::$app->user->logout();
- return $this->goHome();
- }
- public function actionJsoncalendar($start = null, $end = null, $_ = null)
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $eventModels = Events::find()->where(['user_id' => Yii::$app->user->id])->all();
- $events = [];
- foreach ($eventModels as $eventModel) {
- $Event = new \yii2fullcalendar\models\Event();
- $Event->id = $eventModel->id;
- $Event->title = $eventModel->title;
- $Event->start = $eventModel->start;
- $Event->end = $eventModel->end;
- $events[] = $Event;
- }
- return $events;
- }
- public function actionAddEvent($title = '', $start = '', $end = '')
- {
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $event = new Events();
- $event->title = $title;
- $event->start = $start;
- $event->user_id = (string)Yii::$app->user->id;
- $event->end = $end;
- if (!$event->save()) {
- return $event->getErrors();
- }
- return $event->id;
- }
- public function actionChangeEvent($title = '', $id = '', $start = '', $end = '')
- {
- If (!$id) {
- return '';
- }
- $event = Events::findOne($id);
- If (!$event) {
- return '';
- }
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- $event->title = $title ? $title : $event->title;
- $event->start = $start ? $start : $event->start;
- $event->end = $end ? $end : $event->end;
- if (!$event->update()) {
- return $event->getErrors();
- }
- }
- public function actionDeleteEvent($id = '')
- {
- If (!$id) {
- return '';
- }
- $event = Events::findOne($id);
- If (!$event) {
- return '';
- }
- \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- if (!$event->delete()) {
- return $event->getErrors();
- }
- }
- }
Add Comment
Please, Sign In to add comment