public function myPlateAction() { $request = $this->getRequest(); if ($request->isGet()) { $food = $this->_getParam('food'); $date = $this->_getParam('date'); $foodSearch = $this->_getParam('foodsearch'); if ($food) { $modelFoods = new Model_Foods(); header("Content-Type: application/json"); $aResults = $modelFoods->fetchResults($foodSearch); echo "{\"results\": ["; $arr = array(); for ($i = 0; $i < count($aResults); $i++) { $arr[] = '{"id": "' . $aResults[$i]['foodId'] . '", "value": "' . $aResults[$i]['name'] . '", "servingSize": "' . $aResults[$i]['servingSize'] . ' ' . $aResults[$i]['servingSizeType'] . '", "servingSizeType": "' . $aResults[$i]['servingSizeType'] . '", "info": "' . $this->t->_('Calories') . ': ' . $aResults[$i]['calories'] . ' | ' . $this->t->_('Protein') . ': ' . $aResults[$i]['protein'] . ' | ' . $this->t->_('Fat') . ': ' . $aResults[$i]['fat'] . ' | ' . $this->t->_('Sugar') . ': ' . $aResults[$i]['sugar'] . ' | ' . $this->t->_('Carbs') . ': ' . $aResults[$i]['carbs'] . ' | ' . $this->t->_('Sodium') . ': ' . $aResults[$i]['sodium'] . ' | ' . $this->t->_('Fiber') . ': ' . $aResults[$i]['fiber'] . ' | ' . $this->t->_('Cholesterol') . ': ' . $aResults[$i]['cholesterol'] . ' "}'; } echo implode(", ", $arr); echo "]}"; exit; } elseif ($date) { $mealId = $this->_getParam('mealId', 0); $mealId = (int) $mealId; $foodIds = $this->_getParam('foodIds', 0); $what = null; if ($mealId) { $what = 'Meal'; $modelDailyIntake = new Public_Model_Daily_Intake(); $modelDailyIntake->insert(array('userId' => $this->user->getId(), 'mealId' => $mealId, 'date' => $date)); } elseif ($foodIds) { $what = 'Food(s)'; $foodIds = explode(',', $foodIds); foreach ($foodIds as $foodId) { $foodId = (int) $foodId; if ($foodId) { $modelDailyIntake = new Public_Model_Daily_Intake(); $modelDailyIntake->insert(array('userId' => $this->user->getId(), 'foodId' => $foodId, 'servingSize' => $this->_getParam('servingSize'), 'servingSizes' => $this->_getParam('servingSizes'), 'date' => $date)); } } } echo Zend_Json::encode(array('success' => 1)); exit; } } $modelMeals = new Model_Meals(); $modelFoods = new Model_Foods(); $formMeals = self::getMyaccountMealsForm(); $formMeals->setMeals($modelMeals->fetchAll('userId = ' . $this->user->getId())->toArray()); $formFoods = self::getMyaccountFoodsForm(); $modelDailyIntake = new Public_Model_Daily_Intake(); $this->view->dailyIntake = $modelDailyIntake->fetchAll("date = '" . date('Y-m-d') . "' and userId = " . (int) $this->user->getId() . "")->toArray(); $this->view->formMeals = $formMeals; $this->view->formFoods = $formFoods; $this->view->modelFoods = $modelFoods; }