Exemplo n.º 1
0
 /**
  * Creates a new EventPost model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new EventPost();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionCreateEvent()
 {
     $user = User::findOne(Yii::$app->request->post('user_id'));
     if (!$user) {
         return json_encode(['success' => false, 'data' => ['User not found.']]);
     }
     $region = Region::findOne(Yii::$app->request->post('region_id'));
     if (!$region) {
         return json_encode(['success' => false, 'data' => ['Region not found.']]);
     }
     $genre = Genre::findOne(Yii::$app->request->post('genre_id'));
     if (!$genre) {
         return json_encode(['success' => false, 'data' => ['Genre not found.']]);
     }
     $start_date = new \DateTime(Yii::$app->request->post('start_date'));
     $end_date = new \DateTime(Yii::$app->request->post('end_date'));
     $event = new Event();
     $event->user_id = $user->id;
     $event->title = Yii::$app->request->post('title');
     $event->location = Yii::$app->request->post('location');
     $event->start_date = $start_date->format('Y-m-d H:i:s');
     $event->end_date = $end_date->format('Y-m-d H:i:s');
     $event->url = Yii::$app->request->post('url');
     $event->notes = Yii::$app->request->post('notes');
     $event->image = Yii::$app->request->post('image');
     $event->visibility = Yii::$app->request->post('visibility');
     $event->region_id = $region->id;
     $event->genre_id = $genre->id;
     if ($event->save()) {
         if ($event->visibility == Event::VISIBILITY_PUBLIC) {
             $eventPost = new EventPost();
             $eventPost->event_id = $event->id;
             $eventPost->status = EventPost::STATUS_NEW;
             $eventPost->save();
         }
         return json_encode(['success' => true, 'data' => '']);
     } else {
         return json_encode(['success' => false, 'data' => $event->getErrors()]);
     }
 }