/**
  * Create a new participation for somebody else.
  *
  * @return \Illuminate\Http\Response
  */
 public function createFor($id, Request $request)
 {
     $user = User::findOrFail($request->user_id);
     $event = Event::findOrFail($id);
     $data = ['activity_id' => $event->activity->id, 'user_id' => $user->id];
     if ($request->has('helping_committee_id')) {
         $helping = HelpingCommittee::findOrFail($request->helping_committee_id);
         if (!$helping->committee->isMember($user)) {
             abort(500, $user->name . " is not a member of the " . $helping->committee->name . " and thus cannot help on behalf of it.");
         }
         $data['committees_activities_id'] = $helping->id;
     }
     if (!$event->activity) {
         abort(500, "You cannot subscribe for " . $event->title . ".");
     } elseif ($event->activity->getParticipation($user, $request->has('helping_committee_id') ? HelpingCommittee::findOrFail($request->input('helping_committee_id')) : null) !== null) {
         abort(500, "You are already subscribed for " . $event->title . ".");
     } elseif ($event->activity->closed) {
         abort(500, "This activity is closed, you cannot change participation anymore.");
     }
     $request->session()->flash('flash_message', 'You added ' . $user->name . ' for ' . $event->title . '.');
     $participation = new ActivityParticipation();
     $participation->fill($data);
     $participation->save();
     return Redirect::back();
 }
Example #2
0
 /**
  * @param Committee $committee The committee for which the user should be helping.
  * @param User $user The user to check helping status for.
  * @return ActivityParticipation|null Return the ActivityParticipation for the supplied user and committee in combination with this activity. Returns null if there is none.
  */
 public function getHelpingParticipation(Committee $committee, User $user)
 {
     $h = HelpingCommittee::where('activity_id', $this->id)->where('committee_id', $committee->id)->first();
     if ($h === null) {
         return null;
     }
     $p = ActivityParticipation::where('activity_id', $this->id)->where('user_id', $user->id)->where('committees_activities_id', $h->id)->first();
     return $p;
 }
Example #3
0
 public function deleteHelp(Request $request, $id)
 {
     $help = HelpingCommittee::findOrFail($id);
     foreach ($help->users as $user) {
         $name = $user->name;
         $email = $user->email;
         $helptitle = $help->activity->event->title;
         Mail::queue('emails.committeehelpnotneeded', ['user' => $user, 'help' => $help], function ($m) use($name, $email, $helptitle) {
             $m->replyTo('*****@*****.**', 'S.A. Proto');
             $m->to($email, $name);
             $m->subject('The activity ' . $helptitle . ' doesn\'t need your help anymore.');
         });
     }
     foreach (ActivityParticipation::withTrashed()->where('committees_activities_id', $help->id)->get() as $participation) {
         $participation->delete();
     }
     $help->delete();
     $request->session()->flash('flash_message', 'Removed ' . $help->committee->name . ' as helping committee.');
     return Redirect::back();
 }