/**
  * Updates schedule entries of a specific schedule.
  *
  * If a password is needed, check it's correct and throw an error to the session if it's not,
  * update all entries in bulk otherwise.
  *
  * @param int $id
  *
  * @return RedirectResponse
  */
 private function onUpdate($id)
 {
     $schedule = Schedule::findOrFail($id);
     $entries = ScheduleEntry::where('schdl_id', '=', $id)->get();
     // Check if that schedule needs a password
     if ($schedule->schdl_password !== '') {
         //get password for specific id here, similar to enty->id
         if (!Hash::check(Input::get('password'), $schedule->schdl_password)) {
             Session::put('message', Config::get('messages_de.schedule-pw-needed'));
             Session::put('msgType', 'danger');
             return Redirect::back();
         }
     }
     foreach ($entries as $entry) {
         // Remember old value for logging
         $oldPerson = $entry->getPerson;
         // Entry was empty
         if (!isset($entry->prsn_id)) {
             // Entry is not empty now
             if (!Input::get('userName' . $entry->id) == '') {
                 // Add new entry data
                 $this->onAdd($entry);
                 // log revision
                 ScheduleController::logRevision($entry->getSchedule, $entry, "Dienst eingetragen", $oldPerson, $entry->getPerson()->first());
                 // new value
             }
             // Otherwise no change found - do nothing
         } else {
             // Same person there?
             if ($entry->getPerson->prsn_name == Input::get('userName' . $entry->id) and Person::where('id', '=', $entry->prsn_id)->first()->prsn_ldap_id == Input::get('ldapId' . $entry->id)) {
                 // Was comment updated?
                 if ($entry->entry_user_comment != Input::get('comment' . $entry->id)) {
                     $entry->entry_user_comment = Input::get('comment' . $entry->id);
                 }
                 // Otherwise no change found - do nothing
             } else {
                 // Was entry deleted?
                 if (Input::get('userName' . $entry->id) == '') {
                     $this->onDelete($entry);
                     // log revision
                     ScheduleController::logRevision($entry->getSchedule, $entry, "Dienst ausgetragen", $oldPerson, $entry->getPerson()->first());
                     // new value
                 } else {
                     // delete old data
                     $this->onDelete($entry);
                     // add new data
                     $this->onAdd($entry);
                     // log revision
                     ScheduleController::logRevision($entry->getSchedule, $entry, "Dienst geändert", $oldPerson, $entry->getPerson()->first());
                     // new value
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Create a new event with schedule and write it to the database.
  *
  * @return RedirectResponse
  */
 public function createEvent()
 {
     //validate passwords
     if (Input::get('password') != Input::get('passwordDouble')) {
         Session::put('message', Config::get('messages_de.password-mismatch'));
         Session::put('msgType', 'danger');
         return Redirect::back()->withInput();
     }
     $newEvent = $this->editClubEvent(null);
     $newEvent->save();
     $newSchedule = $this->editSchedule(null);
     $newSchedule->evnt_id = $newEvent->id;
     // log revision
     $newSchedule->entry_revisions = json_encode(array("0" => ["entry id" => null, "job type" => null, "action" => "Dienstplan erstellt", "old id" => null, "old value" => null, "new id" => null, "new value" => null, "user id" => Session::get('userId') != NULL ? Session::get('userId') : "", "user name" => Session::get('userId') != NULL ? Session::get('userName') . '(' . Session::get('userClub') . ')' : "Gast", "from ip" => Request::getClientIp(), "timestamp" => (new DateTime())->format('Y-m-d H:i:s')]));
     $newSchedule->save();
     $newEntries = ScheduleController::createScheduleEntries($newSchedule->id);
     foreach ($newEntries as $newEntry) {
         $newEntry->schdl_id = $newSchedule->id;
         $newEntry->save();
         // log revision
         ScheduleController::logRevision($newEntry->getSchedule, $newEntry, "Dienst erstellt", null, null);
         // new value
     }
     // log the action
     Log::info('Create event: User ' . Session::get('userName') . '(' . Session::get('userId') . ', ' . Session::get('userGroup') . ') created event ' . $newEvent->evnt_title . ' (ID: ' . $newEvent->id . ').');
     // show new event
     return Redirect::action('CalendarController@showId', array('id' => $newEvent->id));
 }