ordersprinter/gastsystem/php/menu.php

70 lines
1.7 KiB
PHP
Raw Normal View History

2020-11-19 23:10:06 +01:00
<?php
require_once 'dbutils.php';
require_once 'config.php';
class Menu {
public static function getmenu($pdo) {
$sql = "SELECT value FROM %ossystem% WHERE item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('products'));
if (is_null($result) || (count($result) == 0)) {
return array("status" => "ERROR","msg" => "Keine Produktdefinition hinterlegt.");
}
$products = json_decode($result[0]["value"], true);
$sql = "SELECT value FROM %ossystem% WHERE item=?";
$result = DbUtils::fetchSqlAll($pdo, $sql, array('types'));
if (is_null($result) || (count($result) == 0)) {
return array("status" => "ERROR","msg" => "Keine Produktdefinition hinterlegt.");
}
$types = json_decode($result[0]["value"], true);
2020-11-19 23:12:37 +01:00
foreach ($types as &$t) {
$typeid = $t["id"];
$t["hasprodimages"] = self::hasTypeProdImages($pdo, $types, $products, $typeid);
}
2020-11-19 23:10:06 +01:00
return array("status" => "OK","msg" => array("types" => $types,"products" => $products));
}
2020-11-19 23:12:37 +01:00
private static function hasTypeProdImages($pdo,$alltypes,$allproducts,$typeid) {
$prodids = array();
foreach($allproducts as $p) {
if ($p["ref"] == $typeid) {
$prodids[] = $p["id"];
}
}
$sql = "SELECT IFNULL(content,'') as content FROM %images% WHERE contenttype=? AND productid=?";
foreach($prodids as $prodid) {
$img = DbUtils::fetchSqlAll($pdo, $sql, array(DbUtils::$TYPE_PRODIMG,$prodid));
if (count($img) > 0) {
$imgdata = $img[0]["content"];
if ($imgdata != '') {
return 1;
}
}
}
return 0;
}
2020-11-19 23:10:06 +01:00
}
if (isset($_GET["command"])) {
$command = $_GET["command"];
$pdo = DbUtils::openDbAndReturnPdoStatic();
switch ($command) {
case "getmenu":
$ret = Menu::getmenu($pdo);
echo json_encode($ret);
break;
default:
break;
}
}