Exemplo n.º 1
0
 public static function lookup_conferences($params, $flags)
 {
     $search = [];
     $year = null;
     foreach ($params as $k => $v) {
         if (empty($year) && preg_match("/^[0-9]{4}\$/", $v)) {
             $year = $v;
         } else {
             $search[] = $v;
         }
     }
     if (is_array($flags)) {
         $flags = (object) $flags;
     }
     // Start by getting all conferences
     $conferences = Conference::whereNotNull('start_date')->whereNotNull('end_date');
     // If a year is specified, limit search
     if (!empty($year)) {
         $conferences->year($year);
     }
     // If other search criteria were specified, limit search
     if (count($search) > 0) {
         $conferences->lookup($search);
     }
     // Flags will limit search
     if (is_object($flags)) {
         if (self::flags($flags, 'upcoming') && self::flags($flags, 'current')) {
             $conferences->upcomingOrCurrent();
         } elseif (self::flags($flags, 'past') && self::flags($flags, 'current')) {
             $conferences->pastOrCurrent();
         } elseif (self::flags($flags, 'upcoming')) {
             $conferences->upcoming();
         } elseif (self::flags($flags, 'current')) {
             $conferences->current();
         } elseif (self::flags($flags, 'past')) {
             $conferences->past();
         }
         if (self::flags($flags, 'published')) {
             $conferences->published();
         }
         if (self::flags($flags, 'home')) {
             $conferences->take(3);
         } elseif (!empty($flags->take) && is_int($flags->take)) {
             $conferences->take($flags->take);
         }
     }
     if (is_object($flags)) {
         if (self::flags($flags, 'latest')) {
             $conferences->orderBy('start_date', 'desc');
         } elseif (isset($flags->orderby)) {
             foreach ($flags->orderby as $order) {
                 list($by, $direction) = explode($order);
                 if (!empty($direction)) {
                     $conferences->orderBy($by, $direction);
                 } else {
                     $conferences->orderBy($by);
                 }
             }
         } else {
             $conferences->orderBy('start_date');
         }
         if (self::flags($flags, 'first')) {
             $conferences = $conferences->take(1)->get();
         } elseif (self::flags($flags, 'latest')) {
             $conferences = $conferences->take(1)->get();
         } elseif (self::flags($flags, 'take')) {
             $conferences = $conferences->take($flags->take)->get();
         } else {
             $conferences = $conferences->get();
         }
     } else {
         $conferences = $conferences->get();
     }
     $events = self::collectionToArray($conferences);
     return $events;
 }