예제 #1
0
 /**
  * Generate the view of the week for given month and given year
  * with events in this period.
  *
  * @param string $year
  * @param string $week 
  * @return view weekView
  *
  *
  */
 public function showWeek($year, $week)
 {
     // Create week start date on monday (day 1)
     $weekStart = date('Y-m-d', strtotime($year . "W" . $week . '1'));
     // Create the number of the next week
     $nextWeek = date("W", strtotime("next Week" . $weekStart));
     $nextYear = date("Y", strtotime("next Week" . $weekStart));
     // Create week end date - we go till tuesday (day 2) because café needs alternative week view (Mi-Di)
     $weekEnd = date('Y-m-d', strtotime($nextYear . "W" . $nextWeek . '2'));
     // Create the number of the previous week
     $previousWeek = date("W", strtotime("previous Week" . $weekStart));
     $previousYear = date("Y", strtotime("previous Week" . $weekStart));
     // Convert number of prev/next week to verbatim format - needed for correct << and >> button links
     $nextWeek = $nextYear . "/KW" . $nextWeek;
     $previousWeek = $previousYear . "/KW" . $previousWeek;
     $date = array('year' => $year, 'week' => $week, 'weekStart' => $weekStart, 'weekEnd' => $weekEnd, 'nextWeek' => $nextWeek, 'previousWeek' => $previousWeek);
     $events = ClubEvent::where('evnt_date_start', '>=', $weekStart)->where('evnt_date_start', '<=', $weekEnd)->with('getPlace', 'getSchedule.getEntries.getJobType', 'getSchedule.getEntries.getPerson.getClub')->orderBy('evnt_date_start')->orderBy('evnt_time_start')->get();
     $tasks = Schedule::where('schdl_show_in_week_view', '=', '1')->where('schdl_due_date', '>=', $weekStart)->where('schdl_due_date', '<=', $weekEnd)->with('getEntries.getPerson.getClub', 'getEntries.getJobType')->get();
     // TODO: don't use raw query, rewrite with eloquent.
     $persons = Cache::remember('personsForDropDown', 10, function () {
         $timeSpan = new DateTime("now");
         $timeSpan = $timeSpan->sub(DateInterval::createFromDateString('3 months'));
         return Person::whereRaw("prsn_ldap_id IS NOT NULL \n\t\t\t\t\t\t\t\t\t\t AND (prsn_status IN ('aktiv', 'kandidat') \n\t\t\t\t\t\t\t\t\t\t OR updated_at>='" . $timeSpan->format('Y-m-d H:i:s') . "')")->orderBy('clb_id')->orderBy('prsn_name')->get();
     });
     $clubs = Club::orderBy('clb_title')->lists('clb_title', 'id');
     // IDs of schedules shown, needed for bulk-update
     $updateIds = array();
     foreach ($events as $event) {
         array_push($updateIds, $event->getSchedule->id);
     }
     return View::make('weekView', compact('events', 'schedules', 'date', 'tasks', 'entries', 'weekStart', 'weekEnd', 'persons', 'clubs'));
 }
 /**
  * Calculates the sum of all shifts in a given period for a given person id.
  *
  * @return int 		$subjectTotal
  */
 public function countStatisticsById($id, $from, $till)
 {
     // get all events for the month, currently jan15 for testing
     $events = ClubEvent::where('evnt_date_start', '>', $from)->where('evnt_date_start', '<', $till)->get();
     $subject = Person::find($id);
     $subjectTotal = 0;
     foreach ($events as $event) {
         // for each event - get its schedule
         $schedule = Schedule::findOrFail($event->getSchedule->id);
         // for each schedule - get its entries that have this person's id
         $entries = ScheduleEntry::where('schdl_id', '=', $schedule->id)->where('prsn_id', '=', $subject->id)->get();
         // for each entry - get its job type weight
         foreach ($entries as $entry) {
             $weight = $entry->getJobType->jbtyp_statistical_weight;
             //and add it to subject's total
             $subjectTotal += $weight;
         }
     }
     return $subjectTotal;
 }
예제 #3
0
 /**
  * Generate the view of the calender for given month and given year
  * with events in this period.
  *
  * @param string $year
  * @param string $month 
  * @return view monthView
  */
 public function showMonth($year, $month)
 {
     // Create a string of the start of the month
     $monthStart = $year . $month . '01';
     // String of end of month
     $monthEnd = $year . $month . '31';
     // Create timestamp of the first day of selected month. Time 12:12:12 used only as dummy time
     $usedTime = mktime(12, 12, 12, $month, 1, $year);
     // Create a int with the number of days of the month (28...31)
     $daysOfMonth = date("t", $usedTime);
     // Create a timestamp with start of month
     $startStamp = mktime(0, 0, 0, date("n", $usedTime), 1, date("Y", $usedTime));
     // Int for the start day
     $startDay = date("N", $startStamp);
     // Int for the lst day
     $endDay = date("N", mktime(0, 0, 0, date("n", $usedTime), $daysOfMonth, date("Y", $usedTime)));
     // Array for german translation of the month names
     $monthName = array(1 => Config::get('messages_de.month-name-jan'), 2 => Config::get('messages_de.month-name-feb'), 3 => Config::get('messages_de.month-name-mar'), 4 => Config::get('messages_de.month-name-apr'), 5 => Config::get('messages_de.month-name-may'), 6 => Config::get('messages_de.month-name-jun'), 7 => Config::get('messages_de.month-name-jul'), 8 => Config::get('messages_de.month-name-aug'), 9 => Config::get('messages_de.month-name-sep'), 10 => Config::get('messages_de.month-name-oct'), 11 => Config::get('messages_de.month-name-nov'), 12 => Config::get('messages_de.month-name-dec'));
     $date = array('year' => $year, 'month' => $month, 'daysOfMonth' => $daysOfMonth, 'startDay' => $startDay, 'endDay' => $endDay, 'startStamp' => $startStamp, 'usedTime' => $usedTime, 'monthName' => $monthName[date("n", $usedTime)]);
     $events = ClubEvent::where('evnt_date_start', '>=', $monthStart)->where('evnt_date_start', '<=', $monthEnd)->orderBy('evnt_date_start')->orderBy('evnt_time_start')->get();
     $tasks = Schedule::where('schdl_show_in_week_view', '=', '1')->where('schdl_due_date', '>=', $monthStart)->where('schdl_due_date', '<=', $monthEnd)->get();
     return View::make('monthView', compact('events', 'tasks', 'date'));
 }
 /**
  * Updates all existing places with changes provided.
  *
  * @return view placeManagementView
  */
 public function updatePlaces()
 {
     $places = Place::orderBy('plc_title', 'ASC')->get();
     foreach ($places as $place) {
         if (Input::get('destroy' . $place->id)) {
             // find all schedules that use this place and replace it with a placeholder
             $filter = ClubEvent::where('plc_id', '=', $place->id)->get();
             foreach ($filter as $event) {
                 $event->plc_id = 0;
                 // placeholder with plc_title "-"
                 $event->save();
             }
             Place::destroy($place->id);
         } else {
             // update title
             $place->plc_title = Input::get('plc_title' . $place->id);
             $place->save();
         }
     }
     // need to update our index after the changes
     $places = Place::orderBy('plc_title', 'ASC')->get();
     return View::make('placeManagementView', compact('places'));
 }
 /**
  * Updates multiple schedules.
  */
 public function bulkUpdateSchedule($year, $week)
 {
     // Create week start date
     $weekStart = date('Y-m-d', strtotime($year . "W" . $week . '1'));
     // Create the number of the next week and the week end date
     // We go till tuesday (day 2) because café needs alternative week view (Mi-Di)
     $nextWeek = date("W", strtotime("next Week" . $weekStart));
     $nextYear = date("Y", strtotime("next Week" . $weekStart));
     $weekEnd = date('Y-m-d', strtotime($nextYear . "W" . $nextWeek . '2'));
     // Create (empty) index of all schedules we need to update
     $updateIds = array();
     // Collect IDs of event schedules shown in chosen week view
     $events = ClubEvent::where('evnt_date_start', '>=', $weekStart)->where('evnt_date_start', '<=', $weekEnd)->get();
     // Add them to the index
     foreach ($events as $event) {
         array_push($updateIds, $event->getSchedule->id);
     }
     // Collect IDs of tasks shown in week view
     $tasks = Schedule::where('schdl_show_in_week_view', '=', '1')->where('schdl_due_date', '>=', $weekStart)->where('schdl_due_date', '<=', $weekEnd)->get();
     // Add them to the index
     foreach ($tasks as $task) {
         array_push($updateIds, $task->id);
     }
     // Update each of the schedules in the index
     foreach ($updateIds as $schedule) {
         $this->onUpdate($schedule);
     }
     return Redirect::back();
 }
 /**
  * Generates the view for the list of all events on a specific date.
  *
  * @param  int $year
  * @param  int $month
  * @param  int $day
  *
  * @return view calendarView
  * @return ClubEvent[] $events
  * @return string $date
  */
 public function showDate($year, $month, $day)
 {
     $dateInput = $year . $month . $day;
     $date = strftime("%a, %d. %b %Y", strtotime($dateInput));
     $events = ClubEvent::where('evnt_date_start', '=', $dateInput)->with('getPlace')->paginate(15);
     return View::make('calendarView', compact('events', 'date'));
 }