/**
  * 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));
 }
 /**
  * Vista para la informacion cuando se requiera exportar
  */
 public function actionInformacion()
 {
     if (!Yii::app()->user->isGuest) {
         $tipo = Tipo::model()->findAll();
         $tipos = '';
         $es_internacional = "'No' => 0 <br> 'Sí' => 1";
         $sect = Sector::model()->findAll();
         $sectores = '';
         $est = Estado::model()->findAll();
         $estados = '';
         $pais = Paises::model()->findAll();
         $paises = '';
         $tipo_m = TipoMedios::model()->findAll();
         $tipo_medios = '';
         $grupo = Grupos::model()->findAll();
         $grupos = '';
         $usuario = Usuarios::model()->findAll();
         $usuarios = '';
         $es_internacional = "'No' => 0 <br> 'Sí' => 1";
         foreach ($tipo as $t) {
             $tipos .= "'" . $t->nombre . "' => " . $t->id . " <br>";
         }
         foreach ($sect as $s) {
             $sectores .= "'" . $s->nombre . "' => " . $s->id . " <br>";
         }
         foreach ($usuario as $u) {
             $usuarios .= "'" . $u->nombre . ' ' . $u->apellido . "' => " . $u->id . " <br>";
         }
         foreach ($est as $e) {
             $estados .= "'" . $e->nombre . "' => " . $e->id . " <br>";
         }
         foreach ($pais as $p) {
             $paises .= "'" . $p->nombre . "' => " . $p->id . " <br>";
         }
         foreach ($tipo_m as $tm) {
             $tipo_medios .= "'" . $tm->nombre . "' => " . $tm->id . " <br>";
         }
         foreach ($grupo as $g) {
             $grupos .= "'" . $g->nombre . "' => " . $g->id . " <br>";
         }
         $datos = array('es_internacional' => $es_internacional, 'tipos' => $tipos, 'sectores' => $sectores, 'usuarios' => $usuarios, 'estados' => $estados, 'paises' => $paises, 'tipo_medios' => $tipo_medios, 'grupos' => $grupos);
         $this->render('informacion', array('datos' => $datos));
     } else {
         $this->redirect(Yii::app()->homeUrl);
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Tipo::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }