@ -1,16 +1,16 @@
<?php
<?php
/**
/**
* The EBSCO Document model class
* @file
* The EBSCO Document model class.
*
*
* It provides all the methods and properties needed for :
* It provides all the methods and properties needed for :
* - setting up and performing API calls
* - setting up and performing API calls
* - displaying results in UI
* - displaying results in UI
* - displaying statistics about the search, etc
* - displaying statistics about the search, etc.
*
*
* PHP version 5
* PHP version 5
*
*
*
* Copyright [2017] [EBSCO Information Services]
* Copyright [2017] [EBSCO Information Services]
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
@ -29,139 +29,148 @@
require_once 'EBSCOAPI.php';
require_once 'EBSCOAPI.php';
require_once 'EBSCORecord.php';
require_once 'EBSCORecord.php';
class EBSCODocument
{
/**
/**
* The EBSCOAPI object that performs the API calls
*
*/
class EBSCODocument {
/**
* The EBSCOAPI object that performs the API calls.
*
* @global object EBSCOAPI
* @global object EBSCOAPI
*/
*/
private $eds = null;
private $eds = NULL ;
/**
/**
* The associative array of current request parameters
* The associative array of current request parameters.
*
* @global array
* @global array
*/
*/
private $params = array();
private $params = array();
/**
/**
* The associative array of EBSCO results returned by a Search API call
* The associative array of EBSCO results returned by a Search API call
* #global array
* #global array.
*/
*/
private $results = array();
private $results = array();
/**
/**
* The associative array of data returned by a Retrieve API call
* The associative array of data returned by a Retrieve API call.
*
* @global array
* @global array
*/
*/
private $result = array();
private $result = array();
/**
/**
* The array of data returned by an Info API call
* The array of data returned by an Info API call.
*
* @global array
* @global array
*/
*/
private $info = array();
private $info = array();
/**
/**
* The EBSCORecord model returned by a Retrieve API call
* The EBSCORecord model returned by a Retrieve API call
* #global object EBSCORecord
* #global object EBSCORecord.
*/
*/
private $record = null ;
private $record = NULL ;
/**
/**
* The array of EBSCORecord models returned by a Search API call
* The array of EBSCORecord models returned by a Search API call
* #global array of EBSCORecord objects
* #global array of EBSCORecord objects.
*/
*/
private $records = array();
private $records = array();
/**
/**
* The array of EBSCORecord models returned by a Search API call
* The array of EBSCORecord models returned by a Search API call
* #global array of RelatedRecords
* #global array of RelatedRecords.
*/
*/
private $relatedContent = array();
private $relatedContent = array();
private $autoSuggestTerms = array();
private $autoSuggestTerms = array();
/**
/**
* The array of filters currently applied
* The array of filters currently applied.
*
* @global array
* @global array
*/
*/
private $filters = array();
private $filters = array();
/**
/**
* Maximum number of results returned by Search API call
* Maximum number of results returned by Search API call .
*
* @global integer
* @global integer
*/
*/
private $limit = 10;
private $limit = 10;
/**
/**
* Default level of data detail
* Default level of data detail.
*
* @global string
* @global string
*/
*/
private $amount = 'brief';
private $amount = 'brief';
/**
/**
* Maximum number of links displayed by the pagination
* Maximum number of links displayed by the pagination.
*
* @global integer
* @global integer
*/
*/
private static $page_links = 10;
private static $page_links = 10;
/**
/**
* Limit options
* Limit options
* global array
* global array.
*/
*/
private static $limit_options = array(
private static $limit_options = array(
10 => 10,
10 => 10,
20 => 20,
20 => 20,
30 => 30,
30 => 30,
40 => 40,
40 => 40,
50 => 50
50 => 50,
);
);
/**
/**
* Sort options
* Sort options
* global array
* global array.
*/
*/
private static $sort_options = array(
private static $sort_options = array(
'relevance' => 'Relevance',
'relevance' => 'Relevance',
'date_desc' => 'Date Descending',
'date_desc' => 'Date Descending',
'date_asc' => 'Date Ascending'
'date_asc' => 'Date Ascending',
);
);
/**
/**
* Amount options
* Amount options
* global array
* global array.
*/
*/
private static $amount_options = array(
private static $amount_options = array(
'detailed' => 'Detailed',
'detailed' => 'Detailed',
'brief' => 'Brief',
'brief' => 'Brief',
'title' => 'Title Only'
'title' => 'Title Only',
);
);
/**
/**
* Bool options
* Bool options
* global array
* global array.
*/
*/
private static $bool_options = array(
private static $bool_options = array(
'AND' => 'All terms',
'AND' => 'All terms',
'OR' => 'Any terms',
'OR' => 'Any terms',
'NOT' => 'No terms'
'NOT' => 'No terms',
);
);
/**
/**
* Search mode options
* Search mode options
* global array
* global array.
*/
*/
private static $mode_options = array(
private static $mode_options = array(
'all' => 'All search terms',
'all' => 'All search terms',
'bool' => 'Boolean / Phrase',
'bool' => 'Boolean / Phrase',
'any' => 'Any search terms',
'any' => 'Any search terms',
'smart' => 'SmartText Searching'
'smart' => 'SmartText Searching',
);
);
/**
/**
* Basic search type options
* Basic search type options
* global array
* global array.
*/
*/
private static $basic_search_type_options = array(
private static $basic_search_type_options = array(
'AllFields' => 'All Text',
'AllFields' => 'All Text',
@ -169,12 +178,12 @@ class EBSCODocument
'Author' => 'Author',
'Author' => 'Author',
'Subject' => 'Subject terms',
'Subject' => 'Subject terms',
'Source' => 'Source',
'Source' => 'Source',
'Abstract' => 'Abstract'
'Abstract' => 'Abstract',
);
);
/**
/**
* Advanced search type options
* Advanced search type options
* global array
* global array.
*/
*/
private static $advanced_search_type_options = array(
private static $advanced_search_type_options = array(
'AllFields' => 'All Text',
'AllFields' => 'All Text',
@ -184,7 +193,7 @@ class EBSCODocument
'Source' => 'Journal Title/Source',
'Source' => 'Journal Title/Source',
'Abstract' => 'Abstract',
'Abstract' => 'Abstract',
'ISBN' => 'ISBN',
'ISBN' => 'ISBN',
'ISSN' => 'ISSN'
'ISSN' => 'ISSN',
);
);
private $local_ips = "";
private $local_ips = "";
@ -192,10 +201,10 @@ class EBSCODocument
/**
/**
* Constructor.
* Constructor.
*
*
* @param array $data Raw data from the EBSCO search representing the record.
* @param array $data
* Raw data from the EBSCO search representing the record.
*/
*/
public function __construct($params = null)
public function __construct($params = NULL) {
{
$this->eds = new EBSCOAPI(array(
$this->eds = new EBSCOAPI(array(
'password' => variable_get('ebsco_password'),
'password' => variable_get('ebsco_password'),
'user' => variable_get('ebsco_user'),
'user' => variable_get('ebsco_user'),
@ -204,7 +213,7 @@ class EBSCODocument
'organization' => variable_get('ebsco_organization'),
'organization' => variable_get('ebsco_organization'),
'local_ip_address' => variable_get('ebsco_local_ips'),
'local_ip_address' => variable_get('ebsco_local_ips'),
'guest' => variable_get('ebsco_guest'),
'guest' => variable_get('ebsco_guest'),
'log' => variable_get('ebsco_log')
'log' => variable_get('ebsco_log'),
));
));
$this->params = $params ? $params : $_REQUEST;
$this->params = $params ? $params : $_REQUEST;
@ -212,50 +221,46 @@ class EBSCODocument
$this->amount = variable_get('ebsco_default_amount') ? variable_get('ebsco_default_amount') : $this->amount;
$this->amount = variable_get('ebsco_default_amount') ? variable_get('ebsco_default_amount') : $this->amount;
}
}
/**
/**
* Perform the API Info call
* Perform the API Info call.
*
*
* @return array
* @return array
*/
*/
public function info()
public function info() {
{
$this->info = $this->eds->apiInfo();
$this->info = $this->eds->apiInfo();
return $this->info;
return $this->info;
}
}
/**
/**
* Perform the API Retrieve call
* Perform the API Retrieve call.
*
*
* @return array
* @return array
*/
*/
public function retrieve()
public function retrieve() {
{
list($an, $db) = isset($this->params['id']) ? explode('|', $this->params['id'], 2) : array(NULL, NULL);
list($an, $db) = isset($this->params['id']) ? explode('|', $this->params['id'], 2) : array(null, null);
$this->result = $this->eds->apiRetrieve($an, $db);
$this->result = $this->eds->apiRetrieve($an, $db);
return $this->result;
return $this->result;
}
}
/**
/**
* Perform the API Search call
* Perform the API Search call.
*
*
* @return array
* @return array
*/
*/
public function search()
public function search() {
{
$search = array();
$search = array();
if (isset($this->params['lookfor']) & & isset($this->params['type'])) {
if (isset($this->params['lookfor']) & & isset($this->params['type'])) {
$search = array(
$search = array(
'lookfor' => $this->params['lookfor'],
'lookfor' => $this->params['lookfor'],
'index' => $this->params['type']
'index' => $this->params['type'],
);
);
} else if (isset($this->params['group'])) {
}
elseif (isset($this->params['group'])) {
$search = $this->params;
$search = $this->params;
} else {
}
else {
return array();
return array();
}
}
@ -263,29 +268,27 @@ class EBSCODocument
$page = isset($this->params['page']) ? $this->params['page'] + 1 : 1;
$page = isset($this->params['page']) ? $this->params['page'] + 1 : 1;
$limit = $this->limit;
$limit = $this->limit;
$sort = isset($this->params['sort']) ? $this->params['sort'] : 'relevance';
$sort = isset($this->params['sort']) ? $this->params['sort'] : 'relevance';
$amount = isset($this->params['amount']) ? $this->params['amount'] : 'brief'; //
$amount = isset($this->params['amount']) ? $this->params['amount'] : 'brief'; $mode = isset($this->params['mode']) ? $this->params['mode'] : 'all';
$mode = isset($this->params['mode']) ? $this->params['mode'] : 'all';
// Check if research starters , EMP are active.
//check if research starters , EMP are active
$info = $this->info();
$info = $this->info();
$rs=false ;
$rs = FALSE ;
$emp=false ;
$emp = FALSE ;
if ($info["relatedContent"]) {
if ($info["relatedContent"]) {
foreach ($info["relatedContent"] as $related) {
foreach ($info["relatedContent"] as $related) {
if (($related["Type"] == "rs") and ($related["DefaultOn"] == "y")) {
if (($related["Type"] == "rs") and ($related["DefaultOn"] == "y")) {
$rs=true ;
$rs = TRUE ;
}
}
if (($related["Type"] == "emp") and ($related["DefaultOn"] == "y")) {
if (($related["Type"] == "emp") and ($related["DefaultOn"] == "y")) {
$emp=true ;
$emp = TRUE ;
}
}
}
}
}
}
$autosug=false ;
$autosug = FALSE ;
if ($info["didYouMean"]) {
if ($info["didYouMean"]) {
if ($info["didYouMean"][0]["DefaultOn"] == "y") {
if ($info["didYouMean"][0]["DefaultOn"] == "y") {
$autosug=true ;
$autosug = TRUE ;
}
}
}
}
@ -294,14 +297,12 @@ class EBSCODocument
return $this->results;
return $this->results;
}
}
/**
/**
* Get the EBSCORecord model for the result
* Get the EBSCORecord model for the result.
*
*
** @return array
* * @return array.
*/
*/
public function record()
public function record() {
{
if (empty($this->record) & & !(empty($this->result))) {
if (empty($this->record) & & !(empty($this->result))) {
$this->record = new EBSCORecord($this->result);
$this->record = new EBSCORecord($this->result);
}
}
@ -309,19 +310,17 @@ class EBSCODocument
return $this->record;
return $this->record;
}
}
/**
/**
* Get the EBSCORecord models array from results array
* Get the EBSCORecord models array from results array.
*
*
** @return array
* * @return array.
*/
*/
public function records()
public function records() {
{
if ($this->record instanceof EBSCOException) {
if ($this->record instanceof EBSCOException) {
return null ;
return NULL ;
}
}
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return null ;
return NULL ;
}
}
if (empty($this->records) & & !(empty($this->results))) {
if (empty($this->records) & & !(empty($this->results))) {
foreach ($this->results['documents'] as $result) {
foreach ($this->results['documents'] as $result) {
@ -332,148 +331,133 @@ class EBSCODocument
return $this->records;
return $this->records;
}
}
/**
public function relatedContent()
*
{
*/
public function relatedContent() {
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return null ;
return NULL ;
}
}
$this->relatedContent = isset($this->results['relatedContent']) ? $this->results['relatedContent'] : array();
$this->relatedContent = isset($this->results['relatedContent']) ? $this->results['relatedContent'] : array();
return $this->relatedContent;
return $this->relatedContent;
}
}
public function autoSuggestTerms()
/**
{
*
*/
public function autoSuggestTerms() {
$this->autoSuggestTerms = isset($this->results['autoSuggestTerms']) ? $this->results['autoSuggestTerms'] : null;
$this->autoSuggestTerms = isset($this->results['autoSuggestTerms']) ? $this->results['autoSuggestTerms'] : NULL ;
return $this->autoSuggestTerms;
return $this->autoSuggestTerms;
}
}
/**
/**
* Get the pagination HTML string
* Get the pagination HTML string.
*
*
** @return HTML string
* * @return HTML string.
*/
*/
public function pager()
public function pager() {
{
$pager = NULL;
$pager = null;
try {
try
{
if ($this->has_records()) {
if ($this->has_records()) {
pager_default_initialize($this->record_count() / $this->limit, 1);
pager_default_initialize($this->record_count() / $this->limit, 1);
$pager = theme('pager', array('tags' => null , 'quantity' => self::$page_links));
$pager = theme('pager', array('tags' => NULL , 'quantity' => self::$page_links));
$pager = preg_replace('/< li class = "pager-last last" > (.*)< \/li>/', '', $pager);
$pager = preg_replace('/< li class = "pager-last last" > (.*)< \/li>/', '', $pager);
}
}
}
}
catch(Exception $e)
catch (Exception $e) {
{
}
}
return $pager;
return $pager;
}
}
/********************************************************
/********************************************************
*
*
* Getters (class methods)
* Getters (class methods)
*
*
********************************************************/
********************************************************/
/**
/**
* Getter for sort options
* Getter for sort options.
*
* @return array
* @return array
*/
*/
public static function limit_options()
public static function limit_options() {
{
return self::$limit_options;
return self::$limit_options;
}
}
/**
/**
* Getter for sort options
* Getter for sort options.
*
* @return array
* @return array
*/
*/
public static function sort_options()
public static function sort_options() {
{
return self::$sort_options;
return self::$sort_options;
}
}
/**
/**
* Getter for amount options
* Getter for amount options.
*
* @return array
* @return array
*/
*/
public static function amount_options()
public static function amount_options() {
{
return self::$amount_options;
return self::$amount_options;
}
}
/**
/**
* Getter for boolean options
* Getter for boolean options.
*
* @return array
* @return array
*/
*/
public static function bool_options()
public static function bool_options() {
{
return self::$bool_options;
return self::$bool_options;
}
}
/**
/**
* Getter for search mode options
* Getter for search mode options.
*
* @return array
* @return array
*/
*/
public static function mode_options()
public static function mode_options() {
{
return self::$mode_options;
return self::$mode_options;
}
}
/**
/**
* Getter for Basic search type options
* Getter for Basic search type options.
*
* @return array
* @return array
*/
*/
public static function basic_search_type_options()
public static function basic_search_type_options() {
{
return self::$basic_search_type_options;
return self::$basic_search_type_options;
}
}
/**
/**
* Getter for Advanced search type options
* Getter for Advanced search type options.
*
* @return array
* @return array
*/
*/
public static function advanced_search_type_options()
public static function advanced_search_type_options() {
{
return self::$advanced_search_type_options;
return self::$advanced_search_type_options;
}
}
/********************************************************
/********************************************************
*
*
* Helper methods
* Helper methods
*
*
********************************************************/
********************************************************/
/**
/**
* Get the expanders.
* Get the expanders.
*
*
* @return array
* @return array
*/
*/
public function expanders()
public function expanders() {
{
$expanders = array();
$expanders = array();
try
try {
{
if ($this->info instanceof EBSCOException) {
if ($this->info instanceof EBSCOException)
{
return $expanders;
return $expanders;
}
}
$actions = array();
$actions = array();
@ -485,27 +469,23 @@ class EBSCODocument
$expanders = isset($this->info['expanders']) ? $this->info['expanders'] : array();
$expanders = isset($this->info['expanders']) ? $this->info['expanders'] : array();
foreach ($expanders as $key => $expander) {
foreach ($expanders as $key => $expander) {
if (in_array($expander['Action'], $actions)) {
if (in_array($expander['Action'], $actions)) {
$expanders[$key]['selected'] = true ;
$expanders[$key]['selected'] = TRUE ;
}
}
}
}
}
}
catch(Exception $e)
catch (Exception $e) {
{
}
}
return $expanders;
return $expanders;
}
}
/**
/**
* Get the facets.
* Get the facets.
*
*
* @return array
* @return array
*/
*/
public function facets()
public function facets() {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return array();
return array();
}
}
@ -518,9 +498,9 @@ class EBSCODocument
$facets = isset($this->results['facets']) ? $this->results['facets'] : array();
$facets = isset($this->results['facets']) ? $this->results['facets'] : array();
foreach ($facets as $key => $cluster) {
foreach ($facets as $key => $cluster) {
foreach ($cluster['Values'] as $k => $facet) {
foreach ($cluster['Values'] as $k => $facet) {
$is_applied = false ;
$is_applied = FALSE ;
if (in_array($facet['Action'], $actions)) {
if (in_array($facet['Action'], $actions)) {
$is_applied = true ;
$is_applied = TRUE ;
}
}
$facets[$key]['Values'][$k]['applied'] = $is_applied;
$facets[$key]['Values'][$k]['applied'] = $is_applied;
}
}
@ -529,14 +509,12 @@ class EBSCODocument
return $facets;
return $facets;
}
}
/**
/**
* Get the filters.
* Get the filters.
*
*
* @return array
* @return array
*/
*/
public function filters()
public function filters() {
{
if (!empty($_REQUEST['filter'])) {
if (!empty($_REQUEST['filter'])) {
$labels = array();
$labels = array();
foreach ($this->info['limiters'] as $limiter) {
foreach ($this->info['limiters'] as $limiter) {
@ -549,17 +527,19 @@ class EBSCODocument
if (substr($temp, -1, 1) == ')') {
if (substr($temp, -1, 1) == ')') {
$temp = substr($temp, 0, -1);
$temp = substr($temp, 0, -1);
}
}
// Do not display addfacetfilter, addlimiter or addexpander strings
// Do not display addfacetfilter, addlimiter or addexpander strings.
if (preg_match('/\:/', $filter)) {
if (preg_match('/\:/', $filter)) {
list($field, $value) = explode(':', $temp, 2);
list($field, $value) = explode(':', $temp, 2);
$displayField = isset($labels[$field]) ? $labels[$field] : $field;
$displayField = isset($labels[$field]) ? $labels[$field] : $field;
$displayValue = $value == 'y' ? 'yes' : $value;
$displayValue = $value == 'y' ? 'yes' : $value;
} else if (preg_match('/addexpander/', $filter)) {
}
elseif (preg_match('/addexpander/', $filter)) {
$field = $temp;
$field = $temp;
$value = 'y';
$value = 'y';
$displayField = isset($labels[$field]) ? $labels[$field] : $field;
$displayField = isset($labels[$field]) ? $labels[$field] : $field;
$displayValue = 'yes';
$displayValue = 'yes';
} else {
}
else {
$field = $value = $displayField = $displayValue = $filter;
$field = $value = $displayField = $displayValue = $filter;
}
}
@ -576,17 +556,14 @@ class EBSCODocument
return $this->filters;
return $this->filters;
}
}
/**
/**
* Get the limiters.
* Get the limiters.
*
*
* @return array
* @return array
*/
*/
public function limiters()
public function limiters() {
{
$actions = array(); $ids = array();
$actions = array(); $ids = array();
if ($this->info instanceof EBSCOException)
if ($this->info instanceof EBSCOException) {
{
return array();
return array();
}
}
$filters = $this->filters();
$filters = $this->filters();
@ -597,7 +574,7 @@ class EBSCODocument
$limiters = isset($this->info['limiters']) ? $this->info['limiters'] : array();
$limiters = isset($this->info['limiters']) ? $this->info['limiters'] : array();
foreach ($limiters as $key => $cluster) {
foreach ($limiters as $key => $cluster) {
// multi select limiter
// Multi select limiter.
if (!empty($cluster['Values'])) {
if (!empty($cluster['Values'])) {
foreach ($cluster['Values'] as $limiter) {
foreach ($cluster['Values'] as $limiter) {
$action = $limiter['Action'];
$action = $limiter['Action'];
@ -605,17 +582,19 @@ class EBSCODocument
$limiters[$key]['selected'][] = $limiter['Action'];
$limiters[$key]['selected'][] = $limiter['Action'];
}
}
}
}
// date limiter
// Date limiter.
} else if ($cluster['Type'] == 'ymrange') {
}
elseif ($cluster['Type'] == 'ymrange') {
$id = $cluster['Id'];
$id = $cluster['Id'];
if (($k = array_search($id, $ids)) !== false ) {
if (($k = array_search($id, $ids)) !== FALSE ) {
$limiters[$key]['selected'] = $filters[$k]['action'];
$limiters[$key]['selected'] = $filters[$k]['action'];
}
}
// other limiters
// Other limiters.
} else {
}
else {
$action = str_replace('value', 'y', $cluster['Action']);
$action = str_replace('value', 'y', $cluster['Action']);
if (in_array($action, $actions)) {
if (in_array($action, $actions)) {
$limiters[$key]['selected'] = true ;
$limiters[$key]['selected'] = TRUE ;
}
}
}
}
}
}
@ -623,28 +602,24 @@ class EBSCODocument
return $limiters;
return $limiters;
}
}
/**
/**
* Get the total number of records.
* Get the total number of records.
*
*
* @return integer
* @return int
*/
*/
public function record_count()
public function record_count() {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return 0;
return 0;
}
}
return !empty($this->results) ? $this->results['recordCount'] : 0;
return !empty($this->results) ? $this->results['recordCount'] : 0;
}
}
/**
/**
* Get the number of end record.
* Get the number of end record.
*
*
* @return integer
* @return int
*/
*/
public function record_end()
public function record_end() {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return -1;
return -1;
}
}
@ -653,28 +628,24 @@ class EBSCODocument
return $start + $count;
return $start + $count;
}
}
/**
/**
* Get the number of start record.
* Get the number of start record.
*
*
* @return integer
* @return int
*/
*/
public function record_start()
public function record_start() {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return null ;
return NULL ;
}
}
return !empty($this->results) ? $this->results['start'] + 1 : 0;
return !empty($this->results) ? $this->results['start'] + 1 : 0;
}
}
/**
/**
* Get the search time
* Get the search time.
*
*
* @return decimal number
* @return decimal number
*/
*/
public function search_time()
public function search_time() {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return 0;
return 0;
}
}
@ -682,37 +653,34 @@ class EBSCODocument
isset($this->results['searchTime']) ? $this->results['searchTime'] : 0;
isset($this->results['searchTime']) ? $this->results['searchTime'] : 0;
}
}
/**
/**
* Get the search view : basic or advanced
* Get the search view : basic or advanced.
*
*
* @return string
* @return string
*/
*/
public function search_view()
public function search_view() {
{
if (isset($_REQUEST['group'])) {
if (isset($_REQUEST['group'])) {
return 'advanced';
return 'advanced';
} else {
}
else {
return 'basic';
return 'basic';
}
}
}
}
/**
/**
* Hidden params used by UpdateForm
* Hidden params used by UpdateForm.
*
*
* @return array
* @return array
*/
*/
public function search_params()
public function search_params() {
{
$params = $this->link_search_params();
$params = $this->link_search_params();
// f ilter the params that have same values as sidebar checkboxes, otherwise they will produce duplicates
// F ilter the params that have same values as sidebar checkboxes, otherwise they will produce duplicates.
$not_allowed_values = array(
$not_allowed_values = array(
'addexpander(thesaurus)',
'addexpander(thesaurus)',
'addexpander(fulltext)',
'addexpander(fulltext)',
'addlimiter(FT:y)',
'addlimiter(FT:y)',
'addlimiter(RV:y)',
'addlimiter(RV:y)',
'addlimiter(SO:y)'
'addlimiter(SO:y)',
);
);
$params = $this->array_filter_recursive($params, function ($item) use ($not_allowed_values) {
$params = $this->array_filter_recursive($params, function ($item) use ($not_allowed_values) {
@ -722,20 +690,19 @@ class EBSCODocument
return array_filter($params);
return array_filter($params);
}
}
/**
/**
* Hidden params used by UpdateForm
* Hidden params used by UpdateForm.
*
*
* @return array
* @return array
*/
*/
public function link_search_params()
public function link_search_params() {
{
// Filter the page parameter.
// filter the page parameter
$not_allowed_keys = array('page', 'ui', 'has_js', 'op', 'submit', 'form_id', 'form_build_id');
$not_allowed_keys = array('page', 'ui', 'has_js', 'op', 'submit', 'form_id', 'form_build_id');
$query = "";
$query = "";
if(isset($_SERVER['QUERY_STRING']))
if (isset($_SERVER['QUERY_STRING'])) {
{$query = urldecode($_SERVER['QUERY_STRING']);}
$query = urldecode($_SERVER['QUERY_STRING']);
}
parse_str($query, $params);
parse_str($query, $params);
$params = $this->array_unset_recursive($params, $not_allowed_keys);
$params = $this->array_unset_recursive($params, $not_allowed_keys);
@ -743,28 +710,24 @@ class EBSCODocument
return $params;
return $params;
}
}
/**
/**
* Check if there are records in results array
* Check if there are records in results array.
*
*
** @return boolean
* * @return boolean.
*/
*/
public function has_records()
public function has_records() {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return false ;
return FALSE ;
}
}
return !empty($this->results) & & !empty($this->results['documents']);
return !empty($this->results) & & !empty($this->results['documents']);
}
}
/**
/**
* Create the last search data
* Create the last search data.
*
*
* @return void
* @return void
*/
*/
public function search_create($query = null)
public function search_create($query = NULL) {
{
if ($this->results instanceof EBSCOException) {
if ($this->results instanceof EBSCOException) {
return array();
return array();
}
}
@ -782,25 +745,21 @@ class EBSCODocument
return $last_search;
return $last_search;
}
}
/**
/**
* Save last search data in session
* Save last search data in session.
*
*
* @return void
* @return void
*/
*/
public function search_write($query = null)
public function search_write($query = NULL) {
{
$_SESSION['EBSCO']['last-search'] = $this->search_create($query);
$_SESSION['EBSCO']['last-search'] = $this->search_create($query);
}
}
/**
/**
* Load last search data from session
* Load last search data from session.
*
*
* @return array
* @return array
*/
*/
public function search_read($id = null, $op = null)
public function search_read($id = NULL, $op = NULL) {
{
$params = array();
$params = array();
$lastSearch = $_SESSION['EBSCO']['last-search'];
$lastSearch = $_SESSION['EBSCO']['last-search'];
if ($lastSearch) {
if ($lastSearch) {
@ -810,9 +769,9 @@ class EBSCODocument
$params['page'] = (int) (isset($params['page']) ? $params['page'] : 0);
$params['page'] = (int) (isset($params['page']) ? $params['page'] : 0);
$index = array_search($id, $lastSearch['records']);
$index = array_search($id, $lastSearch['records']);
// i f this is not the first scroll and if this is not a page refresh
// I f this is not the first scroll and if this is not a page refresh.
if (isset($lastSearch['current']) & & $lastSearch['current'] != $id) {
if (isset($lastSearch['current']) & & $lastSearch['current'] != $id) {
// if we change page
// If we change page.
if (($op == 'Next' & & $index % $this->limit === 0) ||
if (($op == 'Next' & & $index % $this->limit === 0) ||
($op == 'Previous' & & $index % $this->limit === 9)) {
($op == 'Previous' & & $index % $this->limit === 9)) {
$params['page'] = ($op == 'Next') ? $params['page'] + 1 : $params['page'] - 1;
$params['page'] = ($op == 'Next') ? $params['page'] + 1 : $params['page'] - 1;
@ -824,7 +783,8 @@ class EBSCODocument
if (count($lastSearch['records']) > 10) {
if (count($lastSearch['records']) > 10) {
$records = array_slice($lastSearch['records'], $index - $index % $this->limit, $this->limit);
$records = array_slice($lastSearch['records'], $index - $index % $this->limit, $this->limit);
} else {
}
else {
$records = $lastSearch['records'];
$records = $lastSearch['records'];
}
}
@ -841,7 +801,8 @@ class EBSCODocument
$lastSearch['previous'] = isset($records[8]) ? $records[8] : '';
$lastSearch['previous'] = isset($records[8]) ? $records[8] : '';
}
}
$lastSearch['next'] = isset($newSearch['records'][0]) ? $newSearch['records'][0] : '';
$lastSearch['next'] = isset($newSearch['records'][0]) ? $newSearch['records'][0] : '';
} else {
}
else {
$lastSearch['next'] = $lastSearch['records'][$index + 1];
$lastSearch['next'] = $lastSearch['records'][$index + 1];
}
}
@ -859,10 +820,12 @@ class EBSCODocument
if ($op == 'Previous') {
if ($op == 'Previous') {
$lastSearch['next'] = isset($records[1]) ? $records[1] : '';
$lastSearch['next'] = isset($records[1]) ? $records[1] : '';
}
}
} else {
}
else {
$lastSearch['previous'] = '';
$lastSearch['previous'] = '';
}
}
} else {
}
else {
$lastSearch['previous'] = $lastSearch['records'][$index - 1];
$lastSearch['previous'] = $lastSearch['records'][$index - 1];
}
}
@ -875,14 +838,12 @@ class EBSCODocument
return $lastSearch;
return $lastSearch;
}
}
/**
/**
* A recursive array_filter
* A recursive array_filter.
*
*
* @return array
* @return array
*/
*/
private function array_filter_recursive($input, $callback = null)
private function array_filter_recursive($input, $callback = NULL) {
{
foreach ($input as & $value) {
foreach ($input as & $value) {
if (is_array($value)) {
if (is_array($value)) {
$value = $this->array_filter_recursive($value, $callback);
$value = $this->array_filter_recursive($value, $callback);
@ -891,9 +852,8 @@ class EBSCODocument
return array_filter($input, $callback);
return array_filter($input, $callback);
}
}
/**
/**
* Recursive filter an array using the given $keys
* Recursive filter an array using the given $keys.
*
*
* @return array
* @return array
*/
*/
@ -912,4 +872,5 @@ class EBSCODocument
return array_filter($input);
return array_filter($input);
}
}
}
}