/** * Editar descuento existente * @return bool */ public function editar() { $idUsuario = Yii::$app->user->getId(); if ($this->validate()) { $model = $this->descuento; $model->nombre = ucfirst($this->nombre); $model->estado = $this->estado; $model->descripcion = ucfirst($this->descripcion); $model->categoria = $this->categoria; $model->precio = $this->precio; $model->transacciones = is_array($this->transacciones) ? implode(',', $this->transacciones) : descuentos::NO_ESPECIFICADO; // //$archivo = new Archivos(); if ($model->update(false)) { if (!empty($this->imagenes)) { foreach ($this->imagenes as $key => $file) { $file = (object) $file; // the path to save file, you can set an uploadPath $nombre = ImagenHelper::obtenerNombreArchivo(['usuario' => $idUsuario, 'articulo' => $model->iddescuento, 'imagen' => $file->name]); $archivo = new Archivos(); $archivo->usuario = $idUsuario; $archivo->descuento = $model->iddescuento; $archivo->nombre = $nombre; $archivo->tipo = $file->type; $archivo->peso = $file->size; $archivo->fechacreado = MetodosHelper::fechaHoy(); //guardamos la imagen principal $archivo->principal = count($this->imagenes) == 1 || $key == $this->principal ? 1 : 0; if ($archivo->save()) { file_put_contents(ImagenHelper::rutaImagenesdescuentos() . $nombre, base64_decode($file->base64)); ImagenHelper::guardarImagenSize($nombre, 'descuentos'); } } } return true; } else { return false; } } return false; }
public function galeriaAction($producto_id) { if ($this->request->hasFiles() == true) { foreach ($this->request->getUploadedFiles() as $file) { //Move the file into the application $carpeta = "file/productos/"; $path = $carpeta . date("Ymd_his") . $file->getName(); if ($file->moveTo($path)) { $resul3 = new Archivos(); $resul3->producto_id = $producto_id; $resul3->tipo_archivo = $file->getType(); $resul3->nombre_archivo = date("Ymd_his") . $file->getName(); $resul3->carpeta = $carpeta; $resul3->tamanio = $file->getSize(); $resul3->usuario_reg = $this->_user->id; $resul3->fecha_reg = date("Y-m-d h:i:s"); $resul3->estado = 0; $resul3->baja_logica = 1; $resul3->tabla = 1; if ($resul3->save()) { $this->flashSession->success("Exito: Registro guardado correctamente..."); } else { $this->flashSession->error("Error: no se a guardado el registro..."); } } else { die("Acurrio algun error."); } } } $this->assets->addCss('/assets/css/widget_galeria.css')->addCss('/js/fileinput/css/fileinput.min.css'); $this->assets->addJs('/assets/js/app.js')->addJs('/assets/js/plugins.js')->addJs('/scripts/productos/galeria.js')->addJs('/js/fileinput/js/fileinput.min.js')->addJs('/js/fileinput/js/fileinput_locale_es.js'); $resul = Productos::findFirstById($producto_id); $this->view->setVar('producto', $resul); $archivo = Archivos::find(array("baja_logica=1 and producto_id='{$producto_id}'")); $this->view->setVar('archivo', $archivo); // $this->view->setVar('producto_id', $producto_id); }
public function logoaddAction() { if ($this->request->hasFiles() == true) { foreach ($this->request->getUploadedFiles() as $file) { //Move the file into the application $carpeta = "file/clientes/"; $path = $carpeta . date("Ymd_his") . $file->getName(); if ($file->moveTo($path)) { $model = new Archivos(); $resul = $model->deleteImagenCliente($this->request->getPost('cliente_id')); $resul3 = new Archivos(); $resul3->producto_id = $this->request->getPost('cliente_id'); $resul3->tipo_archivo = $file->getType(); $resul3->nombre_archivo = date("Ymd_his") . $file->getName(); $resul3->carpeta = $carpeta; $resul3->tamanio = $file->getSize(); $resul3->usuario_reg = $this->_user->id; $resul3->fecha_reg = date("Y-m-d h:i:s"); $resul3->estado = 1; $resul3->baja_logica = 1; $resul3->tabla = 2; if ($resul3->save()) { $this->flashSession->success("Exito: Registro guardado correctamente..."); } else { $this->flashSession->error("Error: no se a guardado el registro..."); } } else { die("Acurrio algun error."); } } } $this->response->redirect('/clientes/view/' . $this->request->getPost('cliente_id')); }