/** * 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; } } }
/** * 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; } }