0 ) { if ( $image[ 0 ][ 0 ] != '' ) { return $image[ 0 ][ 0 ]; } else { return false; } } } static public function getURLs( $googleEvent ) { preg_match_all( self::$urlMatch, $googleEvent[ 'description' ], $url, PREG_PATTERN_ORDER ); if ( sizeof( $url[ 0 ] ) > 0 ) { if ( $url[ 0 ][ 0 ] != '' ) { return $url[ 0 ][ 0 ]; } else { return false; } } } static public function removeImages( $googleEvent ) { preg_match_all( self::$imageMatch, $googleEvent[ 'description' ], $image, PREG_PATTERN_ORDER ); return preg_replace( self::$imageMatch, '', $googleEvent[ 'description' ] ); } static public function removeURLs( $googleEvent ) { preg_match_all( self::$urlMatch, $googleEvent[ 'description' ], $url, PREG_PATTERN_ORDER ); return preg_replace( self::$urlMatch, '', $googleEvent[ 'description' ] ); } static public function getEvents ( $app ) { $googleCalendar = Helpers::JSON2Array( $app[ 'cache' ][ 'calendar' ][ 'json' ] ); foreach( $googleCalendar[ 'items' ] as $googleEvent ) { unset( $event ); $event = self::getEventDateTime( $googleEvent ); $event[ 'name' ] = $googleEvent[ 'summary' ]; if ( array_key_exists( 'location' , $googleEvent ) ){ $event[ 'location' ] = $googleEvent[ 'location' ]; } $event[ 'image' ] = false; $event[ 'url' ] = false; if ( array_key_exists( 'description' , $googleEvent ) ){ $event[ 'description' ] = $googleEvent[ 'description' ]; $event[ 'image' ] = self::getImages( $event ); $event[ 'description' ] = self::removeImages( $event ); $event[ 'url' ] = self::getURLs( $event ); $event[ 'description' ] = self::removeURLs( $event ); $event[ 'description' ] = nl2br( $event[ 'description' ] ); } $events[] = $event; } return $events; } static public function getEventsByMonth( $events, $year, $month ) { $eventsInMonth = false; foreach( $events as $event ) { if ( ( date( 'Y', $event[ 'start' ] ) == $year ) && ( date( 'm', $event[ 'start' ] ) == $month ) ) { $eventsInMonth[] = $event; } } return $eventsInMonth; } static public function getChartData( $app ) { $dowMap = array( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ); $chartDataQuery = 'SELECT ROUND( AVG( people ) ) FROM state WHERE datetime >= curdate() - INTERVAL 2 WEEK AND WEEKDAY( datetime ) = ? AND HOUR ( datetime ) = ?'; for( $dow = 0; $dow < 7; $dow++ ) { $chartDataByDay[ 'name' ] = $dowMap[ $dow ]; for( $hod = 0; $hod < 24; $hod++ ) { $chartDataByDay[ 'data' ][ $hod ] = $app[ 'db' ]->fetchColumn( $chartDataQuery, array( $dow, $hod ) ); } $chart[ $dow ] = $chartDataByDay; } return $chart; } }