Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new routes to Coral API #292

Merged
merged 8 commits into from
Dec 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion licensing/admin/classes/common/DatabaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ protected function init(NamedArguments $arguments) {
protected function defineRelationships() {}
protected function overridePrimaryKeyName() {}

protected function asArray() {
$aarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$aarray[$attributeName] = $this->$attributeName;
}
}
return $aarray;
}

protected function defineAttributes() {
// Figure out attributes from existing database
Expand Down Expand Up @@ -298,4 +307,4 @@ public function load() {

}

?>
?>
14 changes: 13 additions & 1 deletion licensing/admin/classes/domain/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ protected function defineRelationships() {}

protected function overridePrimaryKeyName() {}

public function asArray() {
$aarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$aarray[$attributeName] = $this->$attributeName;
}
}
$documentType = new DocumentType(new NamedArguments(array("primaryKey" => $this->documentTypeID)));
$aarray['documentType'] = $documentType->shortName;
return $aarray;
}


//returns 1 or 0 indicating if this particular document has children agreements
public function getNumberOfChildren(){
Expand Down Expand Up @@ -248,4 +260,4 @@ public function getExpressionsForDisplay(){

}

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

protected function overridePrimaryKeyName() {}


public function asArray() {
$aarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$aarray[$attributeName] = $this->$attributeName;
}
}
$expressionType = new ExpressionType(new NamedArguments(array("primaryKey" => $this->expressionTypeID)));
$aarray['expressionType'] = $expressionType->shortName;
return $aarray;
}



Expand Down
13 changes: 12 additions & 1 deletion licensing/admin/classes/domain/ExpressionNote.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ protected function defineRelationships() {}

protected function overridePrimaryKeyName() {}

public function asArray() {
$aarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$aarray[$attributeName] = $this->$attributeName;
}
}
return $aarray;
// return parent::asArray();
}



//reorders expression note based on direction the user clicked
Expand Down Expand Up @@ -67,4 +78,4 @@ public function reorder($dir, $oldSeq){

}

?>
?>
28 changes: 27 additions & 1 deletion licensing/admin/classes/domain/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ protected function defineRelationships() {}

protected function overridePrimaryKeyName() {}

public function asArray() {
$larray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$larray[$attributeName] = $this->$attributeName;
}
}
$doccount = 0;
foreach ($this->getDocuments() as $document) {
$larray['documents'][$doccount]['content'] = $document->asArray();;
$exprcount = 0;
foreach ($document->getExpressions() as $expression) {
$expressionType = new ExpressionType(new NamedArguments(array('primaryKey' => $expression->expressionTypeID)));
if ($expressionType->noteType == "Display") {
$larray['documents'][$doccount]['expressions'][$exprcount]['content'] = $expression->asArray();
$notescount = 0;
foreach ($expression->getExpressionNotes() as $expressionNote) {
$larray['documents'][$doccount]['expressions'][$exprcount]['notes'][$notescount] = $expressionNote->asArray();;
$notescount++;
}
$exprcount++;
}
}
$doccount++;
}
return $larray;
}


//returns array of Document objects - used by forms to get dropdowns of available documents
Expand Down Expand Up @@ -51,7 +78,6 @@ public function getDocuments(){
array_push($objects, $object);
}
}

return $objects;
}

Expand Down
2 changes: 1 addition & 1 deletion management/admin/classes/domain/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@ public function getExpressionsForDisplay(){

}

?>
?>
17 changes: 17 additions & 0 deletions organizations/admin/classes/domain/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@ protected function defineRelationships() {}

protected function overridePrimaryKeyName() {}

public function asArray() {
$rarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$rarray[$attributeName] = $this->$attributeName;
}
}

$aliases = $this->getAliases();
$rarray['aliases'] = array();
foreach ($aliases as $alias) {
array_push($rarray['aliases'], $alias->name);
}

return $rarray;
}



//returns array of parent organization objects
Expand Down
18 changes: 18 additions & 0 deletions resources/admin/classes/common/DBService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ class DBService extends Object {
protected $db;
protected $config;
protected $error;
private static $_instance; //The single instance


/*
Get an instance of the Database
@return Instance
*/
public static function getInstance() {
if(!self::$_instance) { // If no instance then make one
self::$_instance = new self();
}
return self::$_instance;
}

protected function init(NamedArguments $arguments) {
parent::init($arguments);
Expand Down Expand Up @@ -53,6 +66,11 @@ protected function connect() {
$this->checkForError();
}

public function changeDb($name = null) {
$dbName = ($name == null) ? $this->config->database->name : $this->config->settings->$name;
$this->db->select_db($dbName);
}

protected function disconnect() {
//mysqli_close($this->db);
}
Expand Down
6 changes: 3 additions & 3 deletions resources/admin/classes/common/DatabaseObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ protected function init(NamedArguments $arguments) {
$this->primaryKeyName = $arguments->primaryKeyName;

$this->primaryKey = $arguments->primaryKey;
$this->db = new DBService;
$this->db = DBService::getInstance();;

$arguments->setDefaultValueForArgumentName('db',false);
$this->db = $arguments->db ? $arguments->db : new DBService;
$this->db = $arguments->db ? $arguments->db : DBService::getInstance();

$this->defineRelationships();
//$this->defineAttributes(); //now performed in load
Expand Down Expand Up @@ -309,4 +309,4 @@ public function load() {

}

?>
?>
10 changes: 9 additions & 1 deletion resources/admin/classes/domain/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ protected function defineRelationships() {}
protected function overridePrimaryKeyName() {}



public function asArray() {
$rarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$rarray[$attributeName] = $this->$attributeName;
}
}
return $rarray;
}

//returns number of children for this particular contact role
public function getNumberOfChildren(){
Expand Down
37 changes: 36 additions & 1 deletion resources/admin/classes/domain/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,43 @@ protected function defineIsbnOrIssn() {}

protected function overridePrimaryKeyName() {}

public function asArray() {
$rarray = array();
foreach (array_keys($this->attributeNames) as $attributeName) {
if ($this->$attributeName != null) {
$rarray[$attributeName] = $this->$attributeName;
}
}

$status = new Status(new NamedArguments(array('primaryKey' => $this->statusID)));
$rarray['status'] = $status->shortName;

if ($this->resourceTypeID) {
$resourceType = new ResourceType(new NamedArguments(array('primaryKey' => $this->resourceTypeID)));
$rarray['resourceType'] = $resourceType->shortName;
}

if ($this->resourceFormatID) {
$resourceFormat = new ResourceFormat(new NamedArguments(array('primaryKey' => $this->resourceFormatID)));
$rarray['resourceFormat'] = $resourceFormat->shortName;
}

if ($this->acquisitionTypeID) {
$acquisitionType = new AcquisitionType(new NamedArguments(array('primaryKey' => $this->acquisitionTypeID)));
$rarray['acquisitionType'] = $acquisitionType->shortName;
}


$identifiers = $this->getIsbnOrIssn();
$rarray['isbnOrIssn'] = array();
foreach ($identifiers as $identifier) {
array_push($rarray['isbnOrIssn'], $identifier->isbnOrIssn);
}
return $rarray;


}

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

Expand Down Expand Up @@ -141,7 +176,7 @@ private function getRelatedResources($key) {
$object = new ResourceRelationship(new NamedArguments(array('primaryKey' => $result['resourceRelationshipID'])));
array_push($objects, $object);
}else{
$db = new DBService;
$db = DBService::getInstance();
foreach ($result as $row) {
$object = new ResourceRelationship(new NamedArguments(array('primaryKey' => $row['resourceRelationshipID'],'db'=>$db)));
array_push($objects, $object);
Expand Down
87 changes: 63 additions & 24 deletions resources/api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@
require 'Flight/flight/Flight.php';

include_once '../directory.php';
include_once '../admin/classes/common/NamedArguments.php';
include_once '../admin/classes/common/Object.php';
include_once '../admin/classes/common/DynamicObject.php';
include_once '../admin/classes/common/Utility.php';
include_once '../admin/classes/common/Configuration.php';
include_once '../admin/classes/common/DBService.php';
include_once '../admin/classes/common/DatabaseObject.php';
include_once '../admin/classes/common/Email.php';
include_once '../admin/classes/domain/Resource.php';
include_once '../admin/classes/domain/ResourceType.php';
include_once '../admin/classes/domain/AcquisitionType.php';
include_once '../admin/classes/domain/ResourceFormat.php';
include_once '../admin/classes/domain/NoteType.php';
include_once '../admin/classes/domain/ResourceNote.php';
include_once '../admin/classes/domain/ResourcePayment.php';
include_once '../admin/classes/domain/AdministeringSite.php';
include_once '../admin/classes/domain/ResourceAdministeringSiteLink.php';
include_once '../admin/classes/domain/Status.php';
include_once '../admin/classes/domain/User.php';
include_once '../admin/classes/domain/Workflow.php';
include_once '../admin/classes/domain/Step.php';
include_once '../admin/classes/domain/ResourceStep.php';
include_once '../admin/classes/domain/UserGroup.php';
include_once '../admin/classes/domain/Fund.php';

if (!isAllowed()) {
header('HTTP/1.0 403 Forbidden');
Expand Down Expand Up @@ -283,6 +259,69 @@
Flight::json($as->shortName);
});

Flight::route('GET /resources/@id', function($id) {
$r = new Resource(new NamedArguments(array('primaryKey' => $id)));
Flight::json($r->asArray());

});

Flight::route('GET /resources/', function() {
$identifier = Flight::request()->query->identifier;
if ($identifier) {
$r = new Resource();
Flight::json(array_map(function($value) { return $value->asArray(); }, $r->getResourceByIsbnOrISSN($identifier)));
}
});

Flight::route('GET /resources/@id/titles', function($id) {
$r = new Resource(new NamedArguments(array('primaryKey' => $id)));
$childResourceArray = array();
$childResourceIDArray = array();
foreach ($r->getChildResources() as $instance) {
foreach (array_keys($instance->attributeNames) as $attributeName) {
$sanitizedInstance[$attributeName] = $instance->$attributeName;
}
$sanitizedInstance[$instance->primaryKeyName] = $instance->primaryKey;
array_push($childResourceIDArray, $sanitizedInstance);
}

foreach ($childResourceIDArray as $childResource){
$childResourceObj = new Resource(new NamedArguments(array('primaryKey' => $childResource['resourceID'])));
array_push($childResourceArray, $childResourceObj->asArray());
}
Flight::json($childResourceArray);
});

Flight::route('GET /resources/@id/licenses', function($id) {
$db = DBService::getInstance();
$r = new Resource(new NamedArguments(array('primaryKey' => $id)));
$licensesArray = array();
$rla = $r->getLicenseArray();
$db->changeDb('licensingDatabaseName');
foreach($rla as $license) {
$l = new License(new NamedArguments(array('primaryKey' => $license['licenseID'])));
array_push($licensesArray, $l->asArray());
}
$db->changeDb();
Flight::json($licensesArray);
});


Flight::route('GET /organizations/@id', function($id) {
$config = new Configuration();
$db = DBService::getInstance();
if ($config->settings->organizationsModule == 'Y') {
include_once '../../organizations/admin/classes/domain/Organization.php';
$db->changeDb('organizationsDatabaseName');
$organization = new Organization(new NamedArguments(array('primaryKey' => $id)));
Flight::json($organization->asArray());
$db->changeDb();
} else {
include_once '../admin/classes/domain/Organization.php';
$organization = new Organization(new NamedArguments(array('primaryKey' => $id)));
Flight::json($organization->asArray());
}
});

Flight::start();

Expand Down