public function consultarSupermercatAction() { $res = []; $res[0] = new RespostaTO(); try { $request = $this->getRequest(); $id = $request->getQuery("id"); if ($id != null) { $s = $this->supers->consultarSupermercat(new Integer($id), UsuariConnectat::getUsuari()->getDepenDe()); $sto = new SupermercatTO(); $sto->convertir($s); $c = new Cataleg(); $ps = $c->consultarProductesSupermercat($s->getId(), UsuariConnectat::getUsuari()->getDepenDe()); foreach ($ps as $p) { $pto = new ProducteTO(); $pto->convertir($p); $sto->afegirProducte($pto); } $res[0]->resultat = "OK"; $res[0]->supermercat = $sto; } } catch (\Exception $e) { $res[0]->resultat = "KO"; $res[0]->missatge = $e->getMessage(); } finally { return new JsonModel($res); } }
public function consultarLlistaProductesAction() { $res = []; $res[0] = new RespostaTO(); try { $productes = $this->cataleg->consultarProductesCistella(UsuariConnectat::getUsuari()->getDepenDe()); foreach ($productes as $p) { $pto = new ProducteTO(); $pto->convertir($p); $prod[] = $pto; } $res[0]->resultat = "OK"; $res[0]->productes = $prod; } catch (\Exception $e) { $res[0]->resultat = "KO"; $res[0]->missatge = $e->getMessage(); } finally { return new JsonModel($res); } }
private function consultarProductes($supermercat) { $res = []; $res[0] = new RespostaTO(); try { $prod = array(); if ($supermercat == null) { $productes = $this->cataleg->consultarLlistaProductes(UsuariConnectat::getUsuari()->getDepenDe()); } else { $productes = $this->cataleg->consultarProductesSupermercat(new Integer($supermercat), UsuariConnectat::getUsuari()->getDepenDe()); } foreach ($productes as $p) { $pto = new ProducteTO(); $pto->convertir($p); $prod[] = $pto; } $res[0]->resultat = "OK"; $res[0]->productes = $prod; } catch (\Exception $e) { $res[0]->resultat = "KO"; $res[0]->missatge = $e->getMessage(); } finally { return new JsonModel($res); } }