Skip to content

Commit

Permalink
category all
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Salisbury committed Feb 16, 2017
1 parent 89afab0 commit 4b6c475
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion api/routes/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
$app->get('/category/all', function( $request, $response ) {
$q = new CategoryQuery;
$cats = $q::create()->find();





$response_json = [
"status" => [
"code" => $response->getStatusCode(),
Expand All @@ -15,9 +20,25 @@
"data" => []
];
foreach( $cats as $cat ) {

$q = new CategoryRankNutrientQuery;
$requestedCatRules = $q->filterByCategoryId($cat->getId())->find();
foreach($requestedCatRules as $rule) {
$rules[] = [
"nutrientName" => $rule->getNutrient()->getName(),
"nutrientId" => $rule->getNutrient()->getId(),
"operator" => $rule->getOperator(),
"threshold" => $rule->getThreshold(),
"units" => $rule->getUnits(),
"rank" => $rule->getRankId()
];
}


$response_json["data"][] = [
"id" => $cat->getId(),
"name" => $cat->getName()
"name" => $cat->getName(),
"rules" => $rules
];
}
$response = $response->withJSON($response_json);
Expand Down
2 changes: 1 addition & 1 deletion api/routes/rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
$app->post('/rules/updateRuleById/{ruleId}', function($request, $response) {

$rule = CategoryRankNutrientQuery::create()->findPk($request->getAttribute("ruleId"));
print_r($rule);

$cat = $request->getParam('catId');


Expand Down

0 comments on commit 4b6c475

Please sign in to comment.