function get_calls($offset = 0, $page_size = 20) { $output = array(); $page_cache_key = $this->cache_key . "_{$offset}_{$page_size}"; $total_cache_key = $this->cache_key . '_total'; if (function_exists('apc_fetch')) { $success = FALSE; $total = apc_fetch($total_cache_key, $success); if ($total and $success) { $this->total = $total; } $data = apc_fetch($page_cache_key, $success); if ($data and $success) { $output = @unserialize($data); if (is_array($output)) { return $output; } } } $page = floor(($offset + 1) / $page_size); $params = array('num' => $page_size, 'page' => $page); $response = $this->twilio->request("Accounts/{$this->twilio_sid}/Calls", 'GET', $params); if ($response->IsError) { throw new VBX_CallException($response->ErrorMessage, $response->HttpStatus); } else { $this->total = (string) $response->ResponseXml->Calls['total']; $records = $response->ResponseXml->Calls->Call; foreach ($records as $record) { $item = new stdClass(); $item->id = (string) $record->Sid; $item->caller = format_phone($record->Caller); $item->called = format_phone($record->Called); $item->status = Call::get_status((string) $record->Status); $item->start = isset($record->StartTime) ? strtotime($record->StartTime) : null; $item->end = isset($record->EndTime) ? strtotime($record->EndTime) : null; $item->seconds = isset($record->Duration) ? (string) $record->Duration : 0; $output[] = $item; } } if (function_exists('apc_store')) { apc_store($page_cache_key, serialize($output), self::CACHE_TIME_SEC); apc_store($total_cache_key, $this->total, self::CACHE_TIME_SEC); } return $output; }