/**
  * Generate the view for editing a task specified by $id.
  *
  * @param int $id
  * @return view editTaskView
  */
 public function showEditTask($id)
 {
     $schedule = Schedule::findOrFail($id);
     $entries = $schedule->getEntries()->with('getJobType')->GetResults();
     $jobtypes = Jobtype::where('jbtyp_is_archived', '=', '0')->orderBy('jbtyp_title', 'ASC')->get();
     return View::make('editTaskView', compact('schedule', 'jobtypes', 'entries'));
 }
 /**
  * Updates all existing job types with changes provided.
  *
  * @return view jobManagementView
  */
 public function updateJobTypes()
 {
     $jobtypes = Jobtype::orderBy('jbtyp_title', 'ASC')->get();
     foreach ($jobtypes as $jobtype) {
         $jobtype->jbtyp_title = Input::get('jbtyp_title' . $jobtype->id);
         $jobtype->jbtyp_time_start = Input::get('jbtyp_time_start' . $jobtype->id);
         $jobtype->jbtyp_time_end = Input::get('jbtyp_time_end' . $jobtype->id);
         $jobtype->jbtyp_statistical_weight = Input::get('jbtyp_statistical_weight' . $jobtype->id);
         $jobtype->jbtyp_is_archived = Input::get('jbtyp_is_archived' . $jobtype->id);
         /*if (Input::get('destroy' . $jobtype->id)) {
         			//ToDo: need to find all schedules that use it and clean them here first.
         			$jobtype->delete(); 
         		} */
         $jobtype->save();
     }
     return View::make('jobManagementView', compact('jobtypes'));
 }
 /**
  * Edit and/or delete scheduleEntries refered to $scheduleId.
  *
  * @param Schedule $schedule
  * @return Collection scheduleEntries
  */
 public static function editScheduleEntries($scheduleId)
 {
     // get number of submitted entries
     $numberOfSubmittedEntries = Input::get('counter');
     // get old entries for this schedule
     $scheduleEntries = ScheduleEntry::where('schdl_id', '=', $scheduleId)->get();
     // prepare a collection for updated entries
     $newEntries = new Collection();
     // Counter to traverse all inputs from 1 to N
     $counterHelper = '1';
     // check for changes in each entry
     foreach ($scheduleEntries as $entry) {
         // same job type as before - do nothing
         if ($entry->getJobType == Input::get('jobType' + $counterHelper)) {
             // add to new collection
             $newEntries->add(ScheduleController::updateScheduleEntry($entry, $jobtype->id, $counterHelper));
         } elseif (Input::get("jobType" . $counterHelper) == '') {
             // log revision
             ScheduleController::logRevision($entry->getSchedule, $entry, "Dienst gelöscht", $entry->getPerson, null);
             // new value
             // proceed with deletion
             $entry->delete();
         } else {
             $jobtype = Jobtype::firstOrCreate(array('jbtyp_title' => Input::get("jobType" . $counterHelper)));
             $entry->jbtyp_id = $jobtype->id;
             // log revision
             /*
             ScheduleController::logRevision($entry->getSchedule, 	// schedule object
             								$entry,					// entry object
             								"Dienst aktualisiert",		// action description
             								$entry->getPerson,		// old value
             								$entry->getPerson);		// new value
             */
             // add to new collection
             $newEntries->add(ScheduleController::updateScheduleEntry($entry, $jobtype->id, $counterHelper));
         }
         // move to next input
         $counterHelper++;
     }
     // At this point we changed all existing entries - have any new ones been added?
     if ($numberOfSubmittedEntries > $counterHelper - 1) {
         // create some new fields
         for ($i = $counterHelper; $i <= $numberOfSubmittedEntries; $i++) {
             // skip empty fields, create new fields only if input not empty
             if (!empty(Input::get("jobType" . $i))) {
                 $jobtype = Jobtype::firstOrCreate(array('jbtyp_title' => Input::get("jobType" . $i)));
                 $newEntry = new ScheduleEntry();
                 $newEntry->jbtyp_id = $jobtype->id;
                 $newEntry->schdl_id = $scheduleId;
                 // log revision
                 ScheduleController::logRevision($newEntry->getSchedule, $newEntry, "Dienst erstellt", null, null);
                 // new value
                 // add to new collection
                 $newEntries->add(ScheduleController::updateScheduleEntry($newEntry, $jobtype->id, $i));
             }
         }
     }
     return $newEntries;
 }
 public function run()
 {
     Eloquent::unguard();
     /**
      * Clearing table
      */
     DB::table('jobtypes')->delete();
     /**
      * Creating regular job types
      */
     Jobtype::create(array('jbtyp_title' => 'Einlass', 'jbtyp_statistical_weight' => '1', 'jbtyp_is_archived' => '0'));
     Jobtype::create(array('jbtyp_title' => 'Bar', 'jbtyp_statistical_weight' => '2', 'jbtyp_is_archived' => '0'));
     Jobtype::create(array('jbtyp_title' => 'Tresen', 'jbtyp_statistical_weight' => '2', 'jbtyp_is_archived' => '0'));
     Jobtype::create(array('jbtyp_title' => 'Disko', 'jbtyp_statistical_weight' => '2', 'jbtyp_is_archived' => '0'));
     Jobtype::create(array('jbtyp_title' => 'Licht', 'jbtyp_statistical_weight' => '1', 'jbtyp_is_archived' => '0'));
     Jobtype::create(array('jbtyp_title' => 'Buy beer', 'jbtyp_statistical_weight' => '10', 'jbtyp_is_archived' => '0'));
     Jobtype::create(array('jbtyp_title' => 'Drink beer', 'jbtyp_statistical_weight' => '30', 'jbtyp_is_archived' => '0'));
     /**
      * Reporting result to console
      */
     $this->command->info('Example job types created.');
 }
 /**
  * Generate the view for editing an event specified by $id.
  *
  * @param int $id
  * @return view editClubEventView
  */
 public function showEditEvent($id)
 {
     $event = ClubEvent::findOrFail($id);
     $schedule = $event->getSchedule()->getResults();
     $jobtypes = Jobtype::where('jbtyp_is_archived', '=', '0')->orderBy('jbtyp_title', 'ASC')->get();
     $places = Place::orderBy('plc_title', 'ASC')->lists('plc_title', 'id');
     $templates = Schedule::where('schdl_is_template', '=', '1')->orderBy('schdl_title', 'ASC')->get();
     $template = Schedule::where('id', '=', $schedule->id)->first();
     // put template data into entries
     $entries = $schedule->getEntries()->with('getJobType')->getResults();
     // put name of the active template for further use
     $activeTemplate = $template->schdl_title;
     return View::make('editClubEventView', compact('event', 'schedule', 'places', 'jobtypes', 'templates', 'template', 'entries', 'activeTemplate'));
 }