예제 #1
0
 public function run($slug)
 {
     /**
      * @var Person  $bride
      * @var Wedding $wedding
      */
     $personBySlug = PersonRepository::getBySlug($slug);
     $bride = CommandBusList::getPersonCommanBus()->handle(new GetCurrentPersonCommand());
     $wedding = WeddingRepository::getByBride($personBySlug);
     $groom = PersonRepository::getById($wedding->groomId());
     $isOwner = $bride->equalsTo($personBySlug);
     return $this->controller->render($bride->user()->type()->prefix() . '/index', ['bride' => $personBySlug, 'wedding' => $wedding, 'groom' => $groom, 'isOwner' => $isOwner]);
 }
예제 #2
0
 public function run()
 {
     /**
      * @var Person $bride
      */
     $bride = $this->getPersonCommandBus()->handle(new GetCurrentPersonCommand());
     $wedding = WeddingRepository::getByBride($bride);
     $cabinetURL = URL::toRoute('/cabinet/' . $bride->user()->slug());
     if ($wedding instanceof Wedding) {
         \Yii::$app->response->redirect($cabinetURL);
         \Yii::$app->end();
     }
     $weddingForm = new WeddingForm();
     if ($weddingForm->load(\Yii::$app->getRequest()->post()) && $weddingForm->validate()) {
         $transaction = \Yii::$app->getDb()->beginTransaction();
         $groom = $this->getPersonCommandBus()->handle(new CreatePersonCommand($weddingForm->groomFirstName(), $weddingForm->groomLastName()));
         $this->getWeddingCommandBus()->handle(new CreateWeddingCommand($groom, $bride, $weddingForm->date()));
         $transaction->commit();
         \Yii::$app->response->redirect($cabinetURL);
         \Yii::$app->end();
     }
     return $this->controller->render('wedding', ['weddingForm' => $weddingForm]);
 }