示例#1
0
文件: Service.php 项目: maxwroc/PHP
 protected function generateMeals($aDates, $iMealsQuantityPerDay = 6)
 {
     $oService = new Model_Service();
     foreach ($aDates as $sDate) {
         $iCount = 0;
         $aMeals = $oService->getRandomMeals($this->oCurrentUser->account_id, $iMealsQuantityPerDay);
         foreach ($aMeals as $aMeal) {
             $oMeal = new Model_Meal();
             $oMeal->date = $sDate;
             $oMeal->name = ++$iCount;
             $oMeal->price = (double) $aMeal['price'];
             $oMeal->account_id = (int) $this->oCurrentUser->account_id;
             if (!$oMeal->save()) {
                 return 'error 1';
             }
             $iMealId = $oMeal->getInsertId();
             foreach ($aMeal['courses'] as $iCourseId) {
                 if (!$oService->saveMealCourse($iMealId, $iCourseId)) {
                     return 'error 2';
                 }
             }
         }
         // foreach
     }
     // foreach
     return sprintf('Menu na zadany tydzien utworzone. <a href="%s">powrot</a>', str_replace('generate/', '', $this->getPageUrl()));
 }