function views_oai_pmh_plugin_display::build_oai_resumption_token in Views OAI-PMH 6.2
Same name and namespace in other branches
- 6 plugins/views_oai_pmh_plugin_display.inc \views_oai_pmh_plugin_display::build_oai_resumption_token()
- 7 plugins/views_oai_pmh_plugin_display.inc \views_oai_pmh_plugin_display::build_oai_resumption_token()
- 7.2 plugins/views_oai_pmh_plugin_display.inc \views_oai_pmh_plugin_display::build_oai_resumption_token()
File
- plugins/
views_oai_pmh_plugin_display.inc, line 417 - Contains the OAI-PMH display plugin.
Class
- views_oai_pmh_plugin_display
- We are based on a feed display for compatibility.
Code
function build_oai_resumption_token() {
if (count($this->oai_errors)) {
return;
}
$items_per_page = $this->view->query->pager ? $this->view->query->pager
->get_items_per_page() : $this->view->pager['items_per_page'];
$current_page = $this->view->query->pager ? $this->view->query->pager
->get_current_page() : $this->view->pager['current_page'];
$total_items = $this->view->query->pager ? $this->view->query->pager
->get_total_items() : (!empty($this->view->total_rows) ? $this->view->total_rows : 0);
$total_pages = $this->view->query->pager ? $this->view->query->pager
->get_pager_total() : ($items_per_page ? ceil($total_items / $items_per_page) : 1);
$cursor = $items_per_page * $current_page;
$token = $current_page == $total_pages - 1 ? NULL : md5(uniqid());
$token_expire_time = gmstrftime('%Y-%m-%dT%H:%M:%SZ', time() + 24 * 3600);
$token_attrs = array(
'completeListSize' => $total_items,
'cursor' => $cursor,
);
if ($token) {
$token_attrs['expirationDate'] = $token_expire_time;
$data = array(
'cursor' => $cursor,
'total_items' => $total_items,
'current_page' => $current_page,
'metadataPrefix' => $this->oai_args['metadataPrefix'],
'query' => $this->view->query,
);
$fields = array(
'serialized' => 1,
'created' => REQUEST_TIME,
'expire' => time() + OAI_TOKEN_LIFETIME,
'data' => serialize($data),
'cid' => $token,
);
// doing my own insert here because cache_set was silently eating
// max_allowed_packet errors and dropping cache inserts. http://drupal.org/node/542874
// changing the my.ini setting fixed the error, but I would like users to know about the error.
//
cache_set($token, $data, 'cache_views_oai_pmh', time() + OAI_TOKEN_LIFETIME);
// db_insert('cache_views_oai_pmh')
// ->fields($fields)
// ->execute();
}
return format_xml_elements(array(
array(
'key' => 'resumptionToken',
'attributes' => $token_attrs,
'value' => $token,
),
));
}