From d51f9cad7e194983340e4dbc8c92b84b4eed6941 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Tue, 29 May 2012 14:29:48 -0300 Subject: [PATCH 1/2] updated admin datastream table and started pager function --- includes/object_properties.inc | 1 + islandora.module | 16 +++++++++++----- .../islandora-basic-collection.tpl.php | 2 ++ .../islandora_basic_collection.module | 15 ++++++++++----- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/includes/object_properties.inc b/includes/object_properties.inc index c8589e62..97dd20a4 100644 --- a/includes/object_properties.inc +++ b/includes/object_properties.inc @@ -64,6 +64,7 @@ function islandora_edit_properties_form_submit($form, &$form_state) { function islandora_edit_properties_form($form, &$form_state, $object_id) { $form = array(); $islandora_object = islandora_get_object($object_id); + drupal_set_title($islandora_object->label); if (!isset($islandora_object)) { return NULL; } diff --git a/islandora.module b/islandora.module index 750fccaf..4dd75232 100644 --- a/islandora.module +++ b/islandora.module @@ -646,20 +646,26 @@ function islandora_preprocess_islandora_default_edit(&$variables) { module_load_include('inc', 'islandora', 'includes/datastream'); // $variables['add_datastream_form'] = drupal_get_form('islandora_add_datastream_form', $islandora_object->id); $header = array( + array('data' => t('ID')), + array('data' => t('Type')), + array('data' => t('Mime type')), array('data' => t('Label')), - array('data' => t('Operations'),'colspan' => '2'), - //array('data' => t('Delete')), + array('data' => t('Operations'), 'colspan' => '2'), + //array('data' => t('Delete')), ); $table_attributes = array('class' => array('manage-datastrea')); $rows = array(); foreach ($islandora_object as $ds) { $rows[] = array( + array('class' => 'datastream-label', 'data' => l($ds->id, $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/view')), + array('class' => 'datastream-label', 'data' => $ds->controlGroup), + array('class' => 'datastream-label', 'data' => $ds->mimeType), array('class' => 'datastream-label', 'data' => l($ds->label, $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/view')), - array('class' => 'datastream-download', 'data' => l(t('download'), $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/download')), + array('class' => 'datastream-download', 'data' => l(t('download'), $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/download')), array('class' => 'datastream-delete', 'data' => l(t('delete'), $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/delete')), - ); + ); } $caption = $islandora_object->label . ' - ' . $islandora_object->id; - $table = array('colgroups' => NULL, 'sticky' => TRUE, 'empty' => 'Error loading datastreams', 'caption' => $caption, 'header' => $header, 'rows' => $rows, 'attributes' => $table_attributes); + $table = array('colgroups' => NULL, 'sticky' => TRUE, 'empty' => 'Error loading datastreams', 'caption' => $caption, 'header' => $header, 'rows' => $rows, 'attributes' => $table_attributes); $variables['datastream_table'] = theme_table($table); } \ No newline at end of file diff --git a/islandora_basic_collection/islandora-basic-collection.tpl.php b/islandora_basic_collection/islandora-basic-collection.tpl.php index da5de757..92c9ec5f 100644 --- a/islandora_basic_collection/islandora-basic-collection.tpl.php +++ b/islandora_basic_collection/islandora-basic-collection.tpl.php @@ -25,11 +25,13 @@
+ $value): ?>
+
\ No newline at end of file diff --git a/islandora_basic_collection/islandora_basic_collection.module b/islandora_basic_collection/islandora_basic_collection.module index a288e00d..d0fecb9d 100644 --- a/islandora_basic_collection/islandora_basic_collection.module +++ b/islandora_basic_collection/islandora_basic_collection.module @@ -210,7 +210,7 @@ function islandora_basic_collection_islandora_get_types() { * @return string * themed html */ -function islandora_basic_collection_islandora_view_object($object, $user, $page_number, $page_size) { +function islandora_basic_collection_islandora_view_object($object, $user) { //global $user; $cmodel_list = islandora_basic_collection_islandora_get_types(); $models = $object->models; @@ -242,7 +242,13 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error'); } - $variables['islandora_associated_objects'] = islandora_basic_collection_get_objects($islandora_object); + $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; + $page_size = (empty($_GET['pagesize'])) ? variable_get('islandora_collection_pagesize',5) : $_GET['pagesize']; + $results = islandora_basic_collection_get_objects($islandora_object,$page_number,$page_size); + pager_default_initialize(count($results), $page_size); + $variables['islandora_associated_objects'] = $results; + $pager = theme('pager', array('quantity' => count($results))); + $variables['pager'] = $pager; $variables['islandora_dublin_core'] = $dc_object; $variables['islandora_object_label'] = $islandora_object->label; $variables['theme_hook_suggestions'][] = 'islandora_basic_collection__' . str_replace(':', '_', $islandora_object->id); @@ -260,6 +266,7 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari } $associated_objects_array = array(); + //for($i=$page_size * ($page_number -1),$i < $page_size * ($page) foreach ($variables['islandora_associated_objects'] as $key => $value) { $pid = $variables['islandora_associated_objects'][$key]['object']['value']; $fc_object = islandora_basic_collection_get_object($pid); @@ -307,7 +314,7 @@ function islandora_basic_collection_get_object($object_id) { return $fedora_object; } -function islandora_basic_collection_get_objects($object) { +function islandora_basic_collection_get_objects($object, $page_number = 1, $page_size = 5) { $query = 'select $object $title $content from <#ri> where ($object $title and $object $content @@ -316,8 +323,6 @@ function islandora_basic_collection_get_objects($object) { and $object ) minus $content order by $title'; - $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; - $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; module_load_include('inc', 'islandora', 'RestConnection'); $query_array = array('query' => $query, 'type' => 'itql', 'pid' => $object->id, 'page_size' => $page_size, 'page_number' => $page_number); drupal_alter('islandora_basic_collection_query', $query_array); From e35af9f7bf42d7b0a81589192702668a03d59aad Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Tue, 29 May 2012 15:20:12 -0300 Subject: [PATCH 2/2] added admin section for collection paging and implemented paging --- .../islandora_basic_collection.admin.inc | 7 ++++++ .../islandora_basic_collection.module | 25 +++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/islandora_basic_collection/admin/islandora_basic_collection.admin.inc b/islandora_basic_collection/admin/islandora_basic_collection.admin.inc index 8311f3e8..1536de3b 100644 --- a/islandora_basic_collection/admin/islandora_basic_collection.admin.inc +++ b/islandora_basic_collection/admin/islandora_basic_collection.admin.inc @@ -10,6 +10,13 @@ function islandora_basic_collection_admin() { on a view tab you may have multiple modules configured to provide content for the default tab.'), '#weight' => -10 ); + $form['islandora_basic_collection_page_size'] = array( + '#type' => 'textfield', + '#title' => t('The default number of objects to show for a collection'), + '#default_value' => variable_get('islandora_basic_collection_page_size', '10'), + '#description' => t('The default number of object to show in a collection view.'), + '#weight' => -10 + ); return system_settings_form($form); } diff --git a/islandora_basic_collection/islandora_basic_collection.module b/islandora_basic_collection/islandora_basic_collection.module index d0fecb9d..8b0a2dd3 100644 --- a/islandora_basic_collection/islandora_basic_collection.module +++ b/islandora_basic_collection/islandora_basic_collection.module @@ -224,7 +224,7 @@ function islandora_basic_collection_islandora_view_object($object, $user) { } /** - * + * * @global type $base_url * @param array $variables * an array of variables that will be passed to the theme function @@ -242,12 +242,13 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error'); } - $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; - $page_size = (empty($_GET['pagesize'])) ? variable_get('islandora_collection_pagesize',5) : $_GET['pagesize']; - $results = islandora_basic_collection_get_objects($islandora_object,$page_number,$page_size); - pager_default_initialize(count($results), $page_size); - $variables['islandora_associated_objects'] = $results; - $pager = theme('pager', array('quantity' => count($results))); + $page_number = (empty($_GET['page'])) ? 0 : $_GET['page']; + $page_size = (empty($_GET['pagesize'])) ? variable_get('islandora_basic_collection_page_size', '10') : $_GET['pagesize']; + $results = islandora_basic_collection_get_objects($islandora_object, $page_number, $page_size); + $total_count = count($results); + pager_default_initialize($total_count, $page_size); + + $pager = theme('pager', array('quantity' => $total_count)); $variables['pager'] = $pager; $variables['islandora_dublin_core'] = $dc_object; $variables['islandora_object_label'] = $islandora_object->label; @@ -266,9 +267,11 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari } $associated_objects_array = array(); - //for($i=$page_size * ($page_number -1),$i < $page_size * ($page) - foreach ($variables['islandora_associated_objects'] as $key => $value) { - $pid = $variables['islandora_associated_objects'][$key]['object']['value']; + $start = $page_size * ($page_number); + $end = min($start + $page_size, $total_count); + + for ($i = $start; $i < $end; $i++) { + $pid = $results[$i]['object']['value']; $fc_object = islandora_basic_collection_get_object($pid); if (!isset($fc_object)) { continue; //null object so don't show in collection view; @@ -283,7 +286,7 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari } $object_url = 'islandora/object/' . $pid; $thumbnail_img = ''; - $title = $variables['islandora_associated_objects'][$key]['title']['value']; + $title = $results[$i]['title']['value']; $associated_objects_array[$pid]['pid'] = $pid; $associated_objects_array[$pid]['path'] = $object_url; $associated_objects_array[$pid]['title'] = $title;