/**
  * 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;
         }
     }
 }
Beispiel #2
0
 /**
  * Fetch all subjects relative to a target specified
  * by its pazpar2 key (from the pazpar2 configuration files 
  *
  * @param string $pz2_key   Identifier for a pazpar2 z39.50 target
  * @returns array of Subjects
  */
 public function getSubjectsByTarget($pz2_key)
 {
     $arrSubjects = array();
     $command = "/institutions/{$pz2_key}/subjects.json";
     $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);
     foreach ($api_subjects as $sub) {
         $subject = new Subject();
         $subject->load(array('name' => $sub['subject'], 'id' => $sub['subject_id'], 'position' => $sub['subject'], 'url' => $sub['ukat_url']));
         $subjArray[] = $subject;
     }
     usort($subjArray, array($this, 'alphasort'));
     return $subjArray;
 }