Beispiel #1
0
 public static function create()
 {
     $foodData = json_decode($_POST["foodData"], true);
     $result = array();
     $validate = true;
     $result["foodName"] = false;
     $result["foodPrice"] = false;
     $result["foodType"] = false;
     if (!isset($foodData["foodName"]) || empty($foodData["foodName"])) {
         $result['foodName'] = true;
         $validate = false;
     }
     if (!isset($foodData["foodPrice"]) || empty($foodData["foodPrice"])) {
         $result['foodPrice'] = true;
         $validate = false;
     }
     if (!isset($foodData["foodType"]) || empty($foodData["foodType"])) {
         $result['foodType'] = true;
         $validate = false;
     }
     if (!isset($foodData["image"]) || empty($foodData["image"])) {
         $result['image'] = true;
         $validate = false;
     }
     if ($validate == false) {
         echo json_encode($result);
         return;
     }
     $x = $y = 0;
     $s = 250;
     $d = 100;
     $sizer = new ImageSizer();
     $sizer->load(self::$tmpDir . $foodData["image"]);
     $width = $sizer->getWidth();
     $height = $sizer->getHeight();
     $sizer->save(self::$imageDir . $foodData["image"]);
     $x = $width * ($foodData["cropX"] / $foodData["imageW"]);
     //echo $width." ".$foodData["cropX"]." ".$x."<br>";
     $y = $height * ($foodData["cropY"] / $foodData["imageH"]);
     //echo $height." ".$foodData["cropY"]." ".$y."<br>";
     $d = $width * ($foodData["cropW"] / $foodData["imageW"]);
     //echo $foodData["cropW"]." ".$d;
     if (intval($d) != 0) {
         $sizer->resize($x, $y, $s, $d);
         $sizer->save(self::$thumDir . $foodData["image"]);
     }
     $food = new Food();
     $food->setName($foodData["foodName"]);
     $food->setPrice($foodData["foodPrice"]);
     $food->setFoodTypeId(1);
     $food->setStatus(true);
     $food->setThumbnail($foodData["image"]);
     $food->setImage($foodData["image"]);
     $food->insertDatabase(null);
     echo json_encode($result);
 }
Beispiel #2
0
}
if (empty($foodData["foodType"])) {
    $result["foodType"] .= $error;
    $validate = false;
}
$result["validate"] = $validate;
if ($validate === false) {
    echo json_encode($result);
    exit;
} else {
    if (!empty($foodData["image"])) {
        if (!empty($foodData["cropW"]) || !empty($foodData["cropH"])) {
            $tmpPath = "assets/upload/tmp/";
            $thumPath = "assets/upload/thumbnail/";
            $sizer = new ImageSizer();
            $sizer->load($_SERVER['DOCUMENT_ROOT'] . $tmpPath . $foodData["image"]);
            $width = $sizer->getWidth();
            $height = $sizer->getHeight();
            $x = $width * ($foodData["cropX"] / $foodData["imageW"]);
            $y = $height * ($foodData["cropY"] / $foodData["imageH"]);
            if ($width < $height) {
                $s = $width * ($foodData["cropW"] / $foodData["imageW"]);
            } else {
                $s = $height * ($foodData["cropH"] / $foodData["imageH"]);
            }
            $sizer->crop($x, $y, $s, $s);
            $sizer->save($_SERVER['DOCUMENT_ROOT'] . $thumPath . $foodData["image"]);
        }
    }
    echo json_encode($result);
}