Skip to content

Commit

Permalink
Merge branch 'biblibre-resources_enhancements'
Browse files Browse the repository at this point in the history
  • Loading branch information
remocrevo committed Apr 20, 2015
2 parents 00f56e4 + 1611b14 commit c65b0ba
Show file tree
Hide file tree
Showing 22 changed files with 778 additions and 124 deletions.
2 changes: 1 addition & 1 deletion admin/classes/common/DBService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function disconnect() {
}

public function escapeString($value) {
return mysql_real_escape_string($value);
return mysql_real_escape_string($value, $this->db);
}

public function processQuery($sql, $type = NULL) {
Expand Down
29 changes: 29 additions & 0 deletions admin/classes/domain/IsbnOrIssn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

/*
**************************************************************************************************************************
** CORAL Resources Module 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 IsbnOrIssn extends DatabaseObject {

protected function defineIsbnOrIssn() {}

protected function overridePrimaryKeyName() {}


}

?>
14 changes: 13 additions & 1 deletion admin/classes/domain/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,21 @@ public function getNumberOfChildren(){

}

public function alreadyExists($shortName) {
$query = "SELECT count(*) orgcount FROM Organization WHERE UPPER(shortName) = '" . str_replace("'", "''", strtoupper($shortName)) . "';";
$result = $this->db->processQuery($query, 'assoc');
return $result['orgcount'];
}

public function getOrganizationIDByName($shortName) {
$query = "SELECT organizationID FROM Organization WHERE UPPER(shortName) = '" . str_replace("'", "''", strtoupper($shortName)) . "';";
$result = $this->db->processQuery($query, 'assoc');
return $result['organizationID'];
}




}

?>
?>
156 changes: 134 additions & 22 deletions admin/classes/domain/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
class Resource extends DatabaseObject {

protected function defineRelationships() {}

protected function defineIsbnOrIssn() {}

protected function overridePrimaryKeyName() {}

Expand Down Expand Up @@ -49,36 +51,88 @@ public function getResourceByTitle($title){
return $objects;
}

//returns resource objects by title
public function getResourceByIsbnOrISSN($isbnOrISSN){

$query = "SELECT DISTINCT(resourceID)
FROM IsbnOrIssn";

//returns array of related resource objects
public function getParentResource(){
$i = 0;

$query = "SELECT *
FROM ResourceRelationship
WHERE resourceID = '" . $this->resourceID . "'
AND relationshipTypeID = '1'
ORDER BY 1";
if (!is_array($isbnOrISSN)) {
$value = $isbnOrISSN;
$isbnOrISSN = array($value);
}

foreach ($isbnOrISSN as $value) {
$query .= ($i == 0) ? " WHERE " : " OR ";
$query .= "isbnOrIssn = '" . $this->db->escapeString($value) . "'";
$i++;
}

$query .= " ORDER BY 1";

$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['resourceID'])){
$object = new ResourceRelationship(new NamedArguments(array('primaryKey' => $result['resourceRelationshipID'])));
$object = new Resource(new NamedArguments(array('primaryKey' => $result['resourceID'])));
array_push($objects, $object);
}else{
foreach ($result as $row) {
$object = new Resource(new NamedArguments(array('primaryKey' => $row['resourceID'])));
array_push($objects, $object);
}
}

return $object;
return $objects;
}

public function getIsbnOrIssn() {
$query = "SELECT *
FROM IsbnOrIssn
WHERE resourceID = '" . $this->resourceID . "'
ORDER BY 1";

$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['isbnOrIssnID'])){
$object = new IsbnOrIssn(new NamedArguments(array('primaryKey' => $result['isbnOrIssnID'])));
array_push($objects, $object);
} else {
foreach ($result as $row) {
$object = new IsbnOrIssn(new NamedArguments(array('primaryKey' => $row['isbnOrIssnID'])));
array_push($objects, $object);
}

}

return $objects;

}

//returns array of parent resource objects
public function getParentResources(){
return $this->getRelatedResources('resourceID');
}


//returns array of related resource objects
//returns array of child resource objects
public function getChildResources(){
return $this->getRelatedResources('relatedResourceID');
}

// return array of related resource objects
private function getRelatedResources($key) {

$query = "SELECT *
$query = "SELECT *
FROM ResourceRelationship
WHERE relatedResourceID = '" . $this->resourceID . "'
WHERE $key = '" . $this->resourceID . "'
AND relationshipTypeID = '1'
ORDER BY 1";

Expand All @@ -87,7 +141,7 @@ public function getChildResources(){
$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['relatedResourceID'])){
if (isset($result[$key])){
$object = new ResourceRelationship(new NamedArguments(array('primaryKey' => $result['resourceRelationshipID'])));
array_push($objects, $object);
}else{
Expand All @@ -98,9 +152,8 @@ public function getChildResources(){
}

return $objects;
}


}

//returns array of purchase site objects
public function getResourcePurchaseSites(){
Expand Down Expand Up @@ -884,7 +937,7 @@ public static function getSearchDetails() {
}
if ($search['resourceISBNOrISSN']) {
$resourceISBNOrISSN = mysql_real_escape_string(str_replace("-","",$search['resourceISBNOrISSN']));
$whereAdd[] = "REPLACE(R.isbnOrISSN,'-','') = '" . $resourceISBNOrISSN . "'";
$whereAdd[] = "REPLACE(I.isbnOrIssn,'-','') = '" . $resourceISBNOrISSN . "'";
$searchDisplay[] = "ISSN/ISBN: " . $search['resourceISBNOrISSN'];
}
if ($search['fund']) {
Expand All @@ -899,6 +952,15 @@ public static function getSearchDetails() {
$whereAdd[] = "(R.statusID != $completedStatusID AND RS.stepName = '" . mysql_real_escape_string($search['stepName']) . "' AND RS.stepStartDate IS NOT NULL AND RS.stepEndDate IS NULL)";
$searchDisplay[] = "Routing Step: " . $search['stepName'];
}


if ($search['parent'] != null) {
$parentadd = "(" . $search['parent'] . ".relationshipTypeID = 1";
$parentadd .= ")";
$whereAdd[] = $parentadd;
}



if ($search['statusID']) {
$whereAdd[] = "R.statusID = '" . mysql_real_escape_string($search['statusID']) . "'";
Expand Down Expand Up @@ -1051,7 +1113,6 @@ public static function getSearchDetails() {

$page = $search['page'];
$recordsPerPage = $search['recordsPerPage'];

return array("where" => $whereAdd, "page" => $page, "order" => $orderBy, "perPage" => $recordsPerPage, "display" => $searchDisplay);
}

Expand Down Expand Up @@ -1084,7 +1145,7 @@ public function searchQuery($whereAdd, $orderBy = '', $limit = '', $count = fals
$groupBy = "";
} else {
$select = "SELECT R.resourceID, R.titleText, AT.shortName acquisitionType, R.createLoginID, CU.firstName, CU.lastName, R.createDate, S.shortName status,
GROUP_CONCAT(DISTINCT A.shortName ORDER BY A.shortName DESC SEPARATOR '<br />') aliases";
GROUP_CONCAT(DISTINCT A.shortName, I.isbnOrIssn ORDER BY A.shortName DESC SEPARATOR '<br />') aliases";
$groupBy = "GROUP BY R.resourceID";
}

Expand All @@ -1110,7 +1171,9 @@ public function searchQuery($whereAdd, $orderBy = '', $limit = '', $count = fals
LEFT JOIN ResourceAdministeringSiteLink RADSL ON R.resourceID = RADSL.resourceID
LEFT JOIN ResourcePayment RPAY ON R.resourceID = RPAY.resourceID
LEFT JOIN ResourceNote RN ON R.resourceID = RN.resourceID
LEFT JOIN ResourceStep RS ON R.resourceID = RS.resourceID");
LEFT JOIN ResourceStep RS ON R.resourceID = RS.resourceID
LEFT JOIN IsbnOrIssn I ON R.resourceID = I.resourceID
");

$additional_joins = array();

Expand Down Expand Up @@ -1145,7 +1208,6 @@ public function searchQuery($whereAdd, $orderBy = '', $limit = '', $count = fals
if ($limit) {
$query .= "\nLIMIT " . $limit;
}

return $query;
}

Expand Down Expand Up @@ -1259,11 +1321,11 @@ public function export($whereAdd, $orderBy){
$query = "SELECT R.resourceID, R.titleText, AT.shortName acquisitionType, CONCAT_WS(' ', CU.firstName, CU.lastName) createName,
R.createDate createDate, CONCAT_WS(' ', UU.firstName, UU.lastName) updateName,
R.updateDate updateDate, S.shortName status,
RT.shortName resourceType, RF.shortName resourceFormat, R.isbnOrISSN, R.orderNumber, R.systemNumber, R.resourceURL, R.resourceAltURL,
RT.shortName resourceType, RF.shortName resourceFormat, R.orderNumber, R.systemNumber, R.resourceURL, R.resourceAltURL,
R.currentStartDate, R.currentEndDate, R.subscriptionAlertEnabledInd, AUT.shortName authenticationType,
AM.shortName accessMethod, SL.shortName storageLocation, UL.shortName userLimit, R.authenticationUserName,
R.authenticationPassword, R.coverageText, CT.shortName catalogingType, CS.shortName catalogingStatus, R.recordSetIdentifier, R.bibSourceURL,
R.numberRecordsAvailable, R.numberRecordsLoaded, R.hasOclcHoldings,
R.numberRecordsAvailable, R.numberRecordsLoaded, R.hasOclcHoldings, I.isbnOrIssn,
" . $orgSelectAdd . ",
" . $licSelectAdd . "
GROUP_CONCAT(DISTINCT A.shortName ORDER BY A.shortName DESC SEPARATOR '; ') aliases,
Expand Down Expand Up @@ -1306,6 +1368,7 @@ public function export($whereAdd, $orderBy){
LEFT JOIN AccessMethod AM ON AM.accessMethodID = R.accessMethodID
LEFT JOIN StorageLocation SL ON SL.storageLocationID = R.storageLocationID
LEFT JOIN UserLimit UL ON UL.userLimitID = R.userLimitID
LEFT JOIN IsbnOrIssn I ON I.resourceID = R.resourceID
" . $licJoinAdd . "
" . $whereStatement . "
GROUP BY R.resourceID
Expand Down Expand Up @@ -1674,6 +1737,33 @@ public function hasCatalogingInformation() {



//removes this resource and its children
public function removeResourceAndChildren(){

// for each children
foreach ($this->getChildResources() as $instance) {
$removeChild = true;
$child = new Resource(new NamedArguments(array('primaryKey' => $instance->resourceID)));

// get parents of this children
$parents = $child->getParentResources();

// If the child ressource belongs to another parent than the one we're removing
foreach ($parents as $pinstance) {
$parentResourceObj = new Resource(new NamedArguments(array('primaryKey' => $pinstance->relatedResourceID)));
if ($parentResourceObj->resourceID != $this->resourceID) {
// We do not delete this child.
$removeChild = false;
}
}
if ($removeChild == true) {
$child->removeResource();
}
}
// Finally, we remove the parent
$this->removeResource();
}




Expand All @@ -1689,6 +1779,7 @@ public function removeResource(){
$this->removeResourceOrganizations();
$this->removeResourcePayments();
$this->removeAllSubjects();
$this->removeAllIsbnOrIssn();


$instance = new Contact();
Expand Down Expand Up @@ -2224,6 +2315,27 @@ public function removeAllSubjects(){

}

public function removeAllIsbnOrIssn() {
$query = "DELETE
FROM IsbnOrIssn
WHERE resourceID = '" . $this->resourceID . "'";

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

}

public function setIsbnOrIssn($isbnorissns) {
$this->removeAllIsbnOrIssn();
foreach ($isbnorissns as $isbnorissn) {
if (trim($isbnorissn) != '') {
$isbnOrIssn = new IsbnOrIssn();
$isbnOrIssn->resourceID = $this->resourceID;
$isbnOrIssn->isbnOrIssn = $isbnorissn;
$isbnOrIssn->save();
}
}
}

}

?>
11 changes: 10 additions & 1 deletion admin/classes/domain/ResourceRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,16 @@ protected function defineRelationships() {}

protected function overridePrimaryKeyName() {}

public function exists() {
$query = "SELECT COUNT(*) AS count FROM ResourceRelationship WHERE resourceID = " . $this->resourceID;
$query .= " AND relatedResourceID = " . $this->relatedResourceID;
$query .= " AND relationshipTypeID = " . $this->relationshipTypeID;

$result = $this->db->processQuery($query, 'assoc');
return $result['count'];
}


}

?>
?>
1 change: 1 addition & 0 deletions admin/configuration_sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ feedbackEmailAddress=""
testMode=N
testModeEmailAddress=""
defaultsort=""
importISBNDedupingColumns="ISSN,ISBN"

[database]
type = "mysql"
Expand Down
Loading

0 comments on commit c65b0ba

Please sign in to comment.