asset_list($filter = FALSE)This function lists all assets
vpx_beheer_mm/asset/asset.module, line 713
<?php
function asset_list($filter = FALSE) {
drupal_set_title(t('Assets'));
// Store sort order
foreach (array('sort', 'order') as $item) {
if (isset($_GET[$item])) {
$_SESSION['get']['asset'][$item] = check_plain($_GET[$item]);
}
else {
if (isset($_SESSION['get']['asset'][$item])) {
$_GET[$item] = $_SESSION['get']['asset'][$item];
}
}
}
$item_limit = variable_get('vpx_connector_item_limit', 200);
$page = isset($_GET['page']) ? $_GET['page'] : 0;
$output = '<p>'. t('Manage assets by filtering assets first. Add search criteria and search values to the filter until relevant assets are found.') .'</p>';
$url = sprintf('/asset?limit=%d&granted=TRUE', $item_limit);
// add the filter form
$output .= drupal_get_form('asset_list_filter_form');
$output .= drupal_get_form('asset_list_cql_filter_form');
// add offset (if set)
if ($page !== 0) {
$url .= sprintf('&offset=%d', $page * $item_limit);
}
// add the filter (if set)
if (isset($_SESSION['asset_filter_form']['cql_filter'])) {
$url .= "&cql=" . $_SESSION['asset_filter_form']['cql_filter'];
}
elseif (isset($_SESSION['asset_filter_form']['filter'])) {
$url .= $_SESSION['asset_filter_form']['filter'];
}
// Prepare the table header
$columns = explode('|', variable_get('asset_list_columns', 'Title,title,'));
$header = array();
foreach ($columns as $column) {
list($title, $field, $length) = explode(',', $column);
$header[] = array('data' => t($title), 'field' => $field);
}
// add order_by (if set)
$order_by = FALSE;
if (!isset($_SESSION['asset_filter_form']['cql_filter'])) { // order en cql do not match.
if (isset($_GET['order'])) {
$ts = tablesort_init($header);
$url .= sprintf('&order_by=%s&order_direction=%s', $ts['sql'], $ts['sort']);
}
}
// perform the request
$vpx = new vpx_connector();
$result = $vpx->request('GET', $url);
$vpx->check_result($result, FALSE, '%message');
// get the item count
$asset_item_count = (int)$result->header->item_count_total;
$output .= '<h2>'. t('Assets (@count)', array('@count' => $asset_item_count)) .'</h2>';
$output .= '<p>'. t('Assets matching the search criteria above are listed below. Click on a asset title below to view details.') .'</p>';
$rows = array();
if (isset($result->items->item)) {
foreach ($result->items->item as $item) {
$array = array();
foreach ($columns as $column) {
list($title, $field, $length) = explode(',', $column);
// Get the field's content
$content = '';
if (isset($item->$field)) {
$content = (string)$item->$field;
}
else {
foreach (array('dublin_core', 'qualified_dublin_core') as $subject) {
if (isset($item->$subject->$field)) {
$content = (string)$item->$subject->$field;
}
}
}
// Add the formatted value to the array
if (pa_field_is_date($field) && $content) {
$format = '';
if ($length == 'date') {
$length = 'custom';
$format = 'Y-m-d';
}
$array[] = format_date(strtotime($content), $length, $format);
}
else {
$array[] = pa_trim_string($content, $length);
}
}
// Add the link to the asset
$array[0] = l($array[0], variable_get('vpx_connector_menu_prefix', '') . sprintf('asset/%s', $item->asset_id), array('html' => TRUE));
$rows[] = $array;
}
}
$output .= theme('table', $header, $rows);
// add the pager
$output .= pa_pager($page, $asset_item_count, $item_limit);
return $output;
}
?>