Esempio n. 1
0
 public function editarbannerAction()
 {
     $auth = new \Zend\Authentication\AuthenticationService();
     if (!$auth->hasIdentity()) {
         return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/usuario/index/login');
     }
     $id = $this->params()->fromRoute('id');
     $menu = $this->getRestauranteTable()->buscarBanner($id)->toArray();
     $form = new BannerForm();
     $name = $menu[0]['va_imagen'];
     $form->get('in_id')->setValue($menu[0]['in_id']);
     $form->get('va_nombre')->setValue($menu[0]['va_nombre']);
     $form->get('in_orden')->setValue($menu[0]['in_orden']);
     $form->get('va_url')->setValue($menu[0]['va_url']);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $datos = $this->request->getPost();
         $resultado = $this->getRestauranteTable()->buscarBanner($datos->in_id)->toArray();
         $File = $this->params()->fromFiles('va_imagen');
         $form->setData($datos);
         if ($form->isValid()) {
             $valor = uniqid();
             $info = pathinfo($File['name']);
             if ($File['name'] == '') {
                 $this->getRestauranteTable()->editaBanner($datos, $resultado[0]['va_imagen']);
                 return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/restaurante/index/listadobanner');
             } else {
                 $eliminar = $this->_options->upload->images . '/banner/' . $resultado[0]['va_imagen'];
                 unlink($eliminar);
                 require './vendor/Classes/Filter/Alnum.php';
                 if ($info['extension'] == 'jpg' or $info['extension'] == 'JPG' or $info['extension'] == 'jpeg') {
                     $imf2 = $valor . '.' . $info['extension'];
                     $filter = new \Filter_Alnum();
                     $filtered = $filter->filter($datos->va_nombre);
                     $name = $filtered . '-' . $imf2;
                     $viejaimagen = imagecreatefromjpeg($File['tmp_name']);
                     $copia = $this->_options->upload->images . '/banner/' . $name;
                     imagejpeg($viejaimagen, $copia);
                 }
                 $this->getRestauranteTable()->editaBanner($datos, $name);
                 return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/restaurante/index/listadobanner');
             }
         }
     }
     return array('form' => $form);
 }
Esempio n. 2
0
 public function ingresardatosAction()
 {
     $view = new ViewModel();
     $this->layout()->clase = 'Solicita';
     $form = new Registro("form");
     $storage = new \Zend\Authentication\Storage\Session('Auth');
     $session = $storage->read();
     if (!isset($session)) {
         $url = '/solicita';
         $face = new \Usuario\Controller\ClientesController();
         $facebook = $face->facebook();
         $this->layout()->loginUrl = $facebook['loginUrl'];
         $this->layout()->user = $facebook['user'];
         if ($facebook['id_facebook']) {
             $id_face = $this->getClientesTable()->usuarioface($facebook['email']);
             if (count($id_face) > 0) {
                 if ($id_face[0]['id_facebook'] == '') {
                     $this->getClientesTable()->idfacebook($id_face[0]['in_id'], $facebook['id_facebook'], $facebook['logoutUrl']);
                     AuthController::sessionfacebook($facebook['email'], $facebook['id_facebook'], $url);
                 } else {
                     $this->getClientesTable()->idfacebook2($id_face[0]['in_id'], $facebook['logoutUrl']);
                     AuthController::sessionfacebook($facebook['email'], $facebook['id_facebook'], $url);
                 }
             } else {
                 $this->getClientesTable()->insertarusuariofacebbok($facebook['name'], $facebook['email'], $facebook['id_facebook'], $facebook['logoutUrl']);
                 AuthController::sessionfacebook($facebook['email'], $facebook['id_facebook'], $url);
             }
         }
     }
     $comidas = $this->comidas()->toArray();
     $com = array();
     foreach ($comidas as $y) {
         $com[$y['in_id']] = $y['va_nombre_tipo'];
     }
     $form->get('Ta_tipo_comida_in_id')->setValueOptions($com);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $datos = $this->request->getPost();
         // var_dump($datos->cantidad_platos);exit;
         $File = $this->params()->fromFiles('va_imagen');
         $form->setData($datos);
         if ($form->isValid()) {
             $valor = uniqid();
             $info = pathinfo($File['name']);
             require './vendor/Classes/Filter/Alnum.php';
             if ($info['extension'] == 'jpg' or $info['extension'] == 'JPG' or $info['extension'] == 'jpeg') {
                 $imf2 = $valor . '.' . $info['extension'];
                 $filter = new \Filter_Alnum();
                 $filtered = $filter->filter($datos->va_nombre_contacto);
                 $name = $filtered . '-' . $imf2;
                 $viejaimagen = imagecreatefromjpeg($File['tmp_name']);
                 $copia = $this->_options->upload->images . '/registro/restaurante/' . $name;
                 imagejpeg($viejaimagen, $copia);
             }
             $idrestaurante = $this->getConfigTable()->guardarregistro($datos, $name);
             $id = $idrestaurante;
             $this->flashMessenger()->addMessage('El restaurante ha sido registrado correctamente...');
             $this->redirect()->toUrl('/solicita?id=' . $id . '&plato=' . $datos->cantidad_platos);
         }
     }
     $flashMessenger = $this->flashMessenger();
     if ($flashMessenger->hasMessages()) {
         $mensajes = $flashMessenger->getMessages();
     }
     $formu = new Registroplato();
     $view->setVariables(array('form' => $form, 'formu' => $formu, 'mensaje' => $mensajes));
     return $view;
 }
Esempio n. 3
0
 public function editarplatosAction()
 {
     $auth = new \Zend\Authentication\AuthenticationService();
     if (!$auth->hasIdentity()) {
         return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/usuario/index/login');
     }
     $id = (int) $this->params()->fromRoute('in_id', 0);
     $platicos = $this->platicos($id)->toArray();
     $comeya = $platicos[0]['va_imagen'];
     $va_nombre = 'prueba';
     $idlocal = (int) $this->params()->fromRoute('id_pa', 0);
     if (!$id) {
         return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/restaurante/index/agregarrestaurante');
     }
     try {
         $restaurante = $this->getPlatosTable()->getPlato($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toUrl($this->getRequest()->getBaseUrl() . '/plato/listar');
     }
     $adpter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     $form = new PlatosForm($adpter, $idlocal);
     $form->get('va_imagen')->setValue($comeya);
     /////////////////////PROMOCIONES////////////////////
     // $form->get('Ta_tipo_plato_in_id')->setOptions(array($platotipo[0]['in_id'] =>$platotipo[0]['va_nombre']  ));
     $form->bind($restaurante);
     $promobind = $this->getPlatosTable()->promocionxPlato($id)->toArray();
     $aux = array();
     foreach ($promobind as $value) {
         $aux[$value['ta_tag_in_id']] = $value['ta_tag_in_id'];
         $form->get('va_promocion')->setAttribute('value', $aux);
     }
     /////////////////////////////////////////////////////////////////////////////////
     $form->get('submit')->setAttribute('value', 'MODIFICAR');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $promoc = $this->params()->fromPost('va_promocion');
         $datos = $this->request->getPost();
         $plato_otro = $datos['va_otros'];
         $form->setInputFilter($restaurante->getInputFilter());
         $nonFile = $request->getPost()->toArray();
         $File = $this->params()->fromFiles('va_imagen');
         $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
         $form->setData($data);
         if ($form->isValid()) {
             $nonFile = $request->getPost()->toArray();
             if ($File['name'] != '') {
                 $adapter = new \Zend\File\Transfer\Adapter\Http();
                 if (!$adapter->isValid()) {
                     $dataError = $adapter->getMessages();
                     $error = array();
                     foreach ($dataError as $key => $row) {
                         $error[] = $row;
                     }
                     $form->setMessages(array('imagen' => $error));
                 } else {
                     $restaura = $this->restaurante($idlocal);
                     $rowset = $restaura;
                     $array = array();
                     foreach ($rowset as $resul) {
                         $array[] = $resul;
                     }
                     $this->dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
                     $adapter = $this->dbAdapter;
                     $sql = new Sql($adapter);
                     $select = $sql->select()->from('ta_local')->join(array('tl' => 'ta_plato_has_ta_local'), 'ta_local.in_id = tl.Ta_local_in_id', array('cantidad' => new \Zend\Db\Sql\Expression('COUNT(tl.Ta_plato_in_id)')), 'left')->where(array('ta_local.in_id' => $idlocal))->group('ta_local.in_id');
                     $selectString = $sql->getSqlStringForSqlObject($select);
                     $results = $adapter->query($selectString, $adapter::QUERY_MODE_EXECUTE);
                     $plat = $results;
                     $platos = array();
                     foreach ($plat as $result) {
                         $platos[] = $result;
                     }
                     $anchura = 407;
                     $altura = 272;
                     $destacadox = 215;
                     $destacadoy = 155;
                     $generalx = 145;
                     $generaly = 112;
                     $imf = $File['name'];
                     $info = pathinfo($File['name']);
                     $tamanio = getimagesize($File['tmp_name']);
                     $ancho = $tamanio[0];
                     $alto = $tamanio[1];
                     $valor = uniqid();
                     $va = $this->getPlatosTable()->getPlato($id);
                     $imagen_antigua = $va->va_imagen;
                     if ($ancho > $alto) {
                         $eliminar = $this->_options->upload->images . '/plato/destacado/' . $imagen_antigua;
                         $eliminar1 = $this->_options->upload->images . '/plato/general/' . $imagen_antigua;
                         $eliminar2 = $this->_options->upload->images . '/plato/original/' . $imagen_antigua;
                         $eliminar3 = $this->_options->upload->images . '/plato/principal/' . $imagen_antigua;
                         unlink($eliminar);
                         unlink($eliminar1);
                         unlink($eliminar2);
                         unlink($eliminar3);
                         require './vendor/Classes/Filter/Alnum.php';
                         $alta = (int) ($alto * $anchura / $ancho);
                         if ($alta > 272) {
                             $altura = 272;
                         } else {
                             $altura = $alta;
                         }
                         if ($info['extension'] == 'jpg' or $info['extension'] == 'JPG' or $info['extension'] == 'jpeg') {
                             $nom = $nonFile['va_nombre'];
                             $imf2 = $valor . '.' . $info['extension'];
                             $filter = new \Filter_Alnum();
                             $filtered = $filter->filter($nom);
                             $name = $filtered . '-' . $imf2;
                             if (!is_dir($this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777)) {
                                 mkdir($this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 $principal = $this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                                 $destacado = $this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                                 $general = $this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                                 $original = $this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             }
                             $estampa = imagecreatefrompng($this->_options->upload->images . '/defecto/loguito.png');
                             $viejaimagen = imagecreatefromjpeg($File['tmp_name']);
                             $margen_dcho = 340;
                             $margen_inf = 20;
                             $sx = imagesx($estampa);
                             $sy = imagesy($estampa);
                             imagecopy($viejaimagen, $estampa, $sx, $alto - 100, 0, 0, imagesx($estampa), imagesy($estampa));
                             $nuevaimagen = imagecreatetruecolor($anchura, $altura);
                             $destaque = imagecreatetruecolor($destacadox, $destacadoy);
                             $generale = imagecreatetruecolor($generalx, $generaly);
                             imagecopyresized($nuevaimagen, $viejaimagen, 0, 0, 0, 0, $anchura, $altura, $ancho, $alto);
                             imagecopyresized($destaque, $viejaimagen, 0, 0, 0, 0, $destacadox, $destacadoy, $ancho, $alto);
                             imagecopyresized($generale, $viejaimagen, 0, 0, 0, 0, $generalx, $generaly, $ancho, $alto);
                             $principal = $this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $destacado = $this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $general = $this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $original = $this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             imagejpeg($nuevaimagen, $principal);
                             imagejpeg($destaque, $destacado);
                             imagejpeg($generale, $general);
                             imagejpeg($viejaimagen, $original);
                             $nombre = $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $this->getPlatosTable()->guardarPlato($restaurante, $nombre, $idlocal, $plato_otro, $promoc);
                             $this->redirect()->toUrl('/plato/listar?id=' . $idlocal);
                         }
                     }
                     if ($ancho < $alto) {
                         $eliminar = $this->_options->upload->images . '/plato/destacado/' . $imagen_antigua;
                         $eliminar1 = $this->_options->upload->images . '/plato/general/' . $imagen_antigua;
                         $eliminar2 = $this->_options->upload->images . '/plato/original/' . $imagen_antigua;
                         $eliminar3 = $this->_options->upload->images . '/plato/principal/' . $imagen_antigua;
                         unlink($eliminar);
                         unlink($eliminar1);
                         unlink($eliminar2);
                         unlink($eliminar3);
                         require './vendor/Classes/Filter/Alnum.php';
                         $anchu = (int) ($ancho * $altura / $alto);
                         if ($anchu > 407) {
                             $anchura = 407;
                         } else {
                             $anchura = $anchu;
                         }
                         if ($info['extension'] == 'jpg' or $info['extension'] == 'JPG' or $info['extension'] == 'jpeg') {
                             $nom = $nonFile['va_nombre'];
                             $imf2 = $valor . '.' . $info['extension'];
                             $filter = new \Filter_Alnum();
                             $filtered = $filter->filter($nom);
                             $name = $filtered . '-' . $imf2;
                             if (!is_dir($this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777)) {
                                 mkdir($this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 mkdir($this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/', 0777);
                                 $principal = $this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                                 $destacado = $this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                                 $general = $this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                                 $original = $this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             }
                             $estampa = imagecreatefrompng($this->_options->upload->images . '/defecto/loguito.png');
                             $viejaimagen = imagecreatefromjpeg($File['tmp_name']);
                             $margen_dcho = 340;
                             $margen_inf = 20;
                             $sx = imagesx($estampa);
                             $sy = imagesy($estampa);
                             imagecopy($viejaimagen, $estampa, $sx, $alto - 100, 0, 0, imagesx($estampa), imagesy($estampa));
                             $nuevaimagen = imagecreatetruecolor($anchura, $altura);
                             $destaque = imagecreatetruecolor($destacadox, $destacadoy);
                             $generale = imagecreatetruecolor($generalx, $generaly);
                             imagecopyresized($nuevaimagen, $viejaimagen, 0, 0, 0, 0, $anchura, $altura, $ancho, $alto);
                             imagecopyresized($destaque, $viejaimagen, 0, 0, 0, 0, $destacadox, $destacadoy, $ancho, $alto);
                             imagecopyresized($generale, $viejaimagen, 0, 0, 0, 0, $generalx, $generaly, $ancho, $alto);
                             $principal = $this->_options->upload->images . '/plato/principal/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $destacado = $this->_options->upload->images . '/plato/destacado/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $general = $this->_options->upload->images . '/plato/general/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $original = $this->_options->upload->images . '/plato/original/' . $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             imagejpeg($nuevaimagen, $principal);
                             imagejpeg($destaque, $destacado);
                             imagejpeg($generale, $general);
                             imagejpeg($viejaimagen, $original);
                             $nombre = $array[0]['Ta_restaurante_in_id'] . '/' . $idlocal . '/' . $name;
                             $this->getPlatosTable()->guardarPlato($restaurante, $nombre, $idlocal, $plato_otro, $promoc);
                             $this->redirect()->toUrl('/plato/listar?id=' . $idlocal);
                         }
                     }
                 }
             } else {
                 $platos = $this->getPlatosTable()->getPlato($id);
                 $adapter = new \Zend\File\Transfer\Adapter\Http();
                 $name = $platos->va_imagen;
                 $this->getPlatosTable()->guardarPlato($restaurante, $name, $idlocal, $plato_otro, $promoc);
                 $this->redirect()->toUrl('/plato/listar?id=' . $idlocal);
             }
         }
     }
     return array('in_id' => $id, 'va_nombre' => $va_nombre, 'form' => $form, 'idlocal' => $idlocal);
 }