From 847e930740ca4a8e5375de2059021549bc0e01ed Mon Sep 17 00:00:00 2001 From: "Francisco J. Seva" Date: Thu, 13 Jul 2017 13:14:02 +0200 Subject: [PATCH 1/3] Update main templates (results and side facets) and remove preprocess * Modify ebsco.module removing template_preprocess * Create new callbacks to allow get the search output (initializing theme variables on it) * Add fast cache using drupal_static to avoid initialize (it is needed in new callbacks) * Add new conditional in templates based on new passed parameters. --- ebsco/ebsco.module | 109 +++++++++++++--------- ebsco/templates/ebsco-results.tpl.php | 45 +++++---- ebsco/templates/ebsco-side-facets.tpl.php | 60 ++++++------ 3 files changed, 126 insertions(+), 88 deletions(-) mode change 100644 => 100755 ebsco/templates/ebsco-results.tpl.php diff --git a/ebsco/ebsco.module b/ebsco/ebsco.module index f3b0abb..3d3740b 100644 --- a/ebsco/ebsco.module +++ b/ebsco/ebsco.module @@ -68,9 +68,29 @@ function ebsco_theme() { ), 'ebsco_results' => array( 'template' => 'templates/ebsco-results', + 'variables' => array( + 'lookfor' => NULL, + 'pager' => NULL, + 'record_count' => NULL, + 'record_end' => NULL, + 'record_start' => NULL, + 'records' => NULL, + 'search_time' => NULL, + 'search_view' => NULL, + 'sort_form' => NULL, + ), ), 'ebsco_side_facets' => array( 'template' => 'templates/ebsco-side-facets', + 'variables' => array( + 'record_count' => NULL, + 'expanders' => NULL, + 'limiters' => NULL, + 'facets' => NULL, + 'filters' => NULL, + 'search_params' => NULL, + 'link_search_params' => NULL, + ), ), 'ebsco_basic_search' => array( 'template' => 'templates/ebsco-basic-search', @@ -395,10 +415,43 @@ function ebsco_basic_search_block() { } /** - * EBSCO side facets block callback. + * Init the EBSCODocument search. */ +function ebsco_init_search_document($params = NULL) { + // If there are input params also ensure that we add the + // request params where we receive the page, sort, etc. + if ($params) { + $params += $_REQUEST; + } + + $_ebsco_document = &drupal_static(__FUNCTION__, array()); + if (empty($_ebsco_document)) { + $_ebsco_document = new EBSCODocument($params); + $_ebsco_document->info(); + $_ebsco_document->search(); + } + return $_ebsco_document; +} + function ebsco_side_facets_block() { - return theme('ebsco_side_facets'); + // only build the facets when viewed page is ebsco search + if (request_path() != 'search/ebsco') { + return; + } + $_ebsco_document = ebsco_init_search_document(); + $variables['record_count'] = $_ebsco_document->record_count(); + //$variables['expanders'] = $_ebsco_document->expanders(); + //$variables['limiters'] = $_ebsco_document->limiters(); + $variables['facets'] = $_ebsco_document->facets(); + + // Applied facets, limiters or expanders + $variables['filters'] = $_ebsco_document->filters(); + + // Hidden parameters. + $variables['search_params'] = $_ebsco_document->search_params(); + $variables['link_search_params'] = $_ebsco_document->link_search_params(); + + return theme('ebsco_side_facets', $variables); } /****************************************************** @@ -877,24 +930,15 @@ function ebsco_advanced_search_form_submit($form, &$form_state) { } /** - * Process variables for ebsco-results.tpl.php. - * - * @see ebsco-results.tpl.php + * Get the search results. */ -function template_preprocess_ebsco_results(&$variables) { - global $_ebsco_document; +function ebsco_get_search_results() { + $_ebsco_document = ebsco_init_search_document(); $params = $_REQUEST; - $_SESSION['EBSCO']['redirect'] = drupal_get_destination(); - if (empty($_ebsco_document)) { - $_ebsco_document = new EBSCODocument(); - } - $title = !empty($params['lookfor']) ? ' - ' . $params['lookfor'] : ''; drupal_set_title('Search results' . $title); - $_ebsco_document->search(); - $variables['records'] = $_ebsco_document->records(); $variables['record_start'] = $_ebsco_document->record_start(); $variables['record_end'] = $_ebsco_document->record_end(); @@ -904,10 +948,11 @@ function template_preprocess_ebsco_results(&$variables) { $variables['relatedContent'] = $_ebsco_document->relatedContent(); $variables['autoSuggestTerms'] = $_ebsco_document->autoSuggestTerms(); $variables['lookfor'] = ''; + if (isset($params['lookfor'])) { $variables['lookfor'] = $params['lookfor']; } - elseif (isset($params['group'])) { + else if (isset($params['group'])) { $types = EBSCODocument::basic_search_type_options(); foreach ($params['group'] as $key => $group) { if (!empty($group['lookfor'])) { @@ -918,11 +963,14 @@ function template_preprocess_ebsco_results(&$variables) { } $variables['pager'] = $_ebsco_document->pager(); - $v1 = drupal_get_form('ebsco_sort_form'); - $variables['sort_form'] = drupal_render($v1); + $sort_form = drupal_get_form('ebsco_sort_form'); + $variables['sort_form'] = drupal_render($sort_form); // Save data needed by scroller in Detailed view page - // $_ebsco_document->search_write(); + //$_ebsco_document->search_write(); + + // theme results + return theme('ebsco_results', $variables); } /** @@ -998,31 +1046,6 @@ function template_preprocess_ebsco_result(&$variables) { drupal_set_title($record->title); } -/** - * Process variables for ebsco-side-facets.tpl.php. - * - * @see ebsco-side-facets.tpl.php - */ -function template_preprocess_ebsco_side_facets(&$variables) { - global $_ebsco_document; - - if (empty($_ebsco_document)) { - $_ebsco_document = new EBSCODocument(); - } - $_ebsco_document->info(); - - $variables['record_count'] = $_ebsco_document->record_count(); - $variables['expanders'] = $_ebsco_document->expanders(); - $variables['limiters'] = $_ebsco_document->limiters(); - $variables['facets'] = $_ebsco_document->facets(); - // Applied facets, limiters or expanders. - $variables['filters'] = $_ebsco_document->filters(); - // Hidden parameters. - $variables['search_params'] = $_ebsco_document->search_params(); - // Hidden parameters. - $variables['link_search_params'] = $_ebsco_document->link_search_params(); -} - /****************************************** * View Helpers ******************************************/ diff --git a/ebsco/templates/ebsco-results.tpl.php b/ebsco/templates/ebsco-results.tpl.php old mode 100644 new mode 100755 index e9d8ae6..b224c2d --- a/ebsco/templates/ebsco-results.tpl.php +++ b/ebsco/templates/ebsco-results.tpl.php @@ -46,7 +46,15 @@ } print $sort_form; - print $pager; + + if (!$hide_custom_area) { + print $custom_area; + } + + if (!$hide_top_pager) { + print $pager; + } + if (!user_is_logged_in()) { $link = '' . t('Login') . ''; @@ -231,7 +239,7 @@ record_id()); - $recordUrl = url('ebsco/result', array('query' => array('id' => $id))); + $recordUrl = url($record->p_link, array('absolute' => TRUE)); $fulltextUrl = url('ebsco/fulltext', array('query' => array('id' => $id))); $pdfUrl = url('ebsco/pdf', array('query' => array('id' => $id))); @@ -244,7 +252,7 @@
@@ -337,7 +347,10 @@ - + + + + - - + 0): ?> + + From 39f813af9a11db2de2b310b7c25daaa2e33b6558 Mon Sep 17 00:00:00 2001 From: James Wilson Date: Fri, 14 Jul 2017 12:38:52 -0400 Subject: [PATCH 2/3] Fix punctuation around 'query time' --- ebsco/templates/ebsco-results.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ebsco/templates/ebsco-results.tpl.php b/ebsco/templates/ebsco-results.tpl.php index b224c2d..7450c01 100755 --- a/ebsco/templates/ebsco-results.tpl.php +++ b/ebsco/templates/ebsco-results.tpl.php @@ -42,7 +42,7 @@ } if ($search_time){ - echo "," . t('query time') . ":" . check_plain(round($search_time, 2)) . " s"; + echo ", " . t('query time') . ": " . check_plain(round($search_time, 2)) . " s"; } print $sort_form; From 0d154074b3c7b4d9e60752e9837fa862aaa96842 Mon Sep 17 00:00:00 2001 From: "Francisco J. Seva" Date: Thu, 3 Aug 2017 11:35:17 +0200 Subject: [PATCH 3/3] Changes related to theme variables and template * remove conditional sentence to display top pager * Remove theme variables and add function to set a better number format in search result count. --- ebsco/ebsco.module | 14 +++++++++++++- ebsco/templates/ebsco-results.tpl.php | 6 +++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ebsco/ebsco.module b/ebsco/ebsco.module index 3d3740b..455c597 100644 --- a/ebsco/ebsco.module +++ b/ebsco/ebsco.module @@ -942,7 +942,7 @@ function ebsco_get_search_results() { $variables['records'] = $_ebsco_document->records(); $variables['record_start'] = $_ebsco_document->record_start(); $variables['record_end'] = $_ebsco_document->record_end(); - $variables['record_count'] = $_ebsco_document->record_count(); + $variables['record_count'] = ebsco_result_format($_ebsco_document->record_count()); $variables['search_view'] = $_ebsco_document->search_view(); $variables['search_time'] = $_ebsco_document->search_time(); $variables['relatedContent'] = $_ebsco_document->relatedContent(); @@ -1088,3 +1088,15 @@ function auto_link($string) { ); return $linkedString; } + +function ebsco_result_format($num) { + $x = round($num); + $x_number_format = number_format($x); + $x_array = explode(',', $x_number_format); + $x_parts = array('K', 'M', 'B', 'T'); + $x_count_parts = count($x_array) - 1; + $x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : ''); + $x_display .= $x_parts[$x_count_parts - 1]; + + return $x_display; +} \ No newline at end of file diff --git a/ebsco/templates/ebsco-results.tpl.php b/ebsco/templates/ebsco-results.tpl.php index 7450c01..2a78345 100755 --- a/ebsco/templates/ebsco-results.tpl.php +++ b/ebsco/templates/ebsco-results.tpl.php @@ -51,9 +51,9 @@ print $custom_area; } - if (!$hide_top_pager) { - print $pager; - } + + print $pager; + if (!user_is_logged_in()) {