Exemplo n.º 1
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.º 2
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.º 3
0
 /**
  * Handle the event.
  *
  * @param  Events $event
  * @return void
  */
 public function handle(User $user, $remember)
 {
     $token = new Token();
     $token->generate();
     Session::put('token', $token->token);
     // We will grant the user all roles to which he is entitled!
     $rootcommittee = Committee::where('slug', config('proto.rootcommittee'))->first();
     $boardcommittee = Committee::where('slug', config('proto.boardcommittee'))->first();
     $omnomcom = Committee::where('slug', config('proto.omnomcom'))->first();
     $pilscie = Committee::where('slug', config('proto.pilscie'))->first();
     if ($user->isInCommittee($rootcommittee)) {
         if (!$user->hasRole('admin')) {
             $user->attachRole(Role::where('name', '=', 'admin')->first());
         }
     } else {
         if ($user->hasRole('admin')) {
             $user->detachRole(Role::where('name', '=', 'admin')->first());
         }
     }
     if ($user->isInCommittee($boardcommittee)) {
         if (!$user->hasRole('board')) {
             $user->attachRole(Role::where('name', '=', 'board')->first());
         }
     } else {
         if ($user->hasRole('board')) {
             $user->detachRole(Role::where('name', '=', 'board')->first());
         }
     }
     if ($user->isInCommittee($omnomcom)) {
         if (!$user->hasRole('omnomcom')) {
             $user->attachRole(Role::where('name', '=', 'omnomcom')->first());
         }
     } else {
         if ($user->hasRole('omnomcom')) {
             $user->detachRole(Role::where('name', '=', 'omnomcom')->first());
         }
     }
     if ($user->isInCommittee($pilscie)) {
         if (!$user->hasRole('pilscie')) {
             $user->attachRole(Role::where('name', '=', 'pilscie')->first());
         }
     } else {
         if ($user->hasRole('pilscie')) {
             $user->detachRole(Role::where('name', '=', 'pilscie')->first());
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $event = Event::findOrFail($id);
     $event->title = $request->title;
     $event->start = strtotime($request->start);
     $event->end = strtotime($request->end);
     $event->location = $request->location;
     $event->secret = $request->secret;
     $event->description = $request->description;
     $event->summary = $request->summary;
     if ($request->file('image')) {
         $file = new StorageEntry();
         $file->createFromFile($request->file('image'));
         $event->image()->associate($file);
     }
     $committee = Committee::find($request->input('committee'));
     $event->committee()->associate($committee);
     $event->save();
     Session::flash("flash_message", "Your event '" . $event->title . "' has been saved.");
     return Redirect::route('event::edit', ['id' => $event->id]);
 }
Exemplo n.º 5
0
 public function isInCommitteeBySlug($slug)
 {
     $committee = Committee::where('slug', $slug)->first();
     return $committee && $this->isInCommittee($committee);
 }
Exemplo n.º 6
0
 /**
  * Committee membership tools below
  */
 public function addMembership(Request $request)
 {
     $user = User::find($request->user_id);
     $committee = Committee::find($request->committee_id);
     if ($user == null) {
         abort(404);
     }
     if ($committee == null) {
         abort(404);
     }
     if (($committee->slug == config('proto.rootcommittee') || $committee->slug == config('proto.boardcommittee')) && !Auth::user()->can('admin')) {
         Session::flash("flash_message", "This committee is protected. Only the Have You Tried Turning It Off And On Again committee can change this committee.");
         return Redirect::back();
     }
     $membership = new CommitteeMembership();
     $membership->role = $request->role;
     $membership->edition = $request->edition;
     $membership->user_id = $request->user_id;
     $membership->committee_id = $request->committee_id;
     if (($membership->created_at = date('Y-m-d H:i:s', strtotime($request->start))) === false) {
         Session::flash("flash_message", "Ill-formatted start date.");
         return Redirect::back();
     }
     if ($request->end != "" && ($membership->deleted_at = date('Y-m-d H:i:s', strtotime($request->end))) === false) {
         Session::flash("flash_message", "Ill-formatted end date.");
         return Redirect::back();
     }
     $membership->save();
     Session::flash("flash_message", "You have added " . $membership->user->name . " to " . $membership->committee->name . ".");
     return Redirect::back();
 }
Exemplo n.º 7
0
 private function syncCommitteeMembers($provider)
 {
     $groups = $provider->search()->groups()->get();
     $user2ldap = [];
     foreach ($groups as $group) {
         $this->info('Setting members for ' . $group->name[0] . '.');
         $committee = Committee::findOrFail($group->description[0]);
         $newmembers = [];
         foreach ($committee->users as $user) {
             if (!array_key_exists($user->id, $user2ldap)) {
                 $ldapuser = $provider->search()->where('objectClass', 'user')->where('description', $user->id)->first();
                 if ($ldapuser !== null) {
                     $user2ldap[$user->id] = $ldapuser;
                 } else {
                     $this->error("No LDAP user found for " . $user->name . ".");
                     continue;
                 }
             }
             if (!in_array($user2ldap[$user->id]->dn, $newmembers)) {
                 $newmembers[] = $user2ldap[$user->id]->dn;
             }
         }
         $group->setMembers($newmembers);
         $group->save();
     }
 }
Exemplo n.º 8
0
 /**
  * Display the most important page of the whole site.
  */
 public function developers()
 {
     $committee = Committee::where('slug', '=', config('proto.rootcommittee'))->first();
     $developers = ['current' => CommitteeMembership::where('committee_id', $committee->id)->groupBy('user_id')->get(), 'old' => CommitteeMembership::withTrashed()->where('committee_id', $committee->id)->whereNotNull('deleted_at')->orderBy('created_at', 'ASC')->groupBy('user_id')->get()];
     return view('website.developers', ['developers' => $developers, 'committee' => $committee]);
 }
Exemplo n.º 9
0
 private function constructForwarderList()
 {
     $data = [];
     // Constructing user forwarders.
     $users = User::all();
     foreach ($users as $user) {
         if ($user->member && $user->isActiveMember()) {
             $data[$user->member->proto_username] = [$user->email];
         }
     }
     // Constructing committee forwarders.
     $committees = Committee::all();
     foreach ($committees as $committee) {
         $destinations = [];
         $users = CommitteeMembership::withTrashed()->where('committee_id', $committee->id)->where('created_at', '<', date('Y-m-d H:i:s'))->where(function ($q) {
             $q->whereNull('deleted_at')->orWhere('deleted_at', '>', date('Y-m-d H:i:s'));
         })->get();
         foreach ($users as $user) {
             $destinations[] = $user->user->email;
         }
         if (count($destinations) > 0) {
             $data[$committee->slug] = $destinations;
             $data['committees'][] = $committee->slug . '@' . config('proto.emaildomain');
         }
     }
     // Constructing manual aliases.
     $aliases = Alias::all();
     foreach ($aliases as $alias) {
         if ($alias->destination) {
             $data[$alias->alias][] = $alias->destination;
         } else {
             $data[$alias->alias][] = $alias->user->email;
         }
     }
     return $data;
 }