예제 #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'));
 }
예제 #2
0
 public function run()
 {
     Eloquent::unguard();
     /**
      * clearing table
      */
     DB::table('club_events')->delete();
     /**
      * creating public events
      */
     ClubEvent::create(array('evnt_title' => 'Example Event', 'evnt_subtitle' => 'Event Subtitle', 'plc_id' => '1', 'evnt_date_start' => '2015-04-01', 'evnt_date_end' => '2015-04-02', 'evnt_time_start' => '21:00', 'evnt_time_end' => '01:00', 'evnt_public_info' => 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.', 'evnt_private_details' => 'Use "password" for password.', 'evnt_is_private' => '0'));
     /**
      * reporting result to console
      */
     $this->command->info('Example event created on 01.04.2015.');
 }
 /**
  * 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;
 }
예제 #4
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();
 }
예제 #7
0
 /**
  * Edit or create a clubevent with its entered information.
  * If $id is null create a new clubEvent, otherwise the clubEvent specified by $id will be edit. 
  *
  * @param int $id
  * @return ClubEvent clubEvent
  */
 private function editClubEvent($id)
 {
     $event = new ClubEvent();
     if (!is_null($id)) {
         $event = ClubEvent::findOrFail($id);
     }
     // format: strings; no validation needed
     $event->evnt_title = Input::get('title');
     $event->evnt_subtitle = Input::get('subtitle');
     $event->evnt_public_info = Input::get('publicInfo');
     $event->evnt_private_details = Input::get('privateDetails');
     $event->evnt_type = Input::get('evnt_type');
     // create new place
     if (!Place::where('plc_title', '=', Input::get('place'))->first()) {
         $place = new Place();
         $place->plc_title = Input::get('place');
         $place->save();
         $event->plc_id = $place->id;
     } else {
         $event->plc_id = Place::where('plc_title', '=', Input::get('place'))->first()->id;
     }
     // format: date; validate on filled value
     if (!empty(Input::get('beginDate'))) {
         $newBeginDate = new DateTime(Input::get('beginDate'), new DateTimeZone(Config::get('app.timezone')));
         $event->evnt_date_start = $newBeginDate->format('Y-m-d');
     } else {
         $event->evnt_date_start = date('Y-m-d', mktime(0, 0, 0, 0, 0, 0));
     }
     if (!empty(Input::get('endDate'))) {
         $newEndDate = new DateTime(Input::get('endDate'), new DateTimeZone(Config::get('app.timezone')));
         $event->evnt_date_end = $newEndDate->format('Y-m-d');
     } else {
         $event->evnt_date_end = date('Y-m-d', mktime(0, 0, 0, 0, 0, 0));
     }
     // format: time; validate on filled value
     if (!empty(Input::get('beginTime'))) {
         $event->evnt_time_start = Input::get('beginTime');
     } else {
         $event->evnt_time_start = mktime(0, 0, 0);
     }
     if (!empty(Input::get('endTime'))) {
         $event->evnt_time_end = Input::get('endTime');
     } else {
         $event->evnt_time_end = mktime(0, 0, 0);
     }
     // format: tinyInt; validate on filled value
     // reversed this: input=1 means "event is public", input=0 means "event is private"
     $event->evnt_is_private = Input::get('isPrivate') == '1' ? 0 : 1;
     return $event;
 }
 /**
  * Generates the view for a specific event, including the schedule.
  *
  * @param  int $id
  * @return view ClubEventView
  * @return ClubEvent $clubEvent
  * @return ScheduleEntry[] $entries
  * @return RedirectResponse
  */
 public function showId($id)
 {
     $clubEvent = ClubEvent::with('getPlace')->findOrFail($id);
     if (!Session::has('userId') and $clubEvent->evnt_is_private == 1) {
         Session::put('message', Config::get('messages_de.access-denied'));
         Session::put('msgType', 'danger');
         return Redirect::action('MonthController@showMonth', array('year' => date('Y'), 'month' => date('m')));
     }
     $schedule = Schedule::findOrFail($clubEvent->getSchedule->id);
     $entries = ScheduleEntry::where('schdl_id', '=', $schedule->id)->with('getJobType', 'getPerson', 'getPerson.getClub')->get();
     $clubs = Club::orderBy('clb_title')->lists('clb_title', 'id');
     $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 AND (prsn_status IN ('aktiv', 'kandidat') OR updated_at>='" . $timeSpan->format('Y-m-d H:i:s') . "')")->orderBy('clb_id')->orderBy('prsn_name')->get();
     });
     $revisions = json_decode($clubEvent->getSchedule->entry_revisions, true);
     if (!is_null($revisions)) {
         // deleting ip adresses from output for privacy reasons
         foreach ($revisions as $entry) {
             unset($entry["from ip"]);
         }
     }
     return View::make('clubEventView', compact('clubEvent', 'entries', 'clubs', 'persons', 'revisions'));
 }