Ejemplo n.º 1
0
 /**
  * Creates a new ItemProgramacao model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->validaAjax();
     $this->autorizaUsuario(Yii::$app->request->get('idevento'));
     $model = new ItemProgramacao();
     $model->notificacao = '1';
     $model->evento_idevento = Yii::$app->request->get('idevento');
     $model->data = filter_input(INPUT_GET, 'data');
     $model->hora = filter_input(INPUT_GET, 'hora');
     $model->horaFim = filter_input(INPUT_GET, 'horafim');
     if ($model->horaFim == null) {
         $model->horaFim = date('H:i', strtotime('+2 hour', strtotime($model->hora)));
     }
     if (!($model->tipo_idtipo = filter_input(INPUT_GET, 'tipo'))) {
         if ($tipo = filter_input(INPUT_GET, 'titulo')) {
             $arrayTipo = ArrayHelper::map(Tipo::find()->all(), 'idtipo', 'titulo');
             $model->tipo_idtipo = array_search($tipo, $arrayTipo);
         } else {
             return $this->redirect(['index', 'idevento' => $model->evento_idevento]);
         }
     }
     $arrayPalestrante = ArrayHelper::map(Palestrante::find()->all(), 'idPalestrante', 'nome');
     $arrayLocal = ArrayHelper::map(Local::find()->all(), 'idlocal', 'descricao');
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $this->mensagens('success', "Item '" . $model->titulo . "' foi Adicionado", 'O Item de Programação foi adicionado com sucesso');
             return $this->redirect(['index', 'idevento' => $model->evento_idevento]);
         } else {
             $this->mensagens('danger', "Item '" . $model->titulo . "' Não Adicionado", 'Houve um erro ao adicionar Item de Programacão. Verifique os dados informados e tente novamente');
             return $this->redirect(['index', 'idevento' => $model->evento_idevento]);
         }
     } else {
         return $this->renderAjax('create', ['model' => $model, 'arrayLocal' => $arrayLocal, 'arrayPalestrante' => $arrayPalestrante]);
     }
 }