Exemplo n.º 1
0
 public function getCardapio($cod_tipo_prato = null)
 {
     if ($cod_tipo_prato == null) {
         $cardapio = TipoPratoModel::orderBy("cod", "asc")->get();
     } else {
         $cardapio = TipoPratoModel::where("cod", $cod_tipo_prato)->orderBy("cod", "asc")->get();
     }
     $resultado = array();
     foreach ($cardapio as $key => $value) {
         $rtmp = array();
         $rtmp["cod"] = $value["cod"];
         $rtmp["nome"] = $value["nome"];
         $rtmp["pratos"] = array();
         $pratos = PratosModel::where("deletada", "<>", 1)->where("cod_tipo_prato", $value["cod"])->orderBy("cod_tipo_prato", "asc")->orderBy("nome", "asc")->get();
         foreach ($pratos as $key_1 => $value_1) {
             $tmp = array();
             $tmp["cod"] = $value_1["cod"];
             $tmp["nome"] = $value_1["nome"];
             $tmp["valor"] = number_format((double) $value_1["valor"], 2, '.', '');
             $tmp["descricao"] = $value_1["descricao"];
             if ($value_1["foto_url"] != null) {
                 $tmp["foto_url"] = preg_replace("/..\\//", '', $value_1["foto_url"], 1);
             } else {
                 $tmp["foto_url"] = null;
             }
             array_push($rtmp["pratos"], $tmp);
         }
         array_push($resultado, $rtmp);
     }
     $dados = ["resultado" => $resultado];
     return View::make('site.cardapio')->with($dados);
 }
Exemplo n.º 2
0
 public function postPesquisa()
 {
     $dados = Input::all();
     if (isset($dados["columns"])) {
         $columns = $dados["columns"];
     }
     if (isset($dados["order"])) {
         $order = $dados["order"];
         $order = $order[0];
         $orderIndex = intval($order["column"]);
     }
     if (isset($dados["search"])) {
         $search = $dados["search"];
     }
     $limit = intval($dados["length"]);
     $start = intval($dados["start"]);
     if (isset($dados["min"])) {
         $min = $dados["min"];
     }
     if (isset($dados["max"])) {
         $max = $dados["max"];
     }
     $recordsTotal = count(PratosModel::get());
     if ($limit == -1) {
         $limit = $recordsTotal;
     }
     $pratos = DB::table("pratos")->join("tipo_prato", "pratos.cod_tipo_prato", "=", "tipo_prato.cod")->select(DB::raw('SQL_CALC_FOUND_ROWS *'))->where("pratos.cod", $search["value"])->orWhere(function ($query) use($min, $max, $search) {
         if ($min != "" && $max == "") {
             $query->where("pratos.valor", ">=", $min);
         }
         if ($max != "" && $min == "") {
             $query->where("pratos.valor", "<=", $max);
         }
         if ($min != "" && $max != "") {
             $query->whereBetween("pratos.valor", array($min, $max));
         }
         $exists = TipoPratoModel::where("nome", "LIKE", "%" . $search["value"] . "%")->get();
         if (count($exists) > 0) {
             $query->where("tipo_prato.nome", "LIKE", "%" . $search["value"] . "%");
         } else {
             $query->where("pratos.nome", "LIKE", "%" . $search["value"] . "%");
         }
     })->orderBy($columns[$orderIndex]["name"], $order["dir"])->take($limit)->skip($start)->get();
     $recordsFiltered = DB::select(DB::raw("SELECT FOUND_ROWS() AS total;"));
     $recordsFiltered = $recordsFiltered[0];
     $recordsFiltered = intval($recordsFiltered->total);
     $pratos = DB::table("pratos")->join("tipo_prato", "pratos.cod_tipo_prato", "=", "tipo_prato.cod")->where("pratos.cod", $search["value"])->orWhere(function ($query) use($min, $max, $search) {
         if ($min != "" && $max == "") {
             $query->where("pratos.valor", ">=", $min);
         }
         if ($max != "" && $min == "") {
             $query->where("pratos.valor", "<=", $max);
         }
         if ($min != "" && $max != "") {
             $query->whereBetween("pratos.valor", array($min, $max));
         }
         $exists = TipoPratoModel::where("nome", "LIKE", "%" . $search["value"] . "%")->get();
         if (count($exists) > 0) {
             $query->where("tipo_prato.nome", "LIKE", "%" . $search["value"] . "%");
         } else {
             $query->where("pratos.nome", "LIKE", "%" . $search["value"] . "%");
         }
     })->select("pratos.cod", "tipo_prato.nome as tipo", "pratos.nome as prato", "pratos.valor", "pratos.foto_url", "pratos.deletada as prato_deletado")->orderBy($columns[$orderIndex]["name"], $order["dir"])->take($limit)->skip($start)->get();
     $json = [];
     $json["draw"] = intval($dados["draw"]);
     $json["recordsTotal"] = $recordsTotal;
     $json["recordsFiltered"] = $recordsFiltered;
     $json["aaData"] = array();
     foreach ($pratos as $key => $value) {
         $value = (array) $value;
         $value["valor"] = number_format((double) $value["valor"], 2, '.', '');
         if ($value["prato_deletado"] == 1) {
             continue;
         }
         if ($value["foto_url"] != null) {
             $img = "<a class='fancybox' rel='gallery1' href='" . $value["foto_url"] . "'>";
             $img .= "<img src='" . $value["foto_url"] . "' alt='" . $value["foto_url"] . "'/>";
             $img .= "</a>";
             $value["foto_url"] = $img;
         } else {
             $value["foto_url"] = "<img class='nophoto' src='../img/noimage.png' />";
         }
         array_push($json["aaData"], array_values($value));
     }
     return json_encode($json);
 }
Exemplo n.º 3
0
 public function getListar()
 {
     $tipos = TipoPratoModel::where("deletada", "<>", 1)->orderBy("nome", "asc")->get();
     return json_encode($tipos);
 }
Exemplo n.º 4
0
 public function getCardapio()
 {
     $appid = Input::get('appid');
     if (!isset($appid) || $this->appid != intval($appid)) {
         $response = array();
         $response['error'] = true;
         $response['message'] = Lang::get('geral.acesso_negado');
         return json_encode($response);
     }
     $tipos = TipoPratoModel::where("deletada", "<>", 1)->orderBy("nome", "asc")->get();
     $response = array();
     if (count($tipos) == 0) {
         $response['error'] = true;
         $response['message'] = Lang::get('geral.msg_erro');
     } else {
         $response['error'] = false;
         $response['message'] = "";
         for ($i = 0; $i < count($tipos); $i++) {
             if ($tipos[$i]->foto_url != null) {
                 $path = Request::root() . $tipos[$i]->foto_url;
                 $foto = file_get_contents($path);
                 $tipos[$i]->foto_url = base64_encode($foto);
             }
         }
         $response['cardapio'] = $tipos;
     }
     return json_encode($response);
 }