예제 #1
0
 /**
  * Creates a new Foto model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Foto();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->idFoto]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Foto model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Foto();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $imageName = $model->titutlo;
         $model->file = UploadedFile::getInstance($model, 'file');
         $model->file->saveAS('uploads/' . $imageName . '.' . $model->file->extension);
         $model->link = 'uploads/' . $model->titutlo . '.' . $model->file->extension;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id_foto]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function save($runValidation = true, $attributeNames = null)
 {
     if (parent::save($runValidation, $attributeNames)) {
         //dopo aver salvato le modifiche, processa gli upload delle foto
         foreach ($this->addimage as $tmpfoto) {
             $foto = new Foto();
             $foto->cartellone = $this->id;
             $foto->tmpname = $tmpfoto;
             $foto->save();
         }
         return true;
     }
     return false;
 }
예제 #4
0
파일: Fotos.php 프로젝트: safaricco/admfw
 public function store(Request $request)
 {
     $validation = Validator::make($request->all(), ['titulo' => 'required|string', 'texto' => 'required|string', 'imagens[]' => 'image|mimes:jpeg,bmp,png,jpg']);
     if ($validation->fails()) {
         return redirect('admin/fotos/novo')->withErrors($validation)->withInput();
     } else {
         try {
             $foto = new Foto();
             $foto->titulo = $request->titulo;
             $foto->texto = $request->texto;
             $foto->data = date('Y-m-d');
             $foto->save();
             if ($request->hasFile('imagens')) {
                 Midia::uploadMultiplo($this->tipo_midia, $foto->id_foto);
             }
             session()->flash('flash_message', 'Galerias cadastrada com sucesso!');
         } catch (\Exception $e) {
             LogR::exception($foto, $e);
             session()->flash('flash_message', 'Ops!! Ocorreu algum problema!. ' . $e->getMessage());
         }
         return Redirect::back();
     }
 }
예제 #5
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(FotoRequest $request, $id = null)
 {
     //
     $besar = public_path('upload/besar');
     $kecil = public_path('upload/kecil');
     $input = $request->except('file');
     $data = json_decode($input['data']);
     if (isset($data->id_foto)) {
         $foto = Foto::find($data->id_foto);
         $foto->id_album = $data->id_album;
         if ($request->hasFile('file')) {
             $checkfile = file_exists(public_path('upload/besar/' . $foto->foto_besar));
             $checkfile2 = file_exists(public_path('upload/kecil/' . $foto->foto_kecil));
             if ($checkfile) {
                 unlink(public_path('upload/kecil/' . $foto->foto_kecil));
             }
             if ($checkfile2) {
                 unlink(public_path('upload/besar/' . $foto->foto_besar));
             }
             $foto->foto_besar = Str::random(30) . '.' . $request->file('file')->getClientOriginalExtension();
             $foto->foto_kecil = Str::random(30) . '.' . $request->file('file')->getClientOriginalExtension();
             $request->file('file')->move($besar, $foto->foto_besar);
             // Resize Image Besar
             $img_besar = Image::make(public_path('upload/besar/' . $foto->foto_besar))->resize(800, 600)->save($besar . '/' . $foto->foto_besar);
             // Upload dan Resize Image Besar Ke Image Kecil
             $img_kecil = Image::make(public_path('upload/besar/' . $foto->foto_besar))->resize(300, 200)->save($kecil . '/' . $foto->foto_kecil);
         }
     } else {
         $foto = new Foto();
         $foto->id_album = $input['data'];
         if ($request->hasFile('file')) {
             $foto->foto_besar = Str::random(30) . '.' . $request->file('file')->getClientOriginalExtension();
             $foto->foto_kecil = Str::random(30) . '.' . $request->file('file')->getClientOriginalExtension();
             $request->file('file')->move($besar, $foto->foto_besar);
             // Resize Image Besar
             $foto_besar = Image::make(public_path('upload/besar/' . $foto->foto_besar))->resize(800, 600)->save($besar . '/' . $foto->foto_besar);
             $foto_kecil = Image::make(public_path('upload/besar/' . $foto->foto_besar))->resize(300, 200)->save($kecil . '/' . $foto->foto_kecil);
         }
     }
     if ($foto->save()) {
         return response()->json(array('success' => TRUE));
     } else {
         return 1;
     }
 }
예제 #6
0
 /**
  * Creates a new Denuncia model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Denuncia();
     $model->idLocal = 0;
     if ($model->load(Yii::$app->request->post())) {
         list($dia, $mes, $ano) = split('[/]', $model->data);
         $model->data = $ano . '-' . $mes . '-' . $dia;
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         $path = Yii::$app->basePath . '/web/uploadFoto/';
         $model->status = 1;
         if ($model->save()) {
             foreach ($model->imageFiles as $file) {
                 $foto = new Foto();
                 $foto->idDenuncia = $model->idDenuncia;
                 $foto->endereco = $path . $file->baseName . '.' . $file->extension;
                 $foto->nome = $file->baseName . '.' . $file->extension;
                 $foto->comentario = $model->comentarioFoto;
                 $file->saveAs($foto->endereco);
                 $foto->save();
                 $foto = null;
             }
             return $this->render('sucesso');
         } else {
             list($ano, $mes, $dia) = split('[-]', $model->data);
             $model->data = $dia . '/' . $mes . '/' . $ano;
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #7
0
 /**
  * Updates an existing Ocorrencia model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if (strcmp($model->status, 'Aberto') == 0) {
         $model->status = 1;
     } elseif (strcmp($model->status, 'Solucionado') == 0) {
         $model->status = 2;
     } elseif (strcmp($model->status, 'Não Solucionado') == 0) {
         $model->status = 3;
     }
     $model->idNatureza = $model->idNaturezabkp;
     $model->idSubLocal = $model->idSubLocalbkp;
     $model->idCategoria = $model->idCategoriabkp;
     $model->cpfUsuario = Yii::$app->user->identity->cpf;
     $sublocal = Sublocal::findOne($model->idSubLocalbkp);
     $model->idLocal = $sublocal->idLocalbkp;
     if ($model->load(Yii::$app->request->post())) {
         $model->imageFiles = UploadedFile::getInstances($model, 'imageFiles');
         $path = Yii::$app->basePath . '/web/uploadFoto/';
         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;
         }
         if ($model->save()) {
             //     	if (count ($model->imageFiles) >= 1) {
             if ($model->comentarioFoto != null) {
                 $foto = FotoController::getFotoOcorrencia($model->idOcorrencia);
                 foreach ($foto as $file) {
                     $file->comentario = $model->comentarioFoto;
                     $file->save();
                 }
             }
             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;
             }
             //             }
             return $this->redirect(['view', 'id' => $model->idOcorrencia]);
         } else {
             list($ano, $mes, $dia) = split('[-]', $model->data);
             $model->data = $dia . '/' . $mes . '/' . $ano;
             if ($model->dataConclusao != null) {
                 list($ano, $mes, $dia) = split('[-]', $model->dataConclusao);
                 $model->dataConclusao = $dia . '/' . $mes . '/' . $ano;
             }
             return $this->render('update', ['model' => $model]);
             //  echo "error da foto em".$image->error;
         }
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }