public function addHelp(Request $request, $id) { $event = Event::findOrFail($id); if (!$event->activity) { $request->session()->flash('flash_message', 'This event has no activity data.'); return Redirect::back(); } $amount = $request->input('amount'); if ($amount < 1) { $request->session()->flash('flash_message', 'The amount of helpers should be positive.'); return Redirect::back(); } $committee = Committee::findOrFail($request->input('committee')); $help = HelpingCommittee::create(['activity_id' => $event->activity->id, 'committee_id' => $committee->id, 'amount' => $amount]); foreach ($committee->users as $user) { $name = $user->name; $email = $user->email; $helptitle = $help->activity->event->title; Mail::queue('emails.committeehelpneeded', ['user' => $user, 'help' => $help], function ($m) use($name, $email, $helptitle) { $m->replyTo('*****@*****.**', 'S.A. Proto'); $m->to($email, $name); $m->subject('The activity ' . $helptitle . ' needs your help.'); }); } $request->session()->flash('flash_message', 'Added ' . $committee->name . ' as helping committee.'); return Redirect::back(); }
/** * 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(); }
public function search(Request $request) { $term = $request->input('query'); $data = SearchController::doSearch($term); $aggregate = []; foreach ($data['users'] as $id => $count) { $aggregate[] = ['score' => $count, 'object' => User::findOrFail($id), 'href' => route('user::profile', ['id' => $id])]; } foreach ($data['pages'] as $id => $count) { $page = Page::findOrFail($id); $aggregate[] = ['score' => $count, 'object' => $page, 'href' => route('page::show', ['slug' => $page->slug])]; } foreach ($data['committees'] as $id => $count) { $aggregate[] = ['score' => $count, 'object' => Committee::findOrFail($id), 'href' => route('committee::show', ['id' => $id])]; } foreach ($data['events'] as $id => $count) { $aggregate[] = ['score' => $count, 'object' => Event::findOrFail($id), 'href' => route('event::show', ['id' => $id])]; } usort($aggregate, function ($a, $b) { return $b['score'] - $a['score']; }); return view('website.search', ['term' => $term, 'data' => $aggregate]); }
public function apiEventsMembers($id, Request $request) { if (!Auth::check() || !Auth::user()->member) { abort(403); } $activities = Event::findOrFail($id)->activity->users; $data = array(); foreach ($activities as $activity) { $item = new \stdClass(); $item->id = $activity->id; $item->email = $activity->email; $item->name = $activity->name; $item->birthdate = $activity->birthdate; $item->gender = $activity->gender; $data[] = $item; } return $data; }