/**
  * Get future events.
  *
  * @param   QueryBuilder  $query
  * @return  QueryBuilder
  */
 public function scopeUpcoming($query)
 {
     return $query->where('ends_at', '>', Carbon::create());
 }
 /**
  * Get events by Facebook event id.
  *
  * @param   QueryBuilder  $query
  * @param   array         $facebookIds
  * @return  QueryBuilder
  */
 public function scopeFacebook($query, array $facebookIds)
 {
     return $query->where('provider', '=', self::PROVIDER_FACEBOOK)->whereIn('external_user_id', $facebookIds);
 }
Example #3
0
 /**
  * Filter visible areas.
  *
  * @param   QueryBuilder  $query
  * @return  QueryBuilder
  */
 public function scopeIsVisible($query)
 {
     return $query->where('is_hidden', '<>', true);
 }
Example #4
0
 /**
  * Search models
  *
  * @param   QueryBuilder  $query
  * @param   string        $search
  * @return  QueryBuilder
  */
 public function scopeSearch($query, $search)
 {
     $search = trim($search);
     if (strlen($search)) {
         // Parse search
         $name = [];
         $venue = [];
         $city = [];
         $words = explode(' ', mb_strtolower($search));
         foreach ($words as $word) {
             $tokens = explode(':', $word, 2);
             // Defaults to event name
             if (count($tokens) == 1) {
                 $name[] = $word;
                 continue;
             }
             switch ($tokens[0]) {
                 case 'city':
                 case 'in':
                     $city[] = $tokens[1];
                     break;
                 case 'venue':
                 case 'at':
                     $venue[] = $tokens[1];
                     break;
                 default:
                     $name[] = $word;
             }
         }
         $query->where(function ($query) use($name, $venue, $city) {
             if ($name) {
                 $query->searchWhere(implode(' ', $name), 'name');
             }
             $query->whereHas('event', function ($query) use($name, $venue, $city) {
                 if ($name) {
                     $query->searchWhere(implode(' ', $name), 'name');
                 }
                 if ($venue) {
                     $query->searchWhere(implode(' ', $venue), 'venue_name');
                 }
                 if ($city) {
                     $query->searchWhere(implode(' ', $city), 'city_name');
                 }
             });
         });
     }
     return $query;
 }
Example #5
0
 /**
  * Use the write pdo for query.
  *
  * @return $this 
  * @static 
  */
 public static function useWritePdo()
 {
     //Method inherited from \Illuminate\Database\Query\Builder
     return \October\Rain\Database\QueryBuilder::useWritePdo();
 }
Example #6
0
 /**
  * Search topics and posts.
  *
  * @param   QueryBuilder  $query
  * @param   string        $search
  * @param   bool          $includePosts
  * @return  QueryBuilder
  */
 public function scopeSearch($query, $search, $includePosts = True)
 {
     $search = trim($search);
     if (strlen($search)) {
         $parsed = Search::parseQuery($search, ['topic', 'post'], ['topic' => 'topic', 'post' => 'post', 'author' => 'author', 'by' => 'author']);
         // Search authors?
         $authors = !empty($parsed['author']) ? User::whereIn(DB::raw('LOWER(username)'), $parsed['author'])->lists('id') : [];
         $query->where(function ($query) use($parsed, $authors, $includePosts) {
             if (!empty($parsed['topic'])) {
                 $query->searchWhere(implode(' ', $parsed['topic']), 'name');
                 if ($authors && empty($parsed['post'])) {
                     $query->whereIn('author_id', $authors);
                 }
             }
             if ($includePosts && !empty($parsed['post'])) {
                 $query->orWhereHas('posts', function ($query) use($parsed, $authors) {
                     $query->searchWhere(implode(' ', $parsed['post']), 'post');
                     if ($authors) {
                         $query->whereIn('author_id', $authors);
                     }
                 });
             }
         });
     }
     return $query;
 }
 /**
  * Get events by Facebook event id.
  *
  * @param   QueryBuilder  $query
  * @param   array         $facebookIds
  * @return  QueryBuilder
  */
 public function scopeFacebook($query, array $facebookIds)
 {
     return $query->whereIn('facebook_id', $facebookIds);
 }
Example #8
0
 /**
  * Search topics and posts.
  *
  * @param   QueryBuilder  $query
  * @param   string        $search
  * @return  QueryBuilder
  */
 public function scopeSearch($query, $search)
 {
     $parsed = Search::parseQuery($search, ['post'], ['post' => 'post', 'author' => 'author', 'by' => 'author']);
     // Search authors
     $authors = !empty($parsed['author']) ? User::whereIn(DB::raw('LOWER(username)'), $parsed['author'])->lists('id') : [];
     if ($authors) {
         $query->whereIn('author_id', $authors);
     }
     // Search posts
     if (!empty($parsed['post'])) {
         $query->searchWhere(implode(' ', $parsed['post']), 'post');
     }
     return $query;
 }