Exemplo n.º 1
0
 /**
  * Display the profile for a specific user.
  *
  * @param  int $id
  * @return \Illuminate\Http\Response
  */
 public function show($id = null)
 {
     if ($id == null) {
         $id = Auth::id();
     }
     $user = User::find($id);
     if ($user == null) {
         abort(404);
     }
     $ldap = $user->getUtwenteData();
     $pastCommittees = CommitteeMembership::onlyTrashed()->where('user_id', $user->id)->orderBy('created_at', 'desc')->get();
     return view('users.profile.profile', ['user' => $user, 'ldap' => $ldap, 'pastcommittees' => $pastCommittees]);
 }
Exemplo n.º 2
0
 /**
  * @return bool Whether the user is an active member of the association.
  */
 public function isActiveMember()
 {
     return count(CommitteeMembership::withTrashed()->where('user_id', $this->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()) > 0;
 }
Exemplo n.º 3
0
 public function deleteMembership($id)
 {
     $membership = CommitteeMembership::withTrashed()->findOrFail($id);
     if ($membership->committee->slug == config('proto.rootcommittee') && !Auth::user()->can('admin')) {
         Session::flash("flash_message", "This committee is protected. You cannot delete members from this committee if you are not in it.");
         return Redirect::back();
     }
     if ($membership->user->id == Auth::id() && !Auth::user()->can('admin')) {
         Session::flash("flash_message", "You cannot remove yourself from a committee. Please ask someone else to do so.");
         return Redirect::back();
     }
     Session::flash("flash_message", "You have removed " . $membership->user->name . " from " . $membership->committee->name . ".");
     $committee_id = $membership->committee->id;
     $membership->forceDelete();
     return Redirect::route("committee::edit", ["id" => $committee_id]);
 }
Exemplo n.º 4
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.º 5
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;
 }
Exemplo n.º 6
0
 /**
  * @param User $user The user to check membership for.
  * @return bool Whether the user is currently a member of this committee.
  */
 public function isMember(User $user)
 {
     return count(CommitteeMembership::whereNull('committees_users.deleted_at')->where('user_id', $user->id)->where('committee_id', $this->id)->get()) > 0;
 }