/**
  * Creates a new Ocorrencia model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreatefromdenuncia($idDenuncia)
 {
     $model = new Ocorrencia();
     $denuncia = Denuncia::findOne($idDenuncia);
     $model->detalheLocal = $denuncia->detalheLocal;
     $model->data = $denuncia->data;
     $model->hora = $denuncia->hora;
     $model->descricao = $denuncia->descricao;
     $model->idLocal = $denuncia->idLocal;
     $model->idSubLocal = $denuncia->idSubLocalbkp;
     $sublocal = Sublocal::findOne($denuncia->idSubLocalbkp);
     $model->idLocal = $sublocal->idLocalbkp;
     $model->periodo = $denuncia->periodo;
     $model->comentarioFoto = $denuncia->comentarioFoto;
     if (strcmp($model->periodo, 'Manhã') == 0) {
         $model->periodo = 1;
     } elseif (strcmp($model->periodo, 'Tarde') == 0) {
         $model->periodo = 2;
     } elseif (strcmp($model->periodo, 'Noite') == 0) {
         $model->periodo = 3;
     } elseif (strcmp($model->periodo, 'Madrugada') == 0) {
         $model->periodo = 4;
     }
     if ($model->load(Yii::$app->request->post())) {
         list($dia, $mes, $ano) = split('[/]', $model->data);
         $model->data = $ano . '-' . $mes . '-' . $dia;
         if ($model->dataConclusao != null) {
             list($dia, $mes, $ano) = split('[/]', $model->dataConclusao);
             $model->dataConclusao = $ano . '-' . $mes . '-' . $dia;
         }
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         $path = Yii::$app->basePath . '/web/uploadFoto/';
         $model->cpfUsuario = Yii::$app->user->identity->cpf;
         if ($model->save()) {
             //         if (count ($model->imageFiles) >= 1) {
             foreach ($model->imageFiles as $file) {
                 $foto = new Foto();
                 $foto->idOcorrencia = $model->idOcorrencia;
                 $foto->comentario = $model->comentarioFoto;
                 $foto->endereco = $path . $file->baseName . '.' . $file->extension;
                 $foto->nome = $file->baseName . '.' . $file->extension;
                 $file->saveAs($foto->endereco);
                 $foto->save();
                 $foto = null;
             }
             $foto = FotoController::getFotoDenuncia($denuncia->idDenuncia);
             foreach ($foto as $file) {
                 $file->idOcorrencia = $model->idOcorrencia;
                 $file->save();
             }
             //   }
             return $this->redirect(['view', 'id' => $model->idOcorrencia]);
         } else {
             return $this->render('createdenuncia', ['model' => $model]);
         }
     } else {
         return $this->render('createdenuncia', ['model' => $model]);
     }
 }
 /**
  * Finds the Denuncia model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Denuncia the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Denuncia::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }