Browse Source

Extract Drupal collection view assembly into separate function.

Hurray for enabling code reuse!
pull/126/head
Adam Vessey 13 years ago committed by Adam Vessey
parent
commit
ee4427910b
  1. 114
      CollectionClass.inc

114
CollectionClass.inc

@ -673,49 +673,32 @@ class CollectionClass {
}
/**
* render collection
* @global type $base_url
* @param type $content
* @param type $pid
* @param type $dsId
* @param type $collection
* @param int $pageNumber
* @return type
* Assemble results in a somewhat more logical manner...
*
* ... Compared to generating a table in XSLT to contain a list (as
* renderCollection() used to do/does by default).
*
* @param $sparql_results array
* The array of results as yielded by ObjectHelper::parseSparqlResults()
* (and those associated functions which make use of it)
* @return
* An array to be passed to drupal_render, containing a pager, an unordered
* list of items, and another pager.
*/
function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository');
global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe
$parsedContent = NULL;
$contentModels = $this->collectionObject->get_content_models_list($pid);
$isCollection = FALSE;
//if this is a collection object store the $pid in the session as it will come in handy
//after a purge or ingest to return to the correct collection.
$fedoraItem = NULL;
if (empty($collectionName)) {
$collectionName = menu_get_active_title();
}
$xslContent = $this->getXslContent($pid, $path);
$objectList = '';
if (isset($content) && $content != FALSE) {
if (!$xslContent) { //Didn't find an XSLT.
$intermediate_results = ObjectHelper::parse_sparql_results($content);
unset($content);
public static function assembleCollectionView($sparql_results) {
$per_page = 20; //XXX: Make this configurable.
$pager_name = 0;
$total = count($intermediate_results);
$total = count($sparql_results);
$pager_page = self::hackPager($pager_name, $per_page, $total);
$results = array();
foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) {
foreach (array_slice($sparql_results, $per_page * $pager_page, $per_page) as $result) {
$title = $result['title'];
$obj_path = "fedora/repository/{$result['object']}";
$thumbnail = theme('image', "$obj_path/TN", $title, $title, array(), FALSE);
$tn_path = ($result['thumbnail'] ?
"fedora/repository/{$result['thumbnail']}":
"$obj_path/TN");
$thumbnail = theme('image', $tn_path, $title, $title, array(), FALSE);
$results[] = array(
'data' => l($thumbnail, $obj_path, array(
'html' => TRUE,
@ -738,13 +721,64 @@ class CollectionClass {
'@last' => $last,
'@total' => $total,
));
//$objectList = '<h3>' . $results_range_text . '</h3>';
$objectList .= theme('pager', array(), $per_page, $pager_name);
$objectList .= theme('item_list', $results, $result_range_text, 'ul', array(
return array(
array(
'#type' => 'markup',
'#value' => theme('pager', array(), $per_page, $pager_name),
),
array(
'#type' => 'markup',
'#value' => theme('item_list', $results, $result_range_text, 'ul', array(
'class' => 'islandora-collection-results-list',
));
$objectList .= theme('pager', array(), $per_page, $pager_name);
))
),
array(
'#type' => 'markup',
'#value' => theme('pager', array(), $per_page, $pager_name)
),
);
}
}
/**
* render collection
* @global type $base_url
* @param type $content
* @param type $pid
* @param type $dsId
* @param type $collection
* @param int $pageNumber
* @return type
*/
function renderCollection($content, $pid, $dsId, $collectionName, $pageNumber = NULL) {
$path = drupal_get_path('module', 'fedora_repository');
global $base_url;
$collection_pid = $pid; //we will be changing the pid later maybe
$parsedContent = NULL;
$contentModels = $this->collectionObject->get_content_models_list($pid);
$isCollection = FALSE;
//if this is a collection object store the $pid in the session as it will come in handy
//after a purge or ingest to return to the correct collection.
$fedoraItem = NULL;
if (empty($collectionName)) {
$collectionName = menu_get_active_title();
}
$xslContent = $this->getXslContent($pid, $path);
$objectList = '';
if (isset($content) && $content != FALSE) {
if (!$xslContent) { //Didn't find an XSLT.
return drupal_render(
self::assembleCollectionView(
$this->collectionObject->parseSparqlResults(
$content
)
)
);
}
else {
if (!$pageNumber) {

Loading…
Cancel
Save