/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Ocorrencia();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Ocorrencia'])) {
         $model->attributes = $_POST['Ocorrencia'];
         $model->usuario_id = Yii::app()->user->objeto->id;
         $model->solicitacao = $_POST['solicitacao'];
         if ($model->save()) {
             $tiposSelecionados = $_POST['tipo'];
         }
         $peso = '';
         foreach ($tiposSelecionados as $tipo) {
             $x = new OcorrenciaTipo();
             $x->ocorrencia_id = $model->id;
             $x->tipo_id = $tipo;
             $peso += $tipo;
             $x->save();
         }
         $y = Ocorrencia::model()->findByPk($model->id);
         $y->prioridade = $peso;
         $y->save();
         $this->redirect(array('view', 'id' => $model->id));
     }
     $tipo = Tipo::model()->findAll();
     $this->render('create', array('model' => $model, 'tipo' => $tipo));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new OcorrenciaTipo();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['OcorrenciaTipo'])) {
         $model->attributes = $_POST['OcorrenciaTipo'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }