Esempio 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;
 }
Esempio n. 2
0
 private function syncCommittees($provider)
 {
     $activeIds = [];
     $this->info("Make sure all committees exist in LDAP.");
     foreach (Committee::all() as $committee) {
         $activeIds[] = $committee->id;
         $group = $provider->search()->where('objectClass', 'group')->where('description', $committee->id)->first();
         if ($group == null) {
             $this->info('Creating LDAP group for ' . $committee->name . '.');
             $group = $provider->make()->group();
             $group->cn = trim($committee->name);
             $group->description = $committee->id;
             $group->save();
         }
         $group->move('cn=' . trim($committee->name), 'OU=Committees,OU=Proto,DC=ad,DC=saproto,DC=nl');
         $group->displayName = trim($committee->name);
         $group->description = $committee->id;
         $group->mail = $committee->slug . '@' . config('proto.emaildomain');
         $group->url = route("committee::show", ['id' => $committee->id]);
         $group->setAttribute('sAMAccountName', $committee->slug);
         $group->save();
     }
     $this->info("Removing obsolete committees from LDAP.");
     $committees = $provider->search()->groups()->get();
     foreach ($committees as $group) {
         if (!$group->description[0] || !in_array($group->description[0], $activeIds)) {
             $this->info("Deleting LDAP group " . $group->description[0] . ".");
             $group->delete();
         }
     }
 }
Esempio n. 3
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;
 }