public function getCottagelist() { $response = array(); $cottageType = Input::get('cottageType'); $date = date('Y-m-d', strtotime(Input::get('date'))); $month = date('m', strtotime(Input::get('date'))); $reserves = CottageReservation::where('reservation_date', '=', $date)->get(); $id = array(); if (!empty($reserves)) { foreach ($reserves as $reserve) { $chosenCottages = explode(",", $reserve['cottagelist_id']); foreach ($chosenCottages as $cottage) { if (!$cottage == "") { if (!in_array($cottage, $id)) { $id[count($id)] = $cottage; } } } } $weekDay = date('w', strtotime($date)); $holidayCheck = Holidays::where('date', '=', $date)->first(); //return count($holidayCheck); if ($month == 03 || $month == 04 || $month == 05) { $details = "Summer Season"; $season = 3; } elseif (!empty($holidayCheck)) { $details = $holidayCheck['holidays']; $season = 2; } elseif ($weekDay == 0 || $weekDay == 6) { $details = "Weekend"; $season = 2; } else { $details = "Regular Season"; $season = 1; } /* $response[] = array( "cottage_list"=>'', "name" =>'', "details"=>$details, "season" =>$season, );*/ $cottagelists = CottageList::where('cottage_id', '=', $cottageType)->get(); foreach ($cottagelists as $list) { if (!in_array($list['cottagelist_id'], $id)) { $response[] = array("cottage_list" => $list['cottagelist_id'], "name" => $list['cottagename'], "details" => $details, "season" => $season); } } return $response; } else { $getCottage_lists = CottageList::where('cottage_id', '=', $cottageType)->get(); foreach ($getCottage_lists as $list) { $response[] = array("cottage_list" => $list['cottagelist_id'], "name" => $list['cottagename']); } return $response; } }
public static function getHolidayDatabySeasonId($seasonId) { return Holidays::where('season_id', '=', $seasonId)->get(); }
/** * Display a listing of the resource. * * @return Response */ public function index() { // if (Auth::check()) { $currentPage = "CLASSES"; $mainMenu = "COURSES_MAIN"; $inputs = Input::all(); if (isset($inputs['startTime'])) { //$startDate = //date('Y-m-d', strtotime($season_data['end_date'])); $season_data = Seasons::where('id', '=', $inputs['selectSeason'])->get(); $season_data = $season_data[0]; $startDate = new Carbon(); $endDate = new Carbon(); $startDate = $startDate->createFromFormat('Y-m-d', $season_data['start_date']); $endDate = $endDate->createFromFormat('Y-m-d', $season_data['end_date']); //taking season start date, end date and making calculation to start to specific day(MON,TUE...) switch ($inputs['day']) { case 0: break; case 1: $startDate->addDays(1); break; case 2: $startDate->addDays(2); break; case 3: $startDate->addDays(3); break; case 4: $startDate->addDays(4); break; case 5: $startDate->addDays(5); break; case 6: $startDate->addDays(6); break; } switch ($inputs['day']) { case 0: $endDate->subDays(6); break; case 1: $endDate->subDays(5); break; case 2: $endDate->subDays(4); break; case 3: $endDate->subDays(3); break; case 4: $endDate->subDays(2); break; case 5: $endDate->subDays(1); break; case 6: break; } $date = $startDate->day; $yr = $startDate->year; $month = $startDate->month; $inputs['startDate'] = $date . '-' . $month . '-' . $yr; $courseId = $inputs['franchiseeCourse']; $classId = $inputs['className']; $startTime = $inputs['startTime']; $endTime = $inputs['endTime']; $leadInstructor = $inputs['leadInstructor']; $alternateInstructor = $inputs['alternateInstructor']; $day = date('N', strtotime($inputs['startDate'])); if (date('m', strtotime($inputs['startDate'])) >= 1 && date('m', strtotime($inputs['startDate'])) <= 1) { $endDateYear = date('Y', strtotime($inputs['startDate'])); } else { $endDateYear = date('Y', strtotime($inputs['startDate'])); $endDateYear = $endDateYear + 1; } /* echo $startDate.' = '.$endDate ;//Year.'-03-31'; exit(); */ $months = getMonthsBetweenDates($startDate, $endDate); //Year.'-03-31'); /* echo "<pre>"; print_r($months); echo "</pre>"; exit(); */ $i = 0; foreach ($months as $month) { $yearAndMonth = explode('-', $month['month']); $daysFound[$i] = getDaysFromMonth($yearAndMonth['1'], $yearAndMonth['0'], $day); $i++; } $timeString = date('Y-m-d', strtotime($inputs['startDate'])) . $inputs['startTime']; $timestamp = strtotime($timeString); $startTime24Hours = date('H:i:s', $timestamp); $timeString = $endDateYear . '-3-5 ' . $inputs['endTime']; $timestamp = strtotime($timeString); $endTime24Hours = date('H:i:s', $timestamp); $batchSlug = Courses::getBatchID($courseId, $classId, $startDate, null, $inputs['selectSeason']); $inputBatch['batchName'] = $batchSlug; $inputBatch['classId'] = $classId; $inputBatch['courseId'] = $courseId; $inputBatch['startDate'] = $startDate->toDateString(); $inputBatch['endDate'] = $endDate->toDateString(); $inputBatch['season_id'] = $inputs['selectSeason']; $inputBatch['preferredTime'] = $startTime24Hours; $inputBatch['preferredEndTime'] = $endTime24Hours; $inputBatch['leadInstructor'] = $leadInstructor; $inputBatch['alternateInstructor'] = $alternateInstructor; $inputBatch['location_id'] = $inputs['seasonLocation']; //$inputBatch['classAmount']=$inputs['eachClassAmount']; $newBatch = Batches::addBatches($inputBatch); /* $days = 1; foreach($daysFound as $monthdays){ foreach($monthdays as $dayFound){ if($days <= 40){ $batchScheduleInput['batchId'] = $newBatch->id; $batchScheduleInput['seasonId'] = $inputs['selectSeason']; $batchScheduleInput['scheduleDate'] = $dayFound; $batchScheduleInput['startTime'] = $startTime24Hours; $batchScheduleInput['endTime'] = $endTime24Hours; $batchScheduleInput['scheduleType']= 'class'; BatchSchedule::addSchedule($batchScheduleInput); } $days++; } } */ //calculating dates and adding all the dates to batchschedule for new batch $batch_schedule = new BatchSchedule(); do { $batchScheduleInput['batchId'] = $newBatch->id; $batchScheduleInput['seasonId'] = $inputs['selectSeason']; $batchScheduleInput['scheduleDate'] = $startDate->toDateString(); $batchScheduleInput['startTime'] = $startTime24Hours; $batchScheduleInput['endTime'] = $endTime24Hours; $batchScheduleInput['scheduleType'] = 'class'; BatchSchedule::addSchedule($batchScheduleInput); $startDate->addDays(7); } while ($startDate->eq($endDate) == FALSE); //for last date $batchScheduleInput['batchId'] = $newBatch->id; $batchScheduleInput['seasonId'] = $inputs['selectSeason']; $batchScheduleInput['scheduleDate'] = $startDate->toDateString(); $batchScheduleInput['startTime'] = $startTime24Hours; $batchScheduleInput['endTime'] = $endTime24Hours; $batchScheduleInput['scheduleType'] = 'class'; BatchSchedule::addSchedule($batchScheduleInput); //check for holidays if exists make if (Holidays::where('season_id', '=', $inputs['selectSeason'])->count() > 0) { $holiday_data = Holidays::where('season_id', '=', $inputs['selectSeason'])->select('startdate', 'enddate')->get(); for ($i = 0; $i < count($holiday_data); $i++) { DB::table('batch_schedule')->where('batch_id', '=', $newBatch->id)->whereBetween('schedule_date', array($holiday_data[$i]['startdate'], $holiday_data[$i]['enddate']))->update(array('holiday' => 1)); } } Session::flash('msg', "Batch added successfully."); return Redirect::to('batches'); } $franchiseeId = Session::get('franchiseId'); $season_display_data = Seasons::where('franchisee_id', '=', Session::get('franchiseId'))->orderBy('id', 'DESC')->get(); if (isset($season_display_data[0])) { $s_id = $season_display_data[0]['id']; $batches = Batches::getAllBatchesDatabySeasonId($franchiseeId, $s_id); for ($i = 0; $i < count($batches); $i++) { $batches[$i]['preferred_time'] = date("H:i", strtotime($batches[$i]['preferred_time'])); $batches[$i]['preferred_end_time'] = date("H:i", strtotime($batches[$i]['preferred_end_time'])); $location_data = Location::where('id', '=', $batches[$i]['location_id'])->get(); $batches[$i]['location_name'] = $location_data[0]['location_name']; $batches[$i]['created'] = date("Y-m-d", strtotime($batches[$i]['created_at'])); $batches[$i]['day'] = date('l', strtotime($batches[$i]['start_date'])); if ($batches[$i]['lead_instructor'] != '') { $user_data = User::find($batches[$i]['lead_instructor']); $batches[$i]['instructor_name'] = $user_data['first_name'] . '' . $user_data['last_name']; } else { $batches[$i]['instructor_name'] = ''; } $batches[$i]['count'] = StudentClasses::where('batch_id', '=', $batches[$i]['id'])->count(); } } $courseList = Courses::getFranchiseCoursesList($franchiseeId); $franchiseeCourses = Courses::getFranchiseCoursesList(Session::get('franchiseId')); $Instructors = User::getInstructors(); $dataToView = array('batches', 'courseList', 'currentPage', 'mainMenu', 'franchiseeCourses', 'mondays', 'Instructors'); return View::make('pages.batches.batchesfinal', compact($dataToView)); } else { return Redirect::to("/"); } }