From e37c370137c876eca3df5f5e3a76f09a16d86a34 Mon Sep 17 00:00:00 2001 From: Joel Salisbury Date: Mon, 13 Feb 2017 10:44:36 -0500 Subject: [PATCH] getdecision is done --- api/routes/decision.php | 46 +++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/api/routes/decision.php b/api/routes/decision.php index 7079578..90d0ca0 100644 --- a/api/routes/decision.php +++ b/api/routes/decision.php @@ -136,15 +136,27 @@ function getProductInfo($upc) { $theNuts[$nutrient['nutrient']['@attributes']['name']] = $nutrient['@attributes']['value']; } -echo "

The Product has...

"; -echo "
";
-print_r($theNuts);
-echo "
"; +// echo "

The Product has...

"; +// echo "
";
+// print_r($theNuts);
+// echo "
"; // get the rules by category $q = new CategoryRankNutrientQuery; +$c = new CategoryQuery(); + + $allRules = $q->filterByCategoryId($request->getAttribute('category'))->find(); - $passedRank = "Red"; + //$res["food"] = $prodInfo; + $res["food"]['brand'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['brand']; + $res["food"]['name'] = $prodInfo['response']['body']['product_list']['products'][0]["@attributes"]['name']; + + $res["request"]["categoryRuleRun"] = $c->findPk($request->getAttribute("category"))->getName(); + + +//default + $res["rankId"] = 0; + $res["rankName"] = "Red"; // for each rule, evaluate ingredients foreach($allRules as $rule) { @@ -152,6 +164,8 @@ function getProductInfo($upc) { $operator = $rule->getOperator(); $threshold = $rule->getThreshold(); $presentVal = $theNuts[$nut]; + + $pass = 0; switch($operator) { case "lte": @@ -185,17 +199,27 @@ function getProductInfo($upc) { $rules[$rule->getRank()->getName()]['passedRank'] = $pass?"true" : "false"; if($pass) { - $passedRank = $rule->getRank()->getName(); + $res["rankId"] = $rule->getRank()->getId(); + $res["rankName"] = $rule->getRank()->getName(); } } -echo "

The rules expected...

"; -echo "
";
-print_r($rules);
-echo "
"; +// echo "

The rules expected...

"; +// echo "
";
+// print_r($rules);
+// echo "
"; -echo "Ultimately this food is a ". $passedRank; +// echo "Ultimately this food is a ". $passedRank; + $response_json = [ + "status" => [ + "code" => $response->getStatusCode(), + "message" => "OK" + ], + "data" => [$res] + ]; + $response = $response->withJSON($response_json); + return $response; }); \ No newline at end of file