Skip to content

Commit

Permalink
terms tool integrated to lisencing, ebsco service added
Browse files Browse the repository at this point in the history
  • Loading branch information
queryluke committed Sep 8, 2018
1 parent 195c8f2 commit 9474f01
Show file tree
Hide file tree
Showing 46 changed files with 780 additions and 2,930 deletions.
38 changes: 38 additions & 0 deletions common/safe_file_rewrite.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php


if (!function_exists('safe_file_rewrite')) {
/**
* Safely rewrites a file
*
* @param string $fileName A path to a file
*
* @param string $dataToSave the string to rewrite the file
*/
function safe_file_rewrite($fileName, $dataToSave)
{
if (!is_writable($fileName)) {
throw new Exception("$fileName is not writeable.");
}

if ($fp = fopen($fileName, 'w')) {
$startTime = microtime(TRUE);

do {
$canWrite = flock($fp, LOCK_EX);
// If lock not obtained sleep for 0 - 100 milliseconds, to avoid collision and CPU load
if (!$canWrite) {
usleep(round(rand(0, 100) * 1000));
}
} while ((!$canWrite) and ((microtime(TRUE) - $startTime) < 5));

//file was locked so now we can store information
if ($canWrite) {
fwrite($fp, $dataToSave);
flock($fp, LOCK_UN);
}
fclose($fp);
}
}

}
29 changes: 29 additions & 0 deletions common/write_php_ini.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

require_once 'safe_file_rewrite.php';

if (!function_exists('write_php_ini')) {
/**
* Safely writes to a .ini file from an array
*
* @param string $file A path to a .ini file
*
* @param array $array The array to write as a .ini file
* integer key of the column you wish to retrieve, or it
* may be the string key name for an associative array.
*/
function write_php_ini($file, $array)
{
$res = array();
foreach($array as $key => $val)
{
if(is_array($val))
{
$res[] = "[$key]";
foreach($val as $skey => $sval) $res[] = "$skey = ".(is_numeric($sval) ? $sval : '"'.addcslashes($sval, '"').'"');
}
else $res[] = "$key = ".(is_numeric($val) ? $val : '"'.addcslashes($val, '"').'"');
}
safe_file_rewrite($file, implode("\r\n", $res));
}
}
22 changes: 22 additions & 0 deletions licensing/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@

<?php } ?>

<?php

//if the Terms Tool is used, display options
if ($config->settings->useTermsToolFunctionality == 'Y') { ?>

<br />
<br />

<table class="headerTable">
<tr><td>
<span class="headerText"><?php echo _("Terms Tool Settings");?></span>&nbsp;&nbsp;<span id='span_TermsTool_response'></span>
<br /><a href="ajax_forms.php?action=getTermsToolSettingsForm&height=158&width=265&modal=true" class="thickbox"><?php echo _("edit"); ?></a>
<br />
<br />
<div id='div_TermsTool'>
<img src = "images/circle.gif"><?php echo _("Loading...");?>
</div>
</td></tr>
</table>

<?php } ?>

<br />

<script type="text/javascript" src="js/admin.js"></script>
Expand Down
114 changes: 114 additions & 0 deletions licensing/admin/classes/domain/EBSCOService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php
/*
**************************************************************************************************************************
** CORAL Licensing Module Terms Tool Add-On v. 1.0
**
** Copyright (c) 2010 University of Notre Dame
**
** This file is part of CORAL.
**
** CORAL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
**
** CORAL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License along with CORAL. If not, see <http://www.gnu.org/licenses/>.
**
**************************************************************************************************************************
*/



class EBSCOService extends Object {

protected $issn;
protected $isbn;
protected $config;
protected $error;
protected $open_url;
protected $object_title;

protected function init(NamedArguments $arguments) {
parent::init($arguments);
$this->issn = $arguments->issn;
$this->isbn = $arguments->isbn;
$this->config = new Configuration;

//determine the full open URL
//get the ISBN or ISSN passed in
if ($this->isbn){
$stringAppend = $this->isbn;
}else{
$stringAppend = $this->issn;
}

//get the client identifier out of the config terms
$client_identifier = $this->config->terms->client_identifier;

$this->open_url = "https://api.ebsco.io/rm/rmaccounts/" . $client_identifier . "/titles?search=" . $stringAppend . "&searchfield=isxn&selection=selected&orderby=relevance&count=5&offset=1";
}


public function getTargets() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->open_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'x-api-key: '.$this->config->terms->sid,
]);

//Make the call to EBSCO KB and load results
$response = curl_exec($ch);
curl_close ($ch);

$responseArray = json_decode($response, true);

//get the title of the resource to use in getTitle()
$this->object_title = $responseArray['titles'][0]['titleName'];

$targetArray = array();

//get the package name and URL for all packages and put into target array
foreach($responseArray['titles'] as $title) {
foreach($title['customerResourcesList'] as $package)
if ($package['url']) {
$targetArray[] = array(
'public_name' => $package['packageName'],
'target_url' => $package['url']
);
}
}

return $targetArray;
}


public function getTitle() {

//get title for object from variable
$title = $this->object_title;

//alternatively like SFX and SerialsSolutions: make a new call to EBSCO KB and load results
/*
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$this->open_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/json',
'x-api-key: '.$this->config->terms->sid,
]);
$response = curl_exec($ch);
curl_close ($ch);
$responseArray = json_decode($response, true);
$title = $responseArray['titles'][0]['titleName'];
*/

return $title;
}

}

?>
14 changes: 14 additions & 0 deletions licensing/admin/classes/domain/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,21 @@ public function removeQualifiers(){



//returns most recent update date for this expression
public function getLastUpdateDate(){

$query = "SELECT date_format(MAX(updateDate), '%m/%d/%Y') lastUpdateDate FROM (
SELECT MAX(lastUpdateDate) updateDate
FROM Expression WHERE expressionID='" . $this->expressionID . "'
UNION
SELECT MAX(lastUpdateDate) updateDate
FROM ExpressionNote WHERE expressionID='" . $this->expressionID . "') allDates;";

$result = $this->db->processQuery($query, 'assoc');

return $result['lastUpdateDate'];

}



Expand Down
95 changes: 95 additions & 0 deletions licensing/admin/classes/domain/ExpressionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,103 @@ public function removeExpressionType(){



public function reorderTargets($targetsArray){
$topTargetArray = array();
$bottomTargetArray = array();
$reorderedArray = array();

$targetArray = array();
foreach ($targetsArray as $i => $targetArray){
if (count($this->getExpressionsByResource($targetArray['public_name'])) > 0){
array_push($topTargetArray, $targetArray);
}else{
array_push($bottomTargetArray, $targetArray);
}
}

$targetArray = array();
foreach ($topTargetArray as $targetArray){
array_push($reorderedArray, $targetArray);
}


foreach ($bottomTargetArray as $targetArray){
array_push($reorderedArray, $targetArray);
}

return $reorderedArray;

}





//returns array of expression objects
public function getExpressionsByResource($resourceName){

$query = ("SELECT E.expressionID
FROM Document D, SFXProvider SP, Expression E
WHERE D.documentID = E.documentID
AND (D.expirationDate is null || D.expirationDate = '0000-00-00')
AND SP.documentID = D.documentID
AND E.productionUseInd='1'
AND E.expressionTypeID = '" . $this->expressionTypeID . "'
AND SP.shortName = '" . $resourceName . "';");


$result = $this->db->processQuery($query, 'assoc');

$objects = array();

//need to do this since it could be that there's only one request and this is how the dbservice returns result
if (isset($result['expressionID'])){
$object = new Expression(new NamedArguments(array('primaryKey' => $result['expressionID'])));
array_push($objects, $object);
}else{
foreach ($result as $row) {
$object = new Expression(new NamedArguments(array('primaryKey' => $row['expressionID'])));
array_push($objects, $object);
}
}

return $objects;
}






//returns array of expression type ids
public function getExpressionTypesByResource($resourceName){

$query = ("SELECT distinct E.expressionTypeID
FROM Document D, SFXProvider SP, Expression E, ExpressionType ET
WHERE D.documentID = E.documentID
AND (D.expirationDate is null || D.expirationDate = '0000-00-00')
AND SP.documentID = D.documentID
AND E.productionUseInd='1'
AND ET.expressionTypeID = E.expressionTypeID
AND SP.shortName = '" . $resourceName . "'
ORDER BY ET.shortName;");


$result = $this->db->processQuery($query, 'assoc');

$expressionTypeArray = array();

//need to do this since it could be that there's only one result and this is how the dbservice returns result
if (isset($result['expressionTypeID'])){
$expressionTypeArray[] = $result['expressionTypeID'];
}else{
foreach ($result as $row) {
$expressionTypeArray[] = $row['expressionTypeID'];
}
}

return $expressionTypeArray;
}


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected function init(NamedArguments $arguments) {
}


//get the sfx open URL out of the config settings
$open_url = $this->config->settings->open_url;
//get the sfx open URL out of the config terms
$open_url = $this->config->terms->open_url;

//check if there is already a ? in the URL so that we don't add another when appending the parms
if (strpos($open_url, "?") > 0){
Expand All @@ -53,7 +53,7 @@ protected function init(NamedArguments $arguments) {
}


$sid = $this->config->settings->sid;
$sid = $this->config->terms->sid;
if ($sid){
$open_url .= "rfr_id=info:sid/" . $sid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ protected function init(NamedArguments $arguments) {
$stringAppend = "&rft.issn=" . $this->issn;
}

//get the client identifier out of the config settings
$client_identifier = $this->config->settings->client_identifier;
//get the client identifier out of the config terms
$client_identifier = $this->config->terms->client_identifier;

$this->open_url = "http://" . $client_identifier . ".openurl.xml.serialssolutions.com/openurlxml?version=1.0&url_ver=Z39.88-2004" . $stringAppend;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function init(NamedArguments $arguments) {
public function getTermsToolObj() {

//return correct object for terms tool
$className = $this->config->settings->resolver . "Service";
$className = $this->config->terms->resolver . "Service";

try{
$obj=new $className(new NamedArguments(array('issn' => $this->issn, 'isbn' => $this->isbn)));
Expand Down
6 changes: 6 additions & 0 deletions licensing/admin/configuration_sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ host = ""
name = ""
username = ""
password = ""

[terms]
resolver=
open_url=
sid=
client_identifier=
Loading

0 comments on commit 9474f01

Please sign in to comment.