<?php if (!defined('VB_ENTRY')) die('Access denied.'); class vB_Api_Vb4_events extends vB_Api { public function listing( $beginperiod = 0, $endperiod = null, $perpage = 20, $pagenumber = 1 ) { $cleaner = vB::getCleaner(); $beginperiod = $cleaner->clean($beginperiod, vB_Cleaner::TYPE_UINT); if (empty($beginperiod)) { $beginperiod = vB::getRequest()->getTimeNow(); } $endperiod = $cleaner->clean($endperiod, vB_Cleaner::TYPE_UINT); $perpage = $cleaner->clean($perpage, vB_Cleaner::TYPE_UINT); if ($perpage < 1) { $perpage = 20; } $pagenumber = $cleaner->clean($pagenumber, vB_Cleaner::TYPE_UINT); if ($pagenumber < 1) { $pagenumber = 1; } $searchSort = array( "eventstartdate" => "ASC", ); $searchJSON = array( "type" => "vBForum_Event", "eventstartdate" => $beginperiod, "sort" => $searchSort, "view" => "event", "exclude_type" => "vBForum_PrivateMessage", ); if (!empty($endperiod)) { $searchJSON['eventstartdate'] = array( 'from' => $beginperiod, 'to' => $endperiod, ); } $events = vB_Api::instance('search')->getInitialResults($searchJSON, $perpage, $pagenumber); if ($events === null || isset($events['errors'])) { return vB_Library::instance('vb4_functions')->getErrorResponse($events); } $eventlist = array(); foreach ($events['results'] AS $__nodeid => $__node) { $__event = array( 'nodeid' => (int) $__node['nodeid'], 'eventstarttime' => (int) $__node['content']['eventstartdate'], 'eventendtime' => null, 'location' => null, 'title' => (string) $__node['title'], ); if (!empty($__node['content']['eventenddate'])) { $__event['eventendtime'] = (int) $__node['content']['eventenddate']; } if (!empty($__node['content']['location'])) { $__event['location'] = (string) $__node['content']['location']; } $eventlist[] = $__event; } $total = $events['totalRecords']; $pagenav = vB_Library::instance('vb4_functions')->pageNav($pagenumber, $perpage, $total); $response = array(); $response['response'] = array( 'eventlist' => $eventlist, 'perpage' => $perpage, 'pagenumber' => $pagenumber, 'total' => $total, 'pagenav' => $pagenav, ); return $response; } } 