Beispiel #1
0
 public function actionResturantmenu()
 {
     $from = strtotime(date('2015-07-25'));
     //$from = strtotime(date('Y-m-d'));
     $today = strtotime('+7 days');
     $difference = $today - $from;
     $daysDiff = floor($difference / (60 * 60 * 24));
     $sEndDate = date('Y-m-d', strtotime('+' . $daysDiff . ' days'));
     //$datestr = date('Y-m-d', strtotime('-6 days'));
     $sStartDate = date("Y-m-d", strtotime(date('2015-07-25')));
     $sEndDate = date("Y-m-d", strtotime($sEndDate));
     // Start the variable off with the start date
     $aDays[] = $sStartDate;
     // Set a 'temp' variable, sCurrentDate, with
     // the start date - before beginning the loop
     $sCurrentDate = $sStartDate;
     // While the current date is less than the end date
     while ($sCurrentDate < $sEndDate) {
         // Add a day to the current date
         $sCurrentDate = date("Y-m-d", strtotime("+1 day", strtotime($sCurrentDate)));
         // Add this new day to the aDays array
         $aDays[] = $sCurrentDate;
     }
     $meals = Meal::getMeal();
     $count = 0;
     $newArrayMealsByDays = [];
     if (!empty($meals)) {
         foreach ($meals as $key => $value) {
             //echo $count++;
             //foreach ($aDays as $dateKey => $dateValue) {
             //$dayOfDeal = date('Y-m-d', $value['day']);
             //if($dayOfDeal == $dateValue){
             $newArrayMealsByDays[$value['day']][$count]['id'] = $value['id'];
             $newArrayMealsByDays[$value['day']][$count]['name'] = $value['name'];
             $newArrayMealsByDays[$value['day']][$count]['mealImageUrl'] = $value['image_new_url'];
             $newArrayMealsByDays[$value['day']][$count]['mealPrice'] = $value['meal_price'];
             $getMealItems = MealItemsManage::find()->select(['item_id'])->where(['meal_id' => $value['id']])->asArray()->all();
             if (!empty($getMealItems)) {
                 foreach ($getMealItems as $key2 => $value2) {
                     $query = new Query();
                     $query->select(['meal_item.*', 'meal_item_image.image_new_url', 'meal_item_image.image_org_url'])->from('meal_item')->join('LEFT JOIN', 'meal_item_image', 'meal_item_image.itemID = meal_item.id')->where(['meal_item.id' => $value2['item_id']]);
                     $command = $query->createCommand();
                     $data[] = $command->queryAll()[0];
                 }
                 $newArrayMealsByDays[$value['day']][$count]['items'] = $data;
                 //array_values($newArrayMealsByDays[$dayOfDeal]);
                 unset($data);
                 $count++;
             }
             //}
             //}
         }
     }
     // echo '<pre>';
     // print_r($newArrayMealsByDays);die;
     // die;
     return $this->render('_resturant_menu', ['data' => $newArrayMealsByDays]);
 }