public function refreshDashboardAction()
 {
     $mode = $this->_getParam('mode');
     $today = date('Y-m-d');
     switch ($mode) {
         case 'today':
             $date = $today;
             break;
         case 'yesterday':
             $date = date('Y-m-d', strtotime($today . '-1 day'));
             break;
         case 'tomorrow':
             $date = date('Y-m-d', strtotime($today . '+1 day'));
             break;
         case 'last7days':
             $date1 = date('Y-m-d', strtotime($today . '-7 days'));
             $date2 = $today;
             break;
         case 'last30days':
             $date1 = date('Y-m-d', strtotime($today . '-30 days'));
             $date2 = $today;
             break;
         case 'thismonth':
             $date = null;
             break;
         case 'lastmonth':
             $date = null;
             break;
     }
     $modelDailyExercises = new Public_Model_Daily_Exercises();
     $dailyIntake = new Public_Model_Daily_Intake();
     if (isset($date1) && isset($date2)) {
         $milesRan = $modelDailyExercises->fetchAll("type = 'Running' and date between '" . $date1 . "' and '" . $date2 . "' and userId =  " . $this->user->getId())->toArray();
         $daysWithGym = $modelDailyExercises->fetchDaysWithOrWoutGym($date1, $date2, $this->user);
     } else {
         $dataDailyIntake = $dailyIntake->fetchMacros($date, $this->user);
         $milesRan = $modelDailyExercises->fetchAll("type = 'Running' and date = '" . $date . "' and userId =  " . $this->user->getId())->toArray();
         if (isset($dataDailyIntake[$date]['totalCalories'])) {
             $statistics['caloriesConsumed'] = $dataDailyIntake[$date]['totalCalories'];
         }
     }
     $totalMiles = null;
     foreach ($milesRan as $data) {
         if ($data['miles']) {
             $totalMiles += $data['miles'];
         }
     }
     $statistics['milesRan'] = $totalMiles;
     $this->view->statistics = $statistics;
     $this->_helper->layout->disableLayout();
 }
    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;
    }