Skip to content
Snippets Groups Projects
Commit f1bcb5c2 authored by Demian Katz's avatar Demian Katz
Browse files

More refactoring to simplify Syndetics logic.

parent a73182fe
No related merge requests found
......@@ -87,6 +87,23 @@ abstract class AbstractSyndetics extends AbstractHelper
return true;
}
/**
* Get the Syndetics URL for making a request.
*
* @param string $id Client ID
* @param string $file File to request
* @param string $type Type parameter
*
* @return string
*/
protected function getSyndeticsUrl($id, $file = 'index.xml', $type = 'rw12,h7')
{
$baseUrl = isset($this->config->Syndetics->url)
? $this->config->Syndetics->url : 'http://syndetics.com';
return $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10()
. '/' . $file . '&client=' . $id . '&type=' . $type;
}
/**
* Attempt to get an ISBN-10; revert to ISBN-13 only when ISBN-10 representation
* is impossible.
......@@ -96,10 +113,7 @@ abstract class AbstractSyndetics extends AbstractHelper
protected function getIsbn10()
{
$isbn = is_object($this->isbn) ? $this->isbn->get10() : false;
if (!$isbn) {
$isbn = $this->isbn->get13();
}
return $isbn;
return (!$isbn && is_object($this->isbn)) ? $this->isbn->get13() : $isbn;
}
/**
......
......@@ -82,15 +82,11 @@ class AuthorNotes extends AbstractSyndetics
)
);
//first request url
$baseUrl = isset($this->config->Syndetics->url) ?
$this->config->Syndetics->url : 'http://syndetics.com';
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() .
'/index.xml&client=' . $id . '&type=rw12,hw7';
// Initialize return value
$anotes = array();
//find out if there are any notes
// Find out if there are any notes
$url = $this->getSyndeticsUrl($id);
$result = $this->getHttpClient($url)->send();
if (!$result->isSuccess()) {
return $anotes;
......@@ -106,9 +102,7 @@ class AuthorNotes extends AbstractSyndetics
$nodes = $xmldoc->getElementsByTagName($source);
if ($nodes->length) {
// Load notes
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' .
$sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7';
$url = $this->getSyndeticsUrl($id, $sourceInfo['file']);
$result2 = $this->getHttpClient($url)->send();
if (!$result2->isSuccess()) {
continue;
......
......@@ -74,7 +74,7 @@ class Excerpt extends AbstractSyndetics
*/
protected function loadSyndetics($id, $s_plus=false)
{
//list of syndetic excerpts
// List of syndetic excerpts
$sourceList = array(
'DBCHAPTER' => array(
'title' => 'First Chapter or Excerpt',
......@@ -83,15 +83,11 @@ class Excerpt extends AbstractSyndetics
)
);
//first request url
$baseUrl = isset($this->config->Syndetics->url) ?
$this->config->Syndetics->url : 'http://syndetics.com';
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() .
'/index.xml&client=' . $id . '&type=rw12,hw7';
// Initialize return value:
$review = array();
//find out if there are any excerpts
// Find out if there are any excerpts
$url = $this->getSyndeticsUrl($id);
$result = $this->getHttpClient($url)->send();
if (!$result->isSuccess()) {
return $review;
......@@ -107,9 +103,7 @@ class Excerpt extends AbstractSyndetics
$nodes = $xmldoc->getElementsByTagName($source);
if ($nodes->length) {
// Load excerpts
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' .
$sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7';
$url = $this->getSyndeticsUrl($id, $sourceInfo['file']);
$result2 = $this->getHttpClient($url)->send();
if (!$result2->isSuccess()) {
continue;
......
......@@ -218,7 +218,7 @@ class Reviews extends AbstractSyndetics
*/
protected function loadSyndetics($id, $s_plus=false)
{
//list of syndetic reviews
// List of syndetic reviews
$sourceList = array(
'CHREVIEW' => array('title' => 'Choice Review',
'file' => 'CHREVIEW.XML',
......@@ -255,15 +255,11 @@ class Reviews extends AbstractSyndetics
'file' => 'CRITICASEREVIEW.XML')
);
//first request url
$baseUrl = isset($this->config->Syndetics->url) ?
$this->config->Syndetics->url : 'http://syndetics.com';
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' .
'index.xml&client=' . $id . '&type=rw12,hw7';
// Initialize return value
$review = array();
//find out if there are any reviews
// Find out if there are any reviews
$url = $this->getSyndeticsUrl($id);
$result = $this->getHttpClient($url)->send();
if (!$result->isSuccess()) {
return $review;
......@@ -279,8 +275,7 @@ class Reviews extends AbstractSyndetics
$nodes = $xmldoc->getElementsByTagName($source);
if ($nodes->length) {
// Load reviews
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' .
$sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7';
$url = $this->getSyndeticsUrl($id, $sourceInfo['file']);
$result2 = $this->getHttpClient($url)->send();
if (!$result2->isSuccess()) {
continue;
......
......@@ -82,15 +82,11 @@ class VideoClips extends AbstractSyndetics
)
);
//first request url
$baseUrl = isset($this->config->Syndetics->url) ?
$this->config->Syndetics->url : 'http://syndetics.com';
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() .
'/index.xml&client=' . $id . '&type=rw12,hw7';
// Initialize return value:
$vclips = array();
//find out if there are any clips
// Find out if there are any clips
$url = $this->getSyndeticsUrl($id);
$result = $this->getHttpClient($url)->send();
if (!$result->isSuccess()) {
return $vclips;
......@@ -106,9 +102,7 @@ class VideoClips extends AbstractSyndetics
$nodes = $xmldoc->getElementsByTagName($source);
if ($nodes->length) {
// Load clips
$url = $baseUrl . '/index.aspx?isbn=' . $this->getIsbn10() . '/' .
$sourceInfo['file'] . '&client=' . $id . '&type=rw12,hw7';
$url = $this->getSyndeticsUrl($id, $sourceInfo['file']);
$result2 = $this->getHttpClient($url)->send();
if (!$result2->isSuccess()) {
continue;
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment