Exemplo n.º 1
0
 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();
 }
Exemplo n.º 2
0
 public static function doSearch($term)
 {
     $data = ['users' => [], 'pages' => [], 'events' => [], 'committees' => []];
     $term = str_replace('%', '', $term);
     if (strlen($term) == 0) {
         return $data;
     }
     $term = explode(' ', $term);
     if (count($term) == 0) {
         return $data;
     }
     foreach ($term as $string) {
         $string = strtolower($string);
         if ($string == 'proto') {
             continue;
         }
         foreach (User::all() as $user) {
             if ((strlen($string) >= 3 && strpos(strtolower($user->name), $string) > -1 || strtolower($user->calling_name) == $string || $user->utwente_username && strlen($string) >= 5 && strpos(strtolower($user->utwente_username), $string) > -1 || intval($string) > 0 && $user->id == $string) && $user->member && Auth::check() && Auth::user()->member) {
                 if (array_key_exists($user->id, $data['users'])) {
                     $data['users'][$user->id]++;
                 } else {
                     $data['users'][$user->id] = 1;
                 }
             }
         }
         foreach (Page::all() as $page) {
             if ((strlen($string) >= 3 && strpos(strtolower($page->title), $string) > -1 || strlen($string) >= 3 && strpos(strtolower($page->content), $string) > -1) && (!$page->is_member_only || Auth::check() && Auth::user()->member)) {
                 if (array_key_exists($page->id, $data['pages'])) {
                     $data['pages'][$page->id] += substr_count(strtolower($page->title), $string) + substr_count(strtolower($page->content), $string);
                 } else {
                     $data['pages'][$page->id] = substr_count(strtolower($page->title), $string) + substr_count(strtolower($page->content), $string);
                 }
             }
         }
         foreach (Event::all() as $event) {
             if ((strlen($string) >= 3 && strpos(strtolower($event->title), $string) > -1 || strlen($string) >= 3 && strpos(strtolower($event->description), $string) > -1) && (!$event->secret || Auth::check() && Auth::user()->can('board'))) {
                 if (array_key_exists($event->id, $data['events'])) {
                     $data['events'][$event->id] += substr_count(strtolower($event->title), $string) + substr_count(strtolower($event->content), $string);
                 } else {
                     $data['events'][$event->id] = substr_count(strtolower($event->title), $string) + substr_count(strtolower($event->description), $string);
                     $data['events'][$event->id] -= SearchController::searchTimePenalty($event);
                 }
             }
         }
         foreach (Committee::all() as $committee) {
             if ((strlen($string) >= 3 && strpos(strtolower($committee->name), $string) > -1 || strlen($string) >= 3 && strpos(strtolower($committee->description), $string) > -1) && ($committee->public || Auth::check() && Auth::user()->can('board'))) {
                 if (array_key_exists($committee->id, $data['committees'])) {
                     $data['committees'][$committee->id] += substr_count(strtolower($committee->name), $string) + substr_count(strtolower($committee->description), $string);
                 } else {
                     $data['committees'][$committee->id] = substr_count(strtolower($committee->name), $string) + substr_count(strtolower($committee->description), $string);
                 }
             }
         }
     }
     arsort($data['users']);
     arsort($data['pages']);
     arsort($data['events']);
     arsort($data['committees']);
     return $data;
 }
Exemplo n.º 3
0
 /**
  * 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();
 }
Exemplo n.º 4
0
 /**
  * Display the homepage.
  */
 public function show()
 {
     $events = Event::where('secret', false)->where('start', '>=', date('U'))->orderBy('start')->limit(5)->get();
     $companies = Company::where('in_logo_bar', true)->get();
     if (Auth::check()) {
         $message = WelcomeMessage::where('user_id', Auth::user()->id)->first();
         return view('website.home.members', ['events' => $events, 'companies' => $companies, 'message' => $message]);
     } else {
         return view('website.home.external', ['events' => $events, 'companies' => $companies]);
     }
 }
Exemplo n.º 5
0
 /**
  * Execute the console command.
  */
 public function handle()
 {
     $newsletterlist = EmailList::findOrFail(config('proto.weeklynewsletter'));
     $events = Event::getEventsForNewsletter();
     if ($events->count() > 0) {
         $this->info('Sending weekly newsletter to ' . $newsletterlist->users->count() . ' people.');
         foreach ($newsletterlist->users as $user) {
             $email = $user->email;
             $name = $user->name;
             Mail::queue('emails.newsletter', ['user' => $user, 'list' => $newsletterlist], function ($message) use($email, $name) {
                 $message->to($email, $name)->from('internal@' . config('proto.emaildomain'), config('proto.internal'))->subject('S.A. Proto Weekly Newsletter (Week ' . date("W") . ')');
             });
         }
         $this->info("Done!");
     } else {
         $this->info("There are no upcomming activities.");
     }
 }
Exemplo n.º 6
0
 public function icalCalendar(Request $request)
 {
     $calendar = new IcalCalendar('-//HYTTIOAOAc//S.A. Proto Calendar//EN');
     $calendar->setName('S.A. Proto Calendar');
     $calendar->setDescription('All of Proto\'s events and happenings, straight from the website!');
     $calendar->setCalendarColor('#C1FF00');
     $calendar->setCalendarScale('GREGORIAN');
     $calendar->setMethod('PUBLISH');
     foreach (Event::where('secret', false)->where('start', '>', strtotime('-6 months'))->get() as $event) {
         $infotext = '';
         if ($event->over()) {
             $infotext = 'This activity is over.';
         } elseif ($event->activity !== null && $event->activity->participants == -1) {
             $infotext = 'Sign-up required, but no participant limit.';
         } elseif ($event->activity !== null && $event->activity->participants > 0) {
             $infotext = 'Sign-up required! There are roughly ' . $event->activity->freeSpots() . ' of ' . $event->activity->participants . ' places left.';
         } else {
             $infotext = 'No sign-up necessary.';
         }
         $component = (new IcalEvent())->setDtStart(new DateTime(date('d-m-Y H:i:s', $event->start)))->setDtEnd(new DateTime(date('d-m-Y H:i:s', $event->end)))->setSummary($event->title)->setDescription($infotext . ' More information: ' . route("event::show", ['id' => $event->id]))->setUseTimezone(true)->setLocation($event->location);
         if ($event->committee !== null) {
             $component->setOrganizer(new IcalOrganizer($event->committee->name));
         }
         $calendar->addComponent($component);
     }
     return Response::make($calendar->render())->header('Content-Type', 'text/calendar; charset=utf-8')->header('Content-Disposition', 'attachment; filename="protocalendar.ics"');
 }
Exemplo n.º 7
0
 public function newsletterPreview()
 {
     return view('emails.newsletter', ['user' => Auth::user(), 'list' => EmailList::find(config('proto.weeklynewsletter')), 'events' => Event::getEventsForNewsletter()]);
 }
Exemplo n.º 8
0
 /**
  * @return Event A collection of events for the weekly newsletter.
  */
 public static function getEventsForNewsletter()
 {
     return Event::where('secret', false)->where('start', '>', date('U'))->where('start', '<', strtotime('+4 weeks'))->orderBy('start')->get();
 }