public function store() { // Save visitor event information to database $event = new Calendar(); $event->category = Input::get('category'); $event->event = Input::get('event'); $event->mont = Input::get('month1'); $event->mont2 = Input::get('month2'); $event->da = Input::get('da'); $event->da2 = Input::get('da2'); $event->hour = Input::get('hour'); $event->minute = Input::get('minute'); //$event->address = Input::get('address'); $event->state = Input::get('state'); //$event->zip = Input::get('zip'); $event->phone = Input::get('phone'); $event->pending = "true"; if ($event->save()) { /* Email admin notice of new event pending approval Mail::send('emails.new-event', ['event' => $event], function ($m) use ($event) { $m->to('*****@*****.**', 'Bobby')->subject('New Pending Event!'); }); */ Mail::raw('test mail', function ($m) { $m->from('*****@*****.**', 'Admin')->to('*****@*****.**', 'test name')->subject('test mail'); }); return Redirect::to('/calendar/'); return Redirect('/calendar/'); } else { return View::make('/calendar/add', ['error' => 'Unable to save event. Please try again later or contact system administrator!']); } }
/** * Creates a new Calendar model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Calendar(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Family(); if ($model->load(Yii::$app->request->post())) { //Se o utilizador já tiver uma familia não faz nada if (Yii::$app->user->identity->family_id) { return $this->redirect('update'); } $model->login_status = \app\enum\UserStatus::Inativo; //$model->accepts_members = 0 ; if ($model->validate() && $model->save()) { $user = Yii::$app->user->identity; //inicia transação $transaction = Yii::$app->db->beginTransaction(); //Cria membro $fme = new FamilyMember(); $fme->family_id = $model->id; $fme->user_id = Yii::$app->user->getId(); $fme->name = $user->username; $fme->event_color = '#ff9900'; $fme->user_type = \app\enum\UserType::Administrador_MemoBoard; if (!$fme->save()) { $transaction->rollBack(); return $this->goHome(); } //Cria um calendário para o membro $cal = new Calendar(); $cal->sistem = 0; $cal->name = Yii::$app->user->identity->username; $cal->member_id = $fme->id; if (!$cal->save()) { $transaction->rollBack(); return $this->goHome(); } $user->family_id = $model->id; $user->calendar_id = $cal->id; $user->family_member_id = $fme->id; if (!$user->save()) { $transaction->rollBack(); return $this->goHome(); } //Finaliza transação $transaction->commit(); return $this->redirect('update'); } } return $this->render('create', ['model' => $model]); }