Example #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;
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $course = new Course();
     $page = Page::findOrFail($request->page);
     $study = Study::findOrFail($request->study);
     $course->study()->associate($study);
     $course->page()->associate($page);
     $course->quartile = $request->quartile;
     $course->save();
     return redirect(route("course::list"));
 }
Example #3
0
 public function getUrl()
 {
     if ($this->page_id == null) {
         return $this->url;
     } else {
         $page = Page::find($this->page_id);
         if ($page) {
             return $page->getUrl();
         }
         return "#";
     }
 }
Example #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)
 {
     $menuItem = MenuItem::findOrFail($id);
     $menuItem->fill($request->all());
     if ($request->has('is_member_only')) {
         $menuItem->is_member_only = true;
     } else {
         $menuItem->is_member_only = false;
     }
     if ($request->page_id == 0) {
         $menuItem->page_id = null;
     }
     if ($request->parent == 0) {
         $menuItem->parent = null;
     }
     if ($menuItem->page_id) {
         $menuItem->url = Page::find($menuItem->page_id)->getUrl();
     }
     $menuItem->save();
     return Redirect::route("menu::list");
 }
Example #5
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $page = Page::findOrfail($id);
     Session::flash('flash_message', 'Page ' . $page->title . ' has been removed.');
     $page->delete();
     return Redirect::route('page::list');
 }