flushAll(); // If you want to remove one item like the stored HTML for evets.php $cache->delete('events.php'); // Add a prefered language for requests. If none is set 'und' is used and // content is returned in its original language, first language posted.. $client->setLanguage('de'); // Check to see if there is a copy in the cache. if ($cache->contains('events.php') && $page = $cache->fetch('events.php')) { // We can handle expiring data, and serve a stale page. print $page['html']; // If it's more than an hour old, get a new one. if ($page['created'] + 60 * 60 < time()) { $html = radar_events_page_html($client); $cache->delete('events.php'); } } else { // Generate the page and output it. $html = radar_events_page_html($client); print $html; } if (!empty($html)) { // Save generated HTML into the cache. $page = array('html' => $html, 'created' => time()); $cache->save('events.php', $page); } /** * Make HTML page. */ function radar_events_page_html($client) { $request = radar_prepare_events_request($client); $response = $client->retrieveResponse($request); $events = $client->parseResponse($response); $metadata = $client->parseResponseMeta($response); return radar_events_format($client, $events, $metadata); } /** * Set a filter and retrieve events matching the filter. * * @param \Radar\Connect\Connect $client * The connect client. * * @return Radar\Connect\Event[] * Array of radar connect events. */ function radar_prepare_events_request(\Radar\Connect\Connect $client) { $filter = new \Radar\Connect\Filter; $filter->addCity('Berlin'); // Alternatives:- //$filter->addCity('Amsterdam'); //$filter->addDate(new DateTime('tomorrow')); //$filter->addDay(); //$filter->addCategory('music'); //Some filters don't have explicit methods to set them so for tags... //$filter->add('tag', 'Punk'); // See docs/classes/Radar.Connect.Filter.html for full list of methods. // You can also see all the filter values and their counts in the metadata // returned. See the examples at the top of radar_events_format(). // Get the request. // arguments: // $filter - prepared above, // $fields - array of field names to collect, empty for default // $limit - maximum number of events to return. $request = $client->prepareEventsRequest($filter, array(), 50); return $request; // Execute request. return $client->retrieve($request); } /** * Create HTML of an array of events. * * @param \Radar\Connect\Connect $client * The connect client. * @param \Radar\Connect\Event[] $events * Array of Event entities, for example response to events request. * @param array $metadata * Array of counts and facets. * * @return string * The HTML output. */ function radar_events_format(\Radar\Connect\Connect $client, array $events, array $metadata) { ob_start(); ob_implicit_flush(TRUE); $html = ''; // Metadata includes the result count. print "

There are {$metadata['count']} results for the query

\n"; // Retrieve some facets. Summaries of filters you can use // in further narrowed queries, and their result counts. print '

Forthcoming days

\n"; // For other factets it's even more convenient. The 'filter' value is also the value you set to filter the query. print "

Categories