示例#1
0
文件: Record.php 项目: grharry/vufind
 /**
  * Render an HTML checkbox control for the current record.
  *
  * @param string $idPrefix Prefix for checkbox HTML ids
  *
  * @return string
  */
 public function getCheckbox($idPrefix = '')
 {
     static $checkboxCount = 0;
     $id = $this->driver->getSourceIdentifier() . '|' . $this->driver->getUniqueId();
     $context = ['id' => $id, 'count' => $checkboxCount++, 'prefix' => $idPrefix];
     return $this->contextHelper->renderInContext('record/checkbox.phtml', $context);
 }
示例#2
0
 /**
  * Establishes base settings for making recommendations.
  *
  * @param string                            $settings Settings from config.ini
  * @param \VuFind\RecordDriver\AbstractBase $driver   Record driver object
  *
  * @return void
  */
 public function init($settings, $driver)
 {
     // Create array of query parts:
     $parts = [];
     // Add Dewey class to query
     $deweyClass = $driver->tryMethod('getDeweyCallNumber');
     if (!empty($deweyClass)) {
         // Skip "English Fiction" Dewey class -- this won't give us useful
         // matches because there's too much of it and it's too broad.
         if (substr($deweyClass, 0, 3) != '823') {
             $parts[] = 'srw.dd any "' . $deweyClass . '"';
         }
     }
     // Add author to query
     $author = $driver->getPrimaryAuthor();
     if (!empty($author)) {
         $parts[] = 'srw.au all "' . $author . '"';
     }
     // Add subjects to query
     $subjects = $driver->getAllSubjectHeadings();
     foreach ($subjects as $current) {
         $parts[] = 'srw.su all "' . implode(' ', $current) . '"';
     }
     // Add title to query
     $title = $driver->getTitle();
     if (!empty($title)) {
         $parts[] = 'srw.ti any "' . str_replace('"', '', $title) . '"';
     }
     // Build basic query:
     $query = '(' . implode(' or ', $parts) . ')';
     // Not current record ID if this is already a WorldCat record:
     if ($driver->getSourceIdentifier() == 'WorldCat') {
         $id = $driver->getUniqueId();
         $query .= " not srw.no all \"{$id}\"";
     }
     // Perform the search and save results:
     $queryObj = new \VuFindSearch\Query\Query($query);
     $result = $this->searchService->search('WorldCat', $queryObj, 0, 5);
     $this->results = $result->getRecords();
 }
示例#3
0
 /**
  * Establishes base settings for making recommendations.
  *
  * @param string                            $settings Settings from config.ini
  * @param \VuFind\RecordDriver\AbstractBase $driver   Record driver object
  *
  * @return void
  */
 public function init($settings, $driver)
 {
     $this->results = $this->searchService->similar($driver->getSourceIdentifier(), $driver->getUniqueId());
 }
示例#4
0
 /**
  * Get the previous/next record in the last search
  * result set relative to the current one, also return
  * the position of the current record in the result set.
  * Return array('previousRecord'=>previd, 'nextRecord'=>nextid,
  * 'currentPosition'=>number, 'resultTotal'=>number).
  *
  * @param \VuFind\RecordDriver\AbstractBase $driver Driver for the record
  * currently being displayed
  *
  * @return array
  */
 public function getScrollData($driver)
 {
     $retVal = ['firstRecord' => null, 'lastRecord' => null, 'previousRecord' => null, 'nextRecord' => null, 'currentPosition' => null, 'resultTotal' => null];
     // Do nothing if disabled or data missing:
     if ($this->enabled && isset($this->data->currIds) && isset($this->data->searchId) && ($lastSearch = $this->restoreLastSearch())) {
         // Make sure expected data elements are populated:
         if (!isset($this->data->prevIds)) {
             $this->data->prevIds = null;
         }
         if (!isset($this->data->nextIds)) {
             $this->data->nextIds = null;
         }
         // Store total result set size:
         $retVal['resultTotal'] = isset($this->data->total) ? $this->data->total : 0;
         // Set first and last record IDs
         if ($this->data->firstlast) {
             $retVal['firstRecord'] = $this->getFirstRecordId($lastSearch);
             $retVal['lastRecord'] = $this->getLastRecordId($lastSearch);
         }
         // build a full ID string using the driver:
         $id = $driver->getSourceIdentifier() . '|' . $driver->getUniqueId();
         // find where this record is in the current result page
         $pos = is_array($this->data->currIds) ? array_search($id, $this->data->currIds) : false;
         if ($pos !== false) {
             // OK, found this record in the current result page
             // calculate its position relative to the result set
             $retVal['currentPosition'] = ($this->data->page - 1) * $this->data->limit + $pos + 1;
             // count how many records in the current result page
             $count = count($this->data->currIds);
             if ($pos > 0 && $pos < $count - 1) {
                 // the current record is somewhere in the middle of the current
                 // page, ie: not first or last
                 return $this->scrollOnCurrentPage($retVal, $pos);
             } else {
                 if ($pos == 0) {
                     // this record is first record on the current page
                     return $this->fetchPreviousPage($retVal, $lastSearch, $pos, $count);
                 } else {
                     if ($pos == $count - 1) {
                         // this record is last record on the current page
                         return $this->fetchNextPage($retVal, $lastSearch, $pos);
                     }
                 }
             }
         } else {
             // the current record is not on the current page
             // if there is something on the previous page
             if (!empty($this->data->prevIds)) {
                 // check if current record is on the previous page
                 $pos = is_array($this->data->prevIds) ? array_search($id, $this->data->prevIds) : false;
                 if ($pos !== false) {
                     return $this->scrollToPreviousPage($retVal, $lastSearch, $pos);
                 }
             }
             // if there is something on the next page
             if (!empty($this->data->nextIds)) {
                 // check if current record is on the next page
                 $pos = is_array($this->data->nextIds) ? array_search($id, $this->data->nextIds) : false;
                 if ($pos !== false) {
                     return $this->scrollToNextPage($retVal, $lastSearch, $pos);
                 }
             }
             if ($this->data->firstlast) {
                 if ($id == $retVal['firstRecord']) {
                     return $this->scrollToFirstRecord($retVal, $lastSearch);
                 }
                 if ($id == $retVal['lastRecord']) {
                     return $this->scrollToLastRecord($retVal, $lastSearch);
                 }
             }
         }
     }
     return $retVal;
 }