示例#1
0
 /**
  * Constructor
  * 
  * @param Xerxes_Record $record		record
  * @param Config $config			local config
  */
 public function __construct(Record $record, Config $config)
 {
     $this->xerxes_record = $record;
     $this->registry = Registry::getInstance();
     $this->config = $config;
     // link resolver stuff
     $this->link_resolver = $this->config->getConfig("LINK_RESOLVER_ADDRESS", false, $this->registry->getConfig("LINK_RESOLVER_ADDRESS", false));
     $this->sid = $this->config->getConfig("APPLICATION_SID", false, $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes"));
     if ($this->link_resolver != null) {
         $this->url_open = $record->getOpenURL($this->link_resolver, $this->sid);
     }
     $this->openurl_kev_co = $record->getOpenURL(null, $this->sid);
     // holdings
     $this->holdings = new Holdings();
     if ($record->hasPhysicalHoldings() == false) {
         $this->holdings->checked = true;
     }
     // proxy links?
     $proxy_server = $this->registry->getConfig('PROXY_SERVER', false);
     $should_proxy_links = $this->config->getConfig('SHOULD_PROXY', false, false);
     if ($should_proxy_links) {
         foreach ($this->xerxes_record->getLinks() as $link) {
             $link->addProxyPrefix($proxy_server);
         }
     }
 }
示例#2
0
 public function __construct(Record $record, Config $config)
 {
     $xerxes_record = $record->xerxes_record;
     // old metalib record from xerxes 1
     if ($xerxes_record instanceof \Xerxes_MetalibRecord) {
         $xerxes_record = new Metalib\Record($xerxes_record);
         // convert it x2 record
     } elseif ($xerxes_record instanceof \Xerxes_TransRecord) {
         try {
             $xerxes_record = $xerxes_record->record();
             // extract the x2 record
         } catch (\Exception $e) {
             trigger_error('Xerxes Error (' . $e->getLine() . '): ' . $e->getMessage());
         }
     }
     // record has been corrupted  @todo fix this problem
     if (!$xerxes_record instanceof Xerxes\Record) {
         $this->corrupted = true;
         // mark it as such
         // make a new record with the data we have on hand in the other
         // saved_records fields
         $xerxes_record = new Xerxes\Record();
         $title = $record->title;
         if ($record->nonsort != "") {
             $title = $record->nonsort . ' ' . $title;
         }
         $author = new Author($record->author, null, Author::PERSONAL);
         $format = new \Xerxes\Record\Format();
         $format->setFormat($record->format);
         $properties = array('title' => $title, 'format' => $format, 'authors' => array($author), 'year' => $record->year);
         $xerxes_record->setProperties($properties);
     }
     parent::__construct($xerxes_record, $config);
 }
示例#3
0
文件: Record.php 项目: navtis/xerxes
 public function toXml()
 {
     $objXml = parent::toXml();
     //       echo($this->xmlpp($objXml->saveXML(), false));
     /*
             // Parser::addToXML($objXml, 'source', 'COPAC: ' . $this->source);
     */
     return $objXml;
 }
示例#4
0
文件: Result.php 项目: navtis/xerxes
 /**
  * Constructor
  * 
  * @param Xerxes_Record $record		record
  * @param Config $config			local config
  */
 public function __construct(Record $record, Config $config)
 {
     $this->xerxes_record = $record;
     $this->registry = Registry::getInstance();
     $this->config = $config;
     // link resolver stuff
     $this->link_resolver = $this->config->getConfig("LINK_RESOLVER_ADDRESS", false, $this->registry->getConfig("LINK_RESOLVER_ADDRESS", false));
     $this->sid = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes");
     if ($this->link_resolver != null) {
         $this->url_open = $record->getOpenURL($this->link_resolver, $this->sid);
     }
     $this->openurl_kev_co = $record->getOpenURL(null, $this->sid);
     // holdings
     $this->holdings = new Holdings();
     if ($record->hasPhysicalHoldings() == false) {
         $this->holdings->checked = true;
     }
 }
示例#5
0
文件: Engine.php 项目: navtis/xerxes
 public function getRecommendations(Xerxes\Record $xerxes_record, $min_relevance = 0, $max_records = 10)
 {
     $bx_records = array();
     // now get the open url
     $open_url = $xerxes_record->getOpenURL(null, $this->sid);
     $open_url = str_replace('genre=unknown', 'genre=article', $open_url);
     // send it to bx service
     $url = $this->url . "/recommender/openurl?token=" . $this->token . "&{$open_url}" . "&res_dat=source=global&threshold={$min_relevance}&maxRecords={$max_records}";
     try {
         $client = Factory::getHttpClient();
         $client->setUri($url);
         $client->setConfig(array('timeout' => 4));
         $xml = $client->send()->getBody();
         if ($xml == "") {
             throw new \Exception("No response from bx service");
         }
     } catch (\Exception $e) {
         // just issue the exception as a warning
         trigger_error("Could not get result from bX service: " . $e->getTraceAsString(), E_USER_WARNING);
         return $bx_records;
     }
     // header("Content-type: text/xml"); echo $xml; exit;
     $doc = new \DOMDocument();
     $doc->recover = true;
     $doc->loadXML($xml);
     $xpath = new \DOMXPath($doc);
     $xpath->registerNamespace("ctx", "info:ofi/fmt:xml:xsd:ctx");
     $records = $xpath->query("//ctx:context-object");
     foreach ($records as $record) {
         $bx_record = new Record();
         $bx_record->loadXML($record);
         array_push($bx_records, $bx_record);
     }
     if (count($bx_records) > 0) {
         // first one is the record we want to find recommendations for
         // so skip it; any others are actual recommendations
         array_shift($bx_records);
     }
     return $bx_records;
 }
示例#6
0
文件: Search.php 项目: navtis/xerxes
 /**
  * URL for the sms feature
  * 
  * @param Record $result
  * @return string url
  */
 public function linkSMS(Record $result)
 {
     $arrParams = array('controller' => $this->request->getParam('controller'), "action" => "sms", "id" => $result->getRecordID());
     return $this->request->url_for($arrParams);
 }
示例#7
0
 /**
  * Load data from MARC-XML
  */
 public function loadXML($xml)
 {
     $this->marc = new MarcRecord();
     $this->marc->loadXML($xml);
     parent::loadXML($xml);
 }
示例#8
0
 /** 
  * URL for the full record display, including targets 
  * 
  * @param $result Record object 
  * @return string url 
  */
 public function linkFullRecord(Record $result)
 {
     $arrParams = array('controller' => $this->request->getParam('controller'), "action" => "record", "id" => $result->getRecordID(), 'target' => $this->request->getParam('target', null, true));
     return $this->request->url_for($arrParams);
 }
 public function lookupAction()
 {
     $id = $this->request->getParam("id");
     // we essentially create a mock object and add holdings
     $xerxes_record = new Record();
     $xerxes_record->setRecordID($id);
     $xerxes_record->setSource($this->id);
     $result = new Result($xerxes_record, $this->config);
     $result->fetchHoldings();
     // add to response
     $this->data->setVariable('results', $result);
     // view template
     $this->data->setTemplate('search/lookup.xsl');
     return $this->data;
 }
示例#10
0
 public function loadXML($xml)
 {
     parent::loadXML($xml);
 }
示例#11
0
 /**
  * Add a record to the user's saved record space.
  *
  * @param string $username       username to save the record under
  * @param string $source         name of the source database
  * @param string $id             identifier for the record
  * @param Record $xerxes_record	 xerxes record object to save
  * @return int  inserted id
  */
 public function addRecord($username, $source, $id, Record $xerxes_record)
 {
     $arrValues = array();
     $iYear = (int) $xerxes_record->getYear();
     $strTitle = $xerxes_record->getMainTitle();
     $strSubTitle = $xerxes_record->getSubTitle();
     if ($strSubTitle != "") {
         $strTitle .= ": " . $strSubTitle;
     }
     $strSQL = "INSERT INTO xerxes_records \r\n\t\t\t( source, original_id, timestamp, username, nonsort, title, author, year, format, record_type, marc )\r\n\t\t\tVALUES \r\n\t\t\t( :source, :original_id, :timestamp, :username, :nonsort, :title, :author, :year, :format, :record_type, :marc)";
     $arrValues[":source"] = $source;
     $arrValues[":original_id"] = $id;
     $arrValues[":timestamp"] = date("Y-m-d H:i:s");
     $arrValues[":username"] = $username;
     $arrValues[":nonsort"] = $xerxes_record->getNonSort();
     $arrValues[":title"] = substr($strTitle, 0, 90);
     $arrValues[":author"] = $xerxes_record->getPrimaryAuthor(true);
     $arrValues[":year"] = $iYear;
     $arrValues[":format"] = $xerxes_record->format()->getReadableNormalizedFormat();
     $arrValues[":marc"] = serialize($xerxes_record);
     $arrValues[":record_type"] = "xerxes_record";
     return $this->insert($strSQL, $arrValues, true);
 }
示例#12
0
 /**
  * URL for the sms feature
  * 
  * @param Record $record
  * @return string url
  */
 public function linkSMS(Record $record)
 {
     $arrParams = array('controller' => $this->request->getParam('controller'), 'action' => 'sms', 'id' => $record->getRecordID());
     return $this->request->url_for($arrParams);
 }
示例#13
0
 /**
  * Return an individual record
  * 
  * @param string	record identifier
  * @return ResultSet
  */
 protected function doGetRecord($id)
 {
     $results = new Search\ResultSet($this->config);
     // get the record from the database
     $record = $this->datamap->getRecordByID($id);
     // no record found?
     if ($record == null) {
         $results->total = 0;
         return $results;
     }
     // got one
     $results->total = 1;
     $result = $this->createSearchResult($record);
     // corrupted record, look out
     if ($result->corrupted == true) {
         $fixed = false;
         $data = $record->marc;
         // go back to the original search engine and fetch it again
         $class_name = 'Application\\Model\\' . ucfirst($result->source) . '\\Engine';
         if (class_exists($class_name)) {
             try {
                 $engine = new $class_name();
                 $new_results = $engine->getRecord($result->original_id);
                 if ($new_results->total > 0) {
                     $result = $new_results->getRecord(0);
                     $fixed = true;
                 }
             } catch (NotFoundException $e) {
                 if (strstr($data, 'Xerxes_TransRecord')) {
                     $data = '<?xml version="1.0"?>' . Parser::removeLeft($data, '<?xml version="1.0"?>');
                     $data = Parser::removeRight($data, '</xerxes_record>') . '</xerxes_record>';
                     $xerxes_record = new Xerxes\Record();
                     $xerxes_record->loadXML($data);
                     $record->xerxes_record = $xerxes_record;
                     // recreate the result, since we need the openurl and such
                     $result = $this->createSearchResult($record);
                     $fixed = true;
                 }
             }
         } elseif (strstr($data, 'Xerxes_MetalibRecord')) {
             $data = '<?xml' . Parser::removeLeft($data, '<?xml');
             $data = Parser::removeRight($data, '</x_server_response>') . '</x_server_response>';
             $xerxes_record = new \Xerxes_MetalibRecord();
             $xerxes_record->loadXML($data);
             $record->xerxes_record = $xerxes_record;
             // recreate the result, since we need the openurl and such
             $result = $this->createSearchResult($record);
             $fixed = true;
         }
         if ($fixed == false) {
             throw new \Exception('Sorry, this record has been corrupted');
         }
     }
     // if a catalog record, fetch holdings
     if ($record->xerxes_record instanceof Solr\Record) {
         try {
             $engine = new Solr\Engine();
             $solr_results = $engine->getRecord($result->original_id);
             $holdings = $solr_results->getRecord(0)->getHoldings();
             $result->setHoldings($holdings);
         } catch (\Exception $e) {
             trigger_error('saved records holdings lookup: ' . $e->getMessage(), E_USER_WARNING);
         }
     }
     $results->addResult($result);
     return $results;
 }
 /**
  * Load data from MARC record
  * 
  * @param MarcRecord $marc
  */
 public function loadMarc(MarcRecord $marc)
 {
     $this->marc = $marc;
     parent::loadXML($marc->getMarcXML());
 }
示例#15
0
 /**
  * URL for the full record display
  * Accounts for worldcat 'source' identifier
  *
  * @param $result Record object
  * @return string
  */
 public function linkFullRecord(Record $result)
 {
     $arrParams = array('controller' => $this->request->getParam('controller'), 'action' => 'record', 'source' => $this->request->getParam('source'), 'id' => $result->getRecordID());
     return $this->request->url_for($arrParams);
 }
示例#16
0
 /**
  * Include original record in object
  */
 public function includeOriginalRecord()
 {
     $this->original_record = $this->xerxes_record->getOriginalXML();
 }
示例#17
0
文件: Record.php 项目: navtis/xerxes
 public function __wakeup()
 {
     parent::__construct();
     $this->load($this->serialized);
 }
示例#18
0
 public function getOriginalXML($bolString = false)
 {
     // convert original (JSON-based) array to xml
     $this->document = Parser::convertToDOMDocument('<original />');
     Parser::addToXML($this->document, 'record', $this->original_array);
     return parent::getOriginalXML($bolString);
 }
示例#19
0
 public function toXml()
 {
     $objXml = parent::toXml();
     //       echo($this->xmlpp($objXml->saveXML(), false));
     return $objXml;
 }
示例#20
0
 /**
  * URL for the full record display, taken from the record
  * 
  * @param Record $record
  * @return string url
  */
 public function linkFullRecord(Record $record)
 {
     $links = $record->getLinks();
     $link = $links[0];
     return $link->getUrl();
 }
示例#21
0
 public function lookupAction()
 {
     $id = $this->request->getParam("id");
     // we essentially create a mock object and add holdings
     $xerxes_record = new Record();
     $xerxes_record->setRecordID($id);
     $xerxes_record->setSource($this->id);
     $result = new Result($xerxes_record, $this->config);
     $result->fetchHoldings();
     // add to response
     $this->data["results"] = $result;
     return $this->data;
 }
示例#22
0
 /**
  * Create Record from OpenURL Context Object
  */
 public function __construct()
 {
     parent::__construct();
     $this->utility[] = "xpath";
 }
示例#23
0
 /**
  * Add a record to the user's saved record space. $objXerxesRecord will be
  * updated with internal db id and original id.. 
  *
  * @param string $username					username to save the record under
  * @param string $source					name of the source database
  * @param string $id						identifier for the record
  * @param Xerxes_Record $objXerxesRecord	xerxes record object to save
  * @return int  inserted id
  */
 public function addRecord($username, $source, $id, Record $objXerxesRecord)
 {
     $arrValues = array();
     $iYear = (int) $objXerxesRecord->getYear();
     $strTitle = $objXerxesRecord->getMainTitle();
     $strSubTitle = $objXerxesRecord->getSubTitle();
     if ($strSubTitle != "") {
         $strTitle .= ": " . $strSubTitle;
     }
     $strSQL = "INSERT INTO xerxes_records \r\n\t\t\t( source, original_id, timestamp, username, nonsort, title, author, year, format, record_type, marc )\r\n\t\t\tVALUES \r\n\t\t\t( :source, :original_id, :timestamp, :username, :nonsort, :title, :author, :year, :format, :record_type, :marc)";
     $arrValues[":source"] = $source;
     $arrValues[":original_id"] = $id;
     $arrValues[":timestamp"] = date("Y-m-d H:i:s");
     $arrValues[":username"] = $username;
     $arrValues[":nonsort"] = $objXerxesRecord->getNonSort();
     $arrValues[":title"] = substr($strTitle, 0, 90);
     $arrValues[":author"] = $objXerxesRecord->getPrimaryAuthor(true);
     $arrValues[":year"] = $iYear;
     $arrValues[":format"] = $objXerxesRecord->format()->getInternalFormat();
     ##### xerxes 1 transition hack  @todo remove this
     if ($objXerxesRecord instanceof Summon\Record && $this->registry->getConfig('XERXES_1_TRANS', false)) {
         $link_resolver = $this->registry->getConfig("LINK_RESOLVER_ADDRESS", true);
         $sid = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes");
         $objXerxesRecord = new \Xerxes_TransRecord($objXerxesRecord, $link_resolver, $sid);
     }
     ###### end hack
     $arrValues[":marc"] = serialize($objXerxesRecord);
     $arrValues[":record_type"] = "xerxes_record";
     $this->insert($strSQL, $arrValues);
     // get the internal xerxes record id for the saved record, and fill record
     // with it, so caller can use.
     $getIDSql = "SELECT id FROM xerxes_records WHERE original_id = :original_id";
     $getIDParam = array(":original_id" => $id);
     $getIDResults = $this->select($getIDSql, $getIDParam);
     $objXerxesRecord->id = $getIDResults[0]["id"];
     $objXerxesRecord->original_id = $id;
     return $objXerxesRecord->id;
 }