예제 #1
0
 /**
  * Constructor
  * 
  */
 public function __construct($type, $targets)
 {
     // full set of Targets from configuration file
     $this->config = Config::getInstance();
     $config = $this->config->getConfig("targets");
     if ($config != null) {
         $tgtArray = array();
         foreach ($config->target as $target_data) {
             if ($type == null || (string) $target_data->attributes()->type == $type) {
                 $data = array();
                 // convert from SimpleXmlElement to array
                 foreach ($target_data->attributes() as $a => $b) {
                     $data[$a] = (string) $b;
                 }
                 $target = new Target();
                 $target->load($data);
                 $tgtArray[] = $target;
             }
         }
         usort($tgtArray, function ($a, $b) {
             return strcmp($a->title_short, $b->title_short);
         });
         for ($i = 0; $i < count($tgtArray); $i++) {
             $tgt = $tgtArray[$i];
             $tgt->position = $i + 1;
             $this->targets[$tgt->pz2_key] = $tgt;
         }
     }
 }
예제 #2
0
 /**
  * Constructor
  * 
  */
 public function __construct($pz2_key)
 {
     // full set of Libraries for this institution from configuration file
     $this->config = Config::getInstance();
     $xml = $this->config->getXml();
     $query = "//config[@name='targets']/target[@pz2_key='{$pz2_key}']/library";
     $libraries = $xml->xpath($query);
     $lib_arr = array();
     foreach ($libraries as $config_library) {
         $arr = array();
         $description = (string) $config_library;
         $arr['description'] = $description;
         foreach ($config_library->attributes() as $k => $v) {
             $arr[$k] = (string) $v;
         }
         $library = new Library();
         $arr['pz2_key'] = $pz2_key;
         $library->load($arr);
         $lib_arr[] = $library;
     }
     usort($lib_arr, function ($a, $b) {
         return strcmp($a->name, $b->name);
     });
     $this->libraries = $lib_arr;
 }
예제 #3
0
 public function __construct($command)
 {
     $config = Config::getInstance();
     $this->apiurl = $config->getConfig("apiurl");
     $this->client = Factory::getHttpClient();
     $this->client->setUri($this->apiurl . $command);
     $api_data = $this->client->send()->getBody();
     $api_data = json_decode($api_data, true);
     $api_data = array_pop($api_data);
     $i = 1;
     foreach ($api_data as $k => $v) {
         $api_data[$k]['position'] = $i++;
     }
     $this->api_data = $api_data;
 }
예제 #4
0
 /**
  * Constructor
  * 
  */
 public function __construct($type, $targets)
 {
     // full set of Targets from Search25 API
     $this->config = Config::getInstance();
     $url = $this->config->getConfig("apiurl");
     $command = '/institutions.json?active=true';
     $this->client = Factory::getHttpClient();
     $this->client->setUri($url . $command);
     $api_institutions = $this->client->send()->getBody();
     if ($type == null) {
         $command = "/z3950server.json?active=true";
     } else {
         $command = "/z3950server.json?active=true&source_type={$type}";
     }
     $this->client->setUri($url . $command);
     $api_targets = $this->client->send()->getBody();
     $api_institutions = json_decode($api_institutions, true);
     $api_institutions = array_pop($api_institutions);
     $api_targets = json_decode($api_targets, true);
     $api_targets = array_pop($api_targets);
     $tgtArray = array();
     foreach ($api_targets as $api_target) {
         $data = array();
         $key = $api_target['m25_code'];
         $data['pz2_key'] = $key;
         $data['z3950_location'] = $api_target['z39_name'];
         $data['linkback_url'] = $api_target['linkback_url'];
         $i = 0;
         while ($api_institutions[$i]['m25_code'] != $key) {
             $i++;
         }
         $data['short_name'] = $api_institutions[$i]['short_name'];
         $data['display_name'] = htmlentities($api_institutions[$i]['full_name']);
         $data['sort_name'] = htmlentities($api_institutions[$i]['sort_name']);
         $data['library_url'] = $api_institutions[$i]['library_url'];
         $data['domain'] = $api_institutions[$i]['domain'];
         $target = new Target();
         $target->load($data);
         $tgtArray[] = $target;
     }
     usort($tgtArray, array($this, 'alphasort'));
     for ($i = 0; $i < count($tgtArray); $i++) {
         $tgt = $tgtArray[$i];
         $tgt->position = $i + 1;
         $this->targets[$tgt->pz2_key] = $tgt;
     }
 }
예제 #5
0
 /**
  * Create UserOptions object saving Request with session data
  * @param Request $request
  */
 public function __construct(Request $request)
 {
     $this->container = $request->getContainer('pazpar2options');
     if ($request->getParam('sourcetype') != '') {
         $this->setSessionData('source_type', $request->getParam('sourcetype'));
         // if changing sourcetype, clear all old target selections
         $this->unsetSessionData('selectedby');
     } else {
         if (!$this->existsInSessionData('source_type')) {
             $config = Config::getInstance();
             $this->setSessionData('source_type', $config->getDefaultSourceType());
         }
     }
     // if this is a submit, change the session values as required
     if ($request->getParam('changetargets') != '') {
         $selectedby = $request->getParam('selectedby');
         if ($selectedby == 'names') {
             $targets = $request->getParam('target', null, true);
             $this->setSessionData('names', $targets);
             $this->setSessionData('selectedby', $selectedby);
         } else {
             if ($selectedby == 'subjects') {
                 $subjects = $request->getParam('subject', null, true);
                 $this->setSessionData('subjects', $subjects);
                 $this->setSessionData('selectedby', $selectedby);
             } else {
                 if ($selectedby == 'entitlements') {
                     $entitlements = $request->getParam('entitlement', null, true);
                     $this->setSessionData('entitlements', $entitlements);
                     $this->setSessionData('selectedby', $selectedby);
                 }
             }
         }
     }
     // retrieve the session values
     // set the actual targets to use
     if ($this->existsInSessionData('selectedby')) {
         $key = $this->getSessionData('selectedby');
     } else {
         $this->setSessionData('selectedby', 'names');
         $this->setSessionData('names', array('all'));
         $key = 'names';
     }
     $this->calculateTargets($key, $this->getSessionData($key), $this->getSessionData('source_type'));
 }
예제 #6
0
 public function __construct($results, $targets = null)
 {
     //var_dump($results);
     //Debug::dump($targets);
     $this->config = Config::getInstance();
     $this->start = $results['start'];
     $this->num = sizeof($results["hits"]);
     // should be = num
     $this->total = $results['merged'];
     $final = array();
     foreach ($results["hits"] as $record) {
         //Debug::dump($record);
         // merge the human-readable location name with the pz2 record
         $doc = new \DOMDocument();
         $doc->loadXML($record);
         $root = $doc->documentElement;
         $locs = $root->getElementsByTagName('location');
         $toDrop = array();
         foreach ($locs as $loc) {
             $name = $loc->getAttribute('name');
             $name = strtoupper($name);
             if (isset($targets[$name])) {
                 // insert displayed target title in record
                 $node = $doc->createElement('location_title', $targets[$name]->title_short);
                 $loc->appendChild($node);
                 // and the linkback url
                 $node = $doc->createElement('linkback_url', $targets[$name]->linkback_url);
                 $loc->appendChild($node);
             } else {
                 // drop records not from this target list
                 $toDrop[] = $loc;
             }
         }
         foreach ($toDrop as $loc) {
             // can't drop directly in original foreach or breaks loop
             $loc->parentNode->removeChild($loc);
         }
         $record = $doc->saveXML();
         $xerxes_record = new Record();
         $xerxes_record->loadXML($record);
         $this->addRecord($xerxes_record);
     }
 }
예제 #7
0
 public function __construct($results, $targets = null)
 {
     $this->config = Config::getInstance();
     $this->start = $results['start'];
     $this->num = sizeof($results["hits"]);
     // should be = num
     $this->total = $results['merged'];
     $final = array();
     foreach ($results["hits"] as $record) {
         // merge the human-readable location name with the pz2 record
         $doc = new \DOMDocument();
         $doc->loadXML($record);
         $root = $doc->documentElement;
         $locs = $root->getElementsByTagName('location');
         $toDrop = array();
         foreach ($locs as $loc) {
             $name = $loc->getAttribute('name');
             if ($t = $targets->getIndividualTargets($name)) {
                 // insert displayed target title in record
                 $node = $doc->createElement('location_title', $t->title_short);
                 $loc->appendChild($node);
                 // and the linkback url
                 $node = $doc->createElement('linkback_url', $t->linkback_url);
                 $loc->appendChild($node);
             } else {
                 // drop records not from this target list
                 // This is not needed for most targets, but some are already
                 // from union catalogues and include multiple targets, which
                 // may not be part of the set searched here (eg copac.org.uk)
                 $toDrop[] = $loc;
             }
         }
         foreach ($toDrop as $loc) {
             // can't drop directly in original foreach or breaks loop
             $loc->parentNode->removeChild($loc);
         }
         $record = $doc->saveXML();
         $xerxes_record = new Record();
         $xerxes_record->loadXML($record);
         $this->addRecord($xerxes_record);
     }
 }
예제 #8
0
 /**
  * Constructor
  * 
  */
 public function __construct($pz2_key)
 {
     // full set of Libraries for this institution from Search25 API
     $this->config = Config::getInstance();
     $url = $this->config->getConfig("apiurl");
     $command = "/institutions/{$pz2_key}/libraries.json?active=true";
     $this->client = Factory::getHttpClient();
     $this->client->setUri($url . $command);
     $api_libraries = $this->client->send()->getBody();
     $api_libraries = json_decode($api_libraries, true);
     $api_libraries = array_pop($api_libraries);
     $arr = array();
     foreach ($api_libraries as $api_library) {
         $library = new Library();
         $api_library['pz2_key'] = $pz2_key;
         $library->load($api_library);
         $arr[] = $library;
     }
     usort($arr, array($this, 'alphasort'));
     $this->libraries = $arr;
 }
예제 #9
0
 /**
  * Constructor
  * 
  */
 public function __construct()
 {
     // full set of Subjects from configuration file
     $this->config = Config::getInstance();
     $config = $this->config->getConfig("targets");
     if ($config != null) {
         $subj_assoc = array();
         $subj_urls = array();
         $key = 'pz2_key';
         foreach ($config->target as $target_data) {
             $t = (string) $target_data->attributes()->{$key};
             if (!array_key_exists($t, $this->targets_to_subjects)) {
                 $this->targets_to_subjects[$t] = array();
             }
             // now pick up all the subjects for this target
             $subjects = $target_data->children();
             $id = 'id';
             foreach ($subjects as $s) {
                 if ($s->getName() == 'subject') {
                     $subj = (string) $s;
                     $subj_id = (string) $s->attributes()->{$id};
                     $subj_url = (string) $s->attributes()->url;
                     $subj_urls[$subj] = $subj_url;
                     $subj_assoc[$subj] = $subj_id;
                     if (!array_key_exists($subj_id, $this->subjects_to_targets)) {
                         $this->subjects_to_targets[$subj_id] = array();
                     }
                     $this->targets_to_subjects[$t][] = $subj_id;
                     $this->subjects_to_targets[$subj_id][] = $t;
                 }
             }
         }
         $this->subjectnames = array_keys($subj_assoc);
         foreach ($this->subjectnames as $sn) {
             $subject = new Subject();
             $subject->load(array('name' => $sn, 'id' => $subj_assoc[$sn], 'position' => $subj_assoc[$sn], 'url' => $subj_urls[$sn]));
             $this->subjects[] = $subject;
         }
     }
 }
예제 #10
0
 /**
  * Constructor
  * 
  */
 public function __construct()
 {
     // full set of Subjects from API
     $this->config = Config::getInstance();
     $this->url = $this->config->getConfig("apiurl");
     $command = '/subjects.json?active=true';
     $this->client = Factory::getHttpClient();
     $this->client->setUri($this->url . $command);
     $api_subjects = $this->client->send()->getBody();
     $api_subjects = json_decode($api_subjects, true);
     $api_subjects = array_pop($api_subjects);
     $subjArray = array();
     foreach ($api_subjects as $sub) {
         $subject = new Subject();
         $subject->load(array('name' => $sub['subject'], 'id' => $sub['subject_id'], 'position' => $sub['subject_id'], 'url' => $sub['ukat_url']));
         $subjArray[] = $subject;
     }
     usort($subjArray, array($this, 'alphasort'));
     for ($i = 0; $i < count($subjArray); $i++) {
         $subj = $subjArray[$i];
         $subj->setPosition($i);
         $this->subjects[] = $subj;
     }
 }
예제 #11
0
 /**
  * Lazy loader for Config
  */
 public function conf()
 {
     if (!$this->config instanceof Config) {
         $this->config = Config::getInstance();
     }
     return $this->config;
 }
예제 #12
0
 public function __construct()
 {
     $config = Config::getInstance();
 }
예제 #13
0
 public function __construct()
 {
     $config = Config::getInstance();
     $this->apiurl = $config->getConfig("apiurl");
     $this->client = Factory::getHttpClient();
 }