diff --git a/CollectionClass.inc b/CollectionClass.inc index 68dbc08a..5882a460 100644 --- a/CollectionClass.inc +++ b/CollectionClass.inc @@ -35,16 +35,16 @@ class CollectionClass { } } - static function get_collection_query($pid) { - if ($query = self::_get_collection_query_from_stream($pid)) { + public static function getCollectionQuery($pid) { + if ($query = self::getCollectionQueryFromStream($pid)) { return $query; } else { - return self::_get_default_collection_query($pid); + return self::getDefaultCollectionQuery($pid); } } - static function _get_collection_query_from_stream($pid) { + protected static function getCollectionQueryFromStream($pid) { module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $item = new Fedora_Item($pid); if ($item->exists() && array_key_exists('QUERY', $item->datastreams)) { @@ -55,7 +55,7 @@ class CollectionClass { } } - static function _get_default_collection_query($pid) { + protected static function getDefaultCollectionQuery($pid) { return 'select $object $title $content from <#ri> where ($object $title and $object $content @@ -87,7 +87,7 @@ class CollectionClass { * Gets objects related to this item. * * Query the resource index using the provided iTQL query. If no query is - * provided, one should be obtained via self::get_collection_query() which + * provided, one should be obtained via self::getCollectionQuery() which * grabs the child objects. * * @param $pid string @@ -112,7 +112,7 @@ class CollectionClass { } if ($query_string === NULL) { - $query_string = self::get_collection_query($pid); + $query_string = self::getCollectionQuery($pid); } // Replace %parent_collection% with the actual collection PID @@ -616,12 +616,45 @@ class CollectionClass { * Unfortunate function, I know... * * Does just what it says: Hacks the default Drupal pager such that it might - * be rendered. + * be rendered, likely with: theme('pager', array(), $per_page, $pager_name) + * (I reccomend seeing the real documentation for more detail, but the first + * array can be a list of the tags to use for first, previous, next and last + * (text in the pager), I don't believe per_page is actually used in the theme + * function, and $pager_name is an integer used to identify the pager (such + * that there can be more than one--that is, tracking different lists of + * content on a single page. You can render the exact same pager multiple + * times, say if you want one at the top and bottom of a list, using the same + * ID/pager_name. + * + * @global $pager_total array + * Numerically indexed array, where keys are the $pager_names and values + * are the number of pages in the given set, based on: ceil($total_items/$per_page); + * @global $pager_page_array array + * Numerically indexed array, where keys are the $pager_names and values + * are the page selected in the relevant set. + * @param $pager_name int + * An integer to identify the pager to affect. Do note that paging in using + * this function will add the 'page' HTTP GET parameter to the URL, with + * the value containing a comma-separated list with max($pager_name + 1) + * values--that is, if you create a single pager named '10', the 'next' + * link will look something like: 0,0,0,0,0,0,0,0,0,0,1 + * @param $per_page int + * An integer representing the number of items per page. + * @param $total_items int + * An integer representing the total number of items in the set. + * @return int + * An integer representing what the current page should be. */ - protected static function _hack_pager($pager_name, $per_page, $total_items) { + protected static function hackPager($pager_name, $per_page = NULL, $total_items = NULL) { global $pager_total, $pager_page_array; - $pager_total[$pager_name] = ceil($total_items / $per_page); + if ($per_page !== NULL && $total_items !== NULL) { + $pager_total[$pager_name] = ceil($total_items / $per_page); + } + + //XXX: Don't know that this is neccessary, to try to load all the time, or + // whether Drupal will load it automatically somewhere... Docs seems a + // a little sparse. $page_info = explode(',', isset($_GET['page']) ? $_GET['page'] : ''); $page = $page_info[$pager_name]; if ($page < 0) { @@ -676,7 +709,7 @@ class CollectionClass { $per_page = 20; //XXX: Make this configurable. $pager_name = 0; $total = count($intermediate_results); - $pager_page = self::_hack_pager($pager_name, $per_page, $total); + $pager_page = self::hackPager($pager_name, $per_page, $total); $results = array(); foreach (array_slice($intermediate_results, $per_page * $pager_page, $per_page) as $result) { diff --git a/ObjectHelper.inc b/ObjectHelper.inc index 659847d7..f41217cc 100644 --- a/ObjectHelper.inc +++ b/ObjectHelper.inc @@ -759,7 +759,7 @@ class ObjectHelper { * @return string * A string containing an iTQL query, selecting something into $object and $title */ - static function _parent_query($pid) { + static function parentQuery($pid) { return 'select $object $title from <#ri> where ($object $title and $object @@ -773,10 +773,10 @@ class ObjectHelper { * @param $pid string * A string containing a Fedora PID to find the parents for. * @return string - * A string containing Sparql XML (the results of the self::_parent_query()) + * A string containing Sparql XML (the results of the self::parentQuery()) */ function get_parent_objects($pid) { - $query_string = self::_parent_query(); + $query_string = self::parentQuery(); module_load_include('inc', 'fedora_repository', 'CollectionClass'); $collection_class = new CollectionClass($pid); $objects = CollectionClass::getRelatedItems($pid, $query_string); @@ -791,7 +791,7 @@ class ObjectHelper { */ function get_parent_objects_asHTML($pid) { module_load_include('inc', 'fedora_repository', 'CollectionClass'); - $results = self::perform_itql_query(self::_parent_query($pid)); + $results = self::performItqlQuery(self::parentQuery($pid)); $parent_collections = array(); foreach ($results as $result) { @@ -874,7 +874,7 @@ class ObjectHelper { and $o $desc and $o '; - $results = self::perform_itql_query($query_string); + $results = self::performItqlQuery($query_string); $pids = array(); //There should only be one... Anyway. @@ -905,7 +905,7 @@ class ObjectHelper { 'and $o $title ' . 'and ( ' . implode(' or ', $query_chunks) . ' )'; - $results = self::perform_itql_query($query_string); + $results = self::performItqlQuery($query_string); $child_pids = array(); if ($results) { @@ -979,7 +979,7 @@ class ObjectHelper { minus $content order by $title desc'; - if (count($results = self::perform_itql_query($query_string)) > 0 && $level > 0) { + if (count($results = self::performItqlQuery($query_string)) > 0 && $level > 0) { $parent = $results[0]['parentObject']; $this_title = $results[0]['title']; @@ -1029,7 +1029,7 @@ class ObjectHelper { * URIs beginning with 'info:fedora/' will have this beginning stripped * off, to facilitate their use as PIDs. */ - public static function parse_sparql_results($sparql) { + public static function parseSparqlResults($sparql) { //Load the results into a SimpleXMLElement $doc = new SimpleXMLElement($sparql, 0, FALSE, 'http://www.w3.org/2001/sw/DataAccess/rf1/result'); @@ -1044,7 +1044,7 @@ class ObjectHelper { $attrs = $element->attributes(); if (!empty($attrs['uri'])) { - $val = self::pid_uri_to_bare_pid((string)$attrs['uri']); + $val = self::pidUriToBarePid((string)$attrs['uri']); } else { $val = (string)$element; @@ -1079,7 +1079,7 @@ class ObjectHelper { * URIs beginning with 'info:fedora/' will have this beginning stripped * off, to facilitate their use as PIDs. */ - static function perform_ri_query($query, $type = 'itql', $limit = -1, $offset = 0) { + static function performRiQuery($query, $type = 'itql', $limit = -1, $offset = 0) { //Setup the query options... $options = array( 'type' => 'tuples', @@ -1110,26 +1110,26 @@ class ObjectHelper { } //Pass the query's results off to a decent parser. - return self::parse_sparql_results($curl_result[0]); + return self::parseSparqlResults($curl_result[0]); } /** - * Thin wrapper for self::_perform_ri_query(). + * Thin wrapper for self::_performRiQuery(). * - * @see self::_perform_ri_query() + * @see self::performRiQuery() */ - public static function perform_itql_query($query, $limit = -1, $offset = 0) { - return self::perform_ri_query($query, 'itql', $limit, $offset); + public static function performItqlQuery($query, $limit = -1, $offset = 0) { + return self::performRiQuery($query, 'itql', $limit, $offset); } /** - * Thin wrapper for self::_perform_ri_query(). + * Thin wrapper for self::performRiQuery(). * - * @see self::_perform_ri_query() + * @see self::_performRiQuery() */ - public static function perform_sparql_query($query, $limit = -1, $offset = 0) { - return self::perform_ri_query($query, 'sparql', $limit, $offset); + public static function performSparqlQuery($query, $limit = -1, $offset = 0) { + return self::performRiQuery($query, 'sparql', $limit, $offset); } /** - * Utility function used in self::_perform_ri_query(). + * Utility function used in self::performRiQuery(). * * Strips off the 'info:fedora/' prefix from the passed in string. * @@ -1140,7 +1140,7 @@ class ObjectHelper { * The input string less the 'info:fedora/' prefix (if it has it). * The original string otherwise. */ - protected static function pid_uri_to_bare_pid($uri) { + protected static function pidUriToBarePid($uri) { $chunk = 'info:fedora/'; $pos = strpos($uri, $chunk); if ($pos === 0) { //Remove info:fedora/ chunk