Exemplo n.º 1
0
 public function doExecute()
 {
     $this->add_export_options();
     // get request paramaters
     $strUsername = $this->request->getSession("username");
     $strOrder = $this->request->getProperty("sortKeys");
     $iStart = $this->request->getProperty("startRecord");
     $strReturn = $this->request->getProperty("return");
     $strLabel = $this->request->getProperty("label");
     $strType = $this->request->getProperty("type");
     $strView = $this->request->getProperty("view");
     // id numbers can come in the form of multiple 'record' params or a single
     // 'records' param, with the ids comma separated
     $arrID = $this->request->getProperty("record", true);
     $strIDs = $this->request->getProperty("records");
     if ($strIDs != null) {
         $arrID = explode(",", $strIDs);
     }
     // these are typically set in actions.xml
     $strLimit = $this->request->getProperty("limit");
     $strLoginOverride = $this->request->getProperty("doNotEnforceLogin");
     // configuration settings
     // default records per page is either set explicitly in saved_record_per_page in config
     // or is the main (metasearch) defaul_records_per_page or 20 which is the const
     $defaultMax = $this->registry->getConfig("DEFAULT_RECORDS_PER_PAGE", false, self::DEFAULT_RECORDS_PER_PAGE);
     $iCount = $this->registry->getConfig("SAVED_RECORDS_PER_PAGE", false, $defaultMax);
     $iCountExport = $this->registry->getConfig("MAXIMUM_RECORD_EXPORT_LIMIT", false, 1000);
     $configMarcBrief = $this->registry->getConfig("XERXES_BRIEF_INCLUDE_MARC", false, false);
     $configMarcFull = $this->registry->getConfig("XERXES_FULL_INCLUDE_MARC", false, false);
     // brief records and export actions should be set to export limit
     if ($strLimit == null) {
         $iCount = $iCountExport;
     }
     // save the return url back to metasearch page if specified
     if ($strReturn != "") {
         $this->request->setSession("SAVED_RETURN", $strReturn);
     }
     ### access control
     // can only override login if username is *NOT* supplied in the paramaters,
     // this prevents people from manually attempting this; 'doNotEnforceLogin'
     // must then only be used in conjunction with specific id numbers
     if ($this->request->getProperty("username") != null && $strLoginOverride != null) {
         throw new Exception("access denied");
     }
     // ensure this is the same user, unless 'doNotEnforceLogin' overrides this,
     // such as with RefWorks or other third-party export
     if ($strLoginOverride == null) {
         $strRedirect = $this->enforceUsername();
         if ($strRedirect != null) {
             $this->request->setRedirect($strRedirect);
             return 1;
         }
     }
     ### records
     // get the total number of records
     $iTotal = $this->getTotal($strUsername, $strLabel, $strType);
     // fetch result(s) from the database
     $objData = new Xerxes_DataMap();
     $arrResults = array();
     if ($arrID != "") {
         $arrResults = $objData->getRecordsByID($arrID);
     } elseif ($strLabel != "") {
         $arrResults = $objData->getRecordsByLabel($strUsername, $strLabel, $strOrder, $iStart, $iCount);
     } elseif ($strType != "") {
         $arrResults = $objData->getRecordsByFormat($strUsername, $strType, $strOrder, $iStart, $iCount);
     } else {
         $arrResults = $objData->getRecords($strUsername, $strView, $strOrder, $iStart, $iCount);
     }
     // create master results xml doc
     $objXml = new DOMDocument();
     $objXml->recover = true;
     $objXml->loadXML("<results />");
     if (count($arrResults) > 0) {
         $objRecords = $objXml->createElement("records");
         $objXml->documentElement->appendChild($objRecords);
         // @todo move this to point of save for search arch
         /* 
         enhance records with links generated from metalib templates,
         and get a list of databases too. We need to get the Xerxes_Records 
         out of our list of Xerxes_Data_Records first.
         */
         $xerxes_records = array();
         $database_links_dom = "";
         foreach ($arrResults as $objDataRecord) {
             if ($objDataRecord->xerxes_record instanceof Xerxes_MetalibRecord) {
                 array_push($xerxes_records, $objDataRecord->xerxes_record);
             }
         }
         if (count($xerxes_records) > 0) {
             Xerxes_MetalibRecord::completeUrlTemplates($xerxes_records, $this->request, $this->registry, $database_links_dom);
             $database_links = $objXml->importNode($database_links_dom->documentElement, true);
             $objXml->documentElement->appendChild($database_links);
         }
         /*  Add the records */
         foreach ($arrResults as $objDataRecord) {
             // create a new record
             $objRecord = $objXml->createElement("record");
             $objRecords->appendChild($objRecord);
             // full record url
             $arrParams = array("base" => "folder", "action" => "full", "username" => $strUsername, "record" => $objDataRecord->id);
             $url = $this->request->url_for($arrParams);
             $objUrlFull = $objXml->createElement("url_full", $url);
             $objRecord->appendChild($objUrlFull);
             // delete url
             $arrParams = array("base" => "folder", "action" => "delete", "username" => $strUsername, "source" => $objDataRecord->source, "id" => $objDataRecord->original_id, "type" => $strType, "label" => $strLabel, "startRecord" => $iStart, "total" => $iTotal, "sortKeys" => $strOrder, "recordsPerPage" => $iCount);
             $url = $this->request->url_for($arrParams);
             $objUrlDelete = $objXml->createElement("url_delete", $url);
             $objRecord->appendChild($objUrlDelete);
             // openurl link
             $arrParams = array("base" => "folder", "action" => "redirect", "type" => "openurl", "id" => $objDataRecord->id);
             $configLinkResolver = $this->registry->getConfig("LINK_RESOLVER_ADDRESS", true);
             $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes");
             foreach ($objDataRecord->properties() as $key => $value) {
                 if ($key == "username" && $strLoginOverride != null) {
                     // exclude the username if login overridden, for privacy
                 } elseif ($key == "xerxes_record" && $value != null) {
                     // import the xerxes record
                     $objXerxesRecord = $value;
                     $objBibRecord = new DOMDocument();
                     $objBibRecord = $objXerxesRecord->toXML();
                     // import it
                     $objImportNode = $objXml->importNode($objBibRecord->documentElement, true);
                     $objRecord->appendChild($objImportNode);
                     // and openurl kev context object from record
                     $kev = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL(null, $configSID));
                     $objOpenUrl = $objXml->createElement("openurl_kev_co", $kev);
                     $objRecord->appendChild($objOpenUrl);
                     // full open url
                     $url = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL($configLinkResolver, $configSID));
                     $objUrlOpen = $objXml->createElement("url_open", $url);
                     $objRecord->appendChild($objUrlOpen);
                     // import the marc record, but only if configured to do so; since both brief
                     // and full record display come in on the same command, we'll use the record count
                     // here as an approximate for the brief versus full view -- hacky, hacky
                     $iNumRecords = count($arrID);
                     if ($strView != "brief" && $configMarcFull == true && $iNumRecords == 1 || $strView != "brief" && $configMarcBrief == true && $iNumRecords != 1) {
                         $objOriginalXml = $objXerxesRecord->getOriginalXML();
                         $objImportNode = $objXml->importNode($objOriginalXml->documentElement, true);
                         $objRecord->appendChild($objImportNode);
                     }
                 } else {
                     $objElement = $objXml->createElement($key, Xerxes_Framework_Parser::escapeXml($value));
                     $objRecord->appendChild($objElement);
                 }
             }
             $arrMulti = array("tags");
             foreach ($arrMulti as $multi) {
                 foreach ($objDataRecord->{$multi} as $value) {
                     // remove the trailing 's'
                     $single = substr($multi, 0, strlen($multi) - 1);
                     if ($value != null) {
                         $objElement = $objXml->createElement($single, Xerxes_Framework_Parser::escapeXml($value));
                         $objRecord->appendChild($objElement);
                     }
                 }
             }
         }
     }
     $this->request->addDocument($objXml);
     return 1;
 }
Exemplo n.º 2
0
 /**
  * Converts records from marc to xerxes_record and adds them to the master xml response
  * Also adds info on whether the record has already been saved this session. 
  *
  * @param DOMDOcument $objXml		master xml document
  * @param array $arrRecords			an array of marc records
  * @param bool $configMarcResults	whether to append the original marc records to the response
  * @return DOMDOcument				master xml response updated with record data
  */
 protected function addRecords($objXml, $arrRecords, $configMarcResults)
 {
     $objRecords = $objXml->createElement("records");
     $arrXerxesRecords = array();
     foreach ($arrRecords as $objRecord) {
         $objXerxesRecord = new Xerxes_MetalibRecord();
         $objXerxesRecord->loadXml($objRecord);
         array_push($arrXerxesRecords, $objXerxesRecord);
     }
     // enhance with links computed from metalib templates.
     Xerxes_MetalibRecord::completeUrlTemplates($arrXerxesRecords, $this->request, $this->registry);
     $position = $this->request->getProperty("startRecord");
     if ($position == "") {
         $position = 1;
     }
     foreach ($arrXerxesRecords as $objXerxesRecord) {
         $objRecordContainer = $objXml->createElement("record");
         $objRecords->appendChild($objRecordContainer);
         // basis for most of the links below
         $arrParams = array("base" => "metasearch", "group" => $this->request->getProperty("group"), "resultSet" => $objXerxesRecord->getResultSet(), "startRecord" => $objXerxesRecord->getRecordNumber());
         // full-text link
         $arrFullText = $arrParams;
         $arrFullText["action"] = "record";
         if ($this->request->getProperty("facet") != "") {
             // append this so the full record page knows how to get back
             $arrFullText["return"] = Xerxes_Framework_Parser::escapeXml($this->request->getServer("REQUEST_URI"));
         } else {
             // this is a regular (non-facet) result
             // we keep current resultset and position (rather than original resultset
             // and recordNumber) for the benefit of the merged set where these are different
             $arrFullText["resultSet"] = $this->request->getProperty("resultSet");
             $arrFullText["startRecord"] = $position;
         }
         $url = $this->request->url_for($arrFullText);
         $objUrlFull = $objXml->createElement("url_full", $url);
         $objRecordContainer->appendChild($objUrlFull);
         // save-delete link
         $arrSave = $arrParams;
         $arrSave["action"] = "save-delete";
         $url = $this->request->url_for($arrSave);
         $objUrlSave = $objXml->createElement("url_save_delete", $url);
         $objRecordContainer->appendChild($objUrlSave);
         // openurl redirect link
         $arrOpen = $arrParams;
         $arrOpen["action"] = "sfx";
         $url = $this->request->url_for($arrOpen);
         $objOpenUrl = $objXml->createElement("url_open", $url);
         $objRecordContainer->appendChild($objOpenUrl);
         // openurl kev context object please
         $configSID = $this->registry->getConfig("APPLICATION_SID", false, "calstate.edu:xerxes");
         $kev = Xerxes_Framework_Parser::escapeXml($objXerxesRecord->getOpenURL(null, $configSID));
         $objOpenUrl = $objXml->createElement("openurl_kev_co", $kev);
         $objRecordContainer->appendChild($objOpenUrl);
         // import xerxes xml
         $objXerxesXml = $objXerxesRecord->toXML();
         $objImportRecord = $objXml->importNode($objXerxesXml->documentElement, true);
         $objRecordContainer->appendChild($objImportRecord);
         // optionally import marc-xml
         if ($configMarcResults == true) {
             $objMarcRecord = $objXerxesRecord->getMarcXML();
             $objImportRecord = $objXml->importNode($objMarcRecord->getElementsByTagName("record")->item(0), true);
             $objRecordContainer->appendChild($objImportRecord);
         }
         $position++;
     }
     $objXml->documentElement->appendChild($objRecords);
     return $objXml;
 }