Example #1
0
 /**
  * Show form to manage resource for a plan
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request, $plan_id)
 {
     // get current plan with resources
     $plan = Plan::with('resources')->find($plan_id);
     // get FULL list of resources
     $resources = Resource::get();
     // return view
     if ($plan) {
         return view('cspot.resources', ['plan' => $plan, 'resources' => $resources]);
     }
     flashError('Plan with ID "' . $id . '" not found');
     return redirect()->back();
 }
Example #2
0
 /**
  * PERMANENTLY DELETE an item 
  *
  */
 public function permDelete($id)
 {
     $item = Item::onlyTrashed()->find($id);
     if (!$item) {
         flash('Error! Item with ID "' . $id . '" not found! (F:permDelete)');
         return redirect()->back();
     }
     // check if user is leader of the corresponding plan or author/admin
     if ($item->plan->leader_id == Auth::user()->id || Auth::user()->isAuthor()) {
         $item->forceDelete();
         flash('Trashed item with id ' . $id . ' deleted permanently');
         return \Redirect::back();
     }
     flashError('Sorry, only plan leader or Author can delete items');
     return redirect()->back();
 }
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     //
     // find a single resource by ID
     $output = Type::find($id);
     if ($output) {
         $plans = $output->plans()->get();
         if (count($plans)) {
             flashError('Type "' . $output->name . '" is still referred by Plans and cannot be deleted.');
             return redirect()->back();
         }
         $output->delete();
         $message = 'Type with id "' . $id . '" deleted.';
         return \Redirect::route('types.index')->with(['status' => $message]);
     }
     //
     $message = 'Error! Type with ID "' . $id . '" not found';
     return \Redirect::route('types.index')->with(['status' => $message]);
 }
Example #4
0
/**
 * Trigger certain actions when leader or teacher of a plan was changed
 *
 * a) send notification to each invovled
 * b) change the team accordingly
 *
 * @param Request $request all data from the HTTP request (the new data)
 * @param EloquentModel $plan  (the old data)
 */
function checkIfLeaderOrTeacherWasChanged($request, $plan)
{
    $msg = false;
    // check if LEADER was changed
    if ($plan->leader_id != $request->leader_id) {
        // check if reason was given for the change
        if (!$request->has('reasonForChange')) {
            flashError('Please provide reason for the change of leader!');
            return false;
        }
        // find the corresponding team record for the leader
        $leader = Team::where([['plan_id', $plan->id], ['role_id', env('LEADER_ID', 4)]]);
        if ($leader->count()) {
            // update the team record
            $leader->update(['user_id' => $request->leader_id]);
        } else {
            // create a new team member...
            $plan->leader_id = $request->leader_id;
            addDefaultRolesAndResourcesToPlan($plan);
        }
        // affected users must be notified of this change accordingly
        $new_leader = User::find($request->leader_id);
        $recipient = $new_leader->id;
        $subject = 'Leader changed for Event on ' . Carbon::parse($plan->date)->format('l, jS \\of F Y');
        $msg = Auth::user()->name . ' changed the leader for this ' . $plan->type->name . ' from ' . $plan->leader->name . ' to ' . $new_leader->name;
    }
    // check if TEACHER was changed
    if ($plan->teacher_id != $request->teacher_id) {
        // check if a reason was given for the change
        if (!$request->has('reasonForChange')) {
            flashError('Please provide reason for the change of teacher!');
            return false;
        }
        // find the corresponding team record for the teacher
        $teacher = Team::where([['plan_id', $plan->id], ['role_id', env('TEACHER_ID', 5)]]);
        if ($teacher->count()) {
            // update the team record
            $teacher->update(['user_id' => $request->teacher_id]);
        } else {
            // create a new team member...
            $plan->teacher_id = $request->teacher_id;
            addDefaultRolesAndResourcesToPlan($plan);
        }
        // affected users must be notified of this change accordingly
        $new_teacher = User::find($request->teacher_id);
        $recipient = $new_teacher->id;
        $subject = 'Teacher changed for Event on ' . Carbon::parse($plan->date)->format('l, jS \\of F Y');
        $msg = Auth::user()->name . ' changed the teacher for this ' . $plan->type->name . ' from ' . $plan->teacher->name . ' to ' . $new_teacher->name;
    }
    if ($msg) {
        // send internal notification and message
        sendInternalMessage($subject, $msg, $recipient);
        Log::info($subject . ' - ' . $msg);
        // also create a history record for this change
        $history = new History(['user_id' => Auth::user()->id, 'changes' => $subject . "\n" . $msg, 'reason' => $request->reasonForChange]);
        $plan->histories()->save($history);
    }
    return true;
}
Example #5
0
 /**
  * Remove the specified plan from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // find a single plan by ID
     $plan = Plan::find($id);
     if ($plan) {
         $items = $plan->items()->withTrashed()->get();
         if (count($items)) {
             flashError('Plan with ID "' . $id . '" still contains items (incl. binned items) and cannot be deleted. Please review this plan now.');
             return $this->edit($id);
         }
         // delete team members for this plan (if any)
         $plan->teams()->delete();
         // delete resources for this plan (if any)
         $plan->resources()->detach();
         // as it is a Many-To-Many relationship....
         // delete the plan
         $plan->delete();
         flash('Plan with id "' . $id . '" deleted.');
         return \Redirect::route($this->view_idx, ['filterby' => 'future']);
     }
     //
     flashError('Plan with ID "' . $id . '" not found');
     return redirect()->back();
 }