|
| 1 | +<?php |
| 2 | + |
| 3 | +// compile home page data |
| 4 | +$now = new DateTime(); |
| 5 | +$pageData = array(); |
| 6 | + |
| 7 | + |
| 8 | +// meetups |
| 9 | + try { |
| 10 | + $meetups = Emergence\Meetup\Connector::getUpcomingEvents(); |
| 11 | + $nextMeetup = array_shift($meetups); |
| 12 | + |
| 13 | + // detect if meetup is happening right now |
| 14 | + // - use ?next_meetup_now=1 to test feature before any event |
| 15 | + if( |
| 16 | + ($nextMeetup && $nextMeetup['time_start'] < $now) |
| 17 | + || !empty($_GET['next_meetup_now']) |
| 18 | + ) { |
| 19 | + $currentMeetup = $nextMeetup; |
| 20 | + $nextMeetup = array_shift($meetups); |
| 21 | + } |
| 22 | + |
| 23 | + if($currentMeetup) { |
| 24 | + $currentMeetup['checkins'] = Laddr\MemberCheckin::getAllForMeetupByProject($currentMeetup['id']); |
| 25 | + } |
| 26 | + |
| 27 | + $pageData['currentMeetup'] = $currentMeetup; |
| 28 | + $pageData['nextMeetup'] = $nextMeetup; |
| 29 | + $pageData['futureMeetups'] = $meetups; |
| 30 | + } catch (Exception $e) { |
| 31 | + // just omit meetup data |
| 32 | + } |
| 33 | + |
| 34 | + |
| 35 | +// build activity stream |
| 36 | + if (!$pageData['activity'] = Cache::fetch('home-activity')) { |
| 37 | + $existingTables = \DB::allValues('table_name', 'SELECT table_name FROM information_schema.TABLES WHERE TABLE_SCHEMA = SCHEMA()'); |
| 38 | + $activityQueries = []; |
| 39 | + |
| 40 | + if (in_array(Emergence\CMS\AbstractContent::$tableName, $existingTables)) { |
| 41 | + $activityQueries[] = sprintf( |
| 42 | + 'SELECT' |
| 43 | + .' ID, Class, Published AS Timestamp' |
| 44 | + .' FROM `%s`' |
| 45 | + .' WHERE' |
| 46 | + .' Class = "%s" AND' |
| 47 | + .' Visibility = "Public" AND' |
| 48 | + .' Status = "Published" AND' |
| 49 | + .' (Published IS NULL OR Published <= CURRENT_TIMESTAMP)', |
| 50 | + Emergence\CMS\AbstractContent::$tableName, |
| 51 | + DB::escape(Emergence\CMS\BlogPost::class) |
| 52 | + ); |
| 53 | + } |
| 54 | + /* |
| 55 | + if (in_array(Laddr\ProjectUpdate::$tableName, $existingTables)) { |
| 56 | + $activityQueries[] = sprintf('SELECT ID, Class, Created AS Timestamp FROM `%s`', Laddr\ProjectUpdate::$tableName); |
| 57 | + } |
| 58 | +
|
| 59 | + if (in_array(Laddr\ProjectBuzz::$tableName, $existingTables)) { |
| 60 | + $activityQueries[] = sprintf('SELECT ID, Class, Published AS Timestamp FROM `%s`', Laddr\ProjectBuzz::$tableName); |
| 61 | + } |
| 62 | + */ |
| 63 | + if (count($activityQueries)) { |
| 64 | + $pageData['activity'] = array_map( |
| 65 | + function($result) { |
| 66 | + return $result['Class']::getByID($result['ID']); |
| 67 | + } |
| 68 | + ,DB::allRecords(implode(' UNION ', $activityQueries).' ORDER BY Timestamp DESC LIMIT 10') |
| 69 | + ); |
| 70 | + } else { |
| 71 | + $pageData['activity'] = []; |
| 72 | + } |
| 73 | + Cache::store('home-activity', $pageData['activity'], 30); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | +// render data against home template |
| 78 | +RequestHandler::respond('home', $pageData); |
0 commit comments