/**
  * 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));
 }
 public function store()
 {
     $post = Input::all();
     if (isset($post['id']) && $post['id'] !== '') {
         $model = Ocorrencia::find($post['id']);
     } else {
         $model = new Ocorrencia();
     }
     $model->aluno_id = Aluno::whereNome($post['aluno_id'])->first()->matricula;
     $model->descricao = $post['descricao'];
     $model->usuario_id = Auth::user()->ni;
     if ($model->save()) {
         return Redirect::to('/aluno/' . $model->aluno_id)->withSuccess('Ocorrência cadastrada com sucesso!');
     }
 }