Esempio n. 1
0
 /**
  * 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->getResourceSource() . '|' . $this->driver->getUniqueId();
     $context = ['id' => $id, 'count' => $checkboxCount++, 'prefix' => $idPrefix];
     return $this->contextHelper->renderInContext('record/checkbox.phtml', $context);
 }
Esempio n. 2
0
 /**
  * init
  *
  * 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)
 {
     $sm = $this->getSearchManager();
     $params = $sm->setSearchClassId('Solr')->getParams();
     $searcher = $sm->setSearchClassId('Solr')->getResults($params);
     $this->results = $searcher->getSimilarRecords($driver->getUniqueId());
 }
Esempio n. 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)
 {
     // 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();
 }
Esempio n. 4
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());
 }
Esempio n. 5
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 = ['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;
         // build a full ID string using the driver:
         $id = $driver->getResourceSource() . '|' . $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);
                 }
             }
         }
     }
     return $retVal;
 }
Esempio n. 6
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 = array('previousRecord' => null, 'nextRecord' => null, 'currentPosition' => null, 'resultTotal' => null);
     // Do nothing if disabled:
     if (!$this->enabled) {
         return $retVal;
     }
     if (isset($this->data->currIds) && isset($this->data->searchId)) {
         // build a full ID string using the driver:
         $id = $driver->getResourceSource() . '|' . $driver->getUniqueId();
         // we need to restore the last search object
         // to fetch either the previous/next page of results
         $lastSearch = $this->restoreLastSearch();
         // give up if we can not restore the last search
         if (!$lastSearch) {
             return $retVal;
         }
         if (!isset($this->data->prevIds)) {
             $this->data->prevIds = null;
         }
         if (!isset($this->data->nextIds)) {
             $this->data->nextIds = null;
         }
         $retVal['resultTotal'] = isset($this->data->total) ? $this->data->total : 0;
         // 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 it's 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 the current record is somewhere in the middle of the current
             // page, ie: not first or last, then it is easy
             if ($pos > 0 && $pos < $count - 1) {
                 $retVal['previousRecord'] = $this->data->currIds[$pos - 1];
                 $retVal['nextRecord'] = $this->data->currIds[$pos + 1];
                 // and we're done
                 return $retVal;
             }
             // if this record is first record on the current page
             if ($pos == 0) {
                 // if the current page is NOT the first page, and
                 // the previous page has not been fetched before, then
                 // fetch the previous page
                 if ($this->data->page > 1 && $this->data->prevIds == null) {
                     $this->data->prevIds = $this->fetchPage($lastSearch, $this->data->page - 1);
                 }
                 // if there is something on the previous page, then the previous
                 // record is the last record on the previous page
                 if (!empty($this->data->prevIds)) {
                     $retVal['previousRecord'] = $this->data->prevIds[count($this->data->prevIds) - 1];
                 }
                 // if it is not the last record on the current page, then
                 // we also have a next record on the current page
                 if ($pos < $count - 1) {
                     $retVal['nextRecord'] = $this->data->currIds[$pos + 1];
                 }
                 // and we're done
                 return $retVal;
             }
             // if this record is last record on the current page
             if ($pos == $count - 1) {
                 // if the next page has not been fetched, then
                 // fetch the next page
                 if ($this->data->nextIds == null) {
                     $this->data->nextIds = $this->fetchPage($lastSearch, $this->data->page + 1);
                 }
                 // if there is something on the next page, then the next
                 // record is the first record on the next page
                 if (!empty($this->data->nextIds)) {
                     $retVal['nextRecord'] = $this->data->nextIds[0];
                 }
                 // if it is not the first record on the current page, then
                 // we also have a previous record on the current page
                 if ($pos > 0) {
                     $retVal['previousRecord'] = $this->data->currIds[$pos - 1];
                 }
                 // and we're done
                 return $retVal;
             }
         } 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) {
                     // decrease the page in the session because
                     // we're now sliding into the previous page
                     // (-- doesn't work on ArrayObjects)
                     $this->data->page = $this->data->page - 1;
                     // shift pages to the right
                     $tmp = $this->data->currIds;
                     $this->data->currIds = $this->data->prevIds;
                     $this->data->nextIds = $tmp;
                     $this->data->prevIds = null;
                     // now we can set the previous/next record
                     if ($pos > 0) {
                         $retVal['previousRecord'] = $this->data->currIds[$pos - 1];
                     }
                     $retVal['nextRecord'] = $this->data->nextIds[0];
                     // recalculate the current position
                     $retVal['currentPosition'] = ($this->data->page - 1) * $this->data->limit + $pos + 1;
                     // update the search URL in the session
                     $lastSearch->getParams()->setPage($this->data->page);
                     $this->rememberSearch($lastSearch);
                     // and we're done
                     return $retVal;
                 }
             }
             // 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) {
                     // increase the page in the session because
                     // we're now sliding into the next page
                     // (++ doesn't work on ArrayObjects)
                     $this->data->page = $this->data->page + 1;
                     // shift pages to the left
                     $tmp = $this->data->currIds;
                     $this->data->currIds = $this->data->nextIds;
                     $this->data->prevIds = $tmp;
                     $this->data->nextIds = null;
                     // now we can set the previous/next record
                     $retVal['previousRecord'] = $this->data->prevIds[count($this->data->prevIds) - 1];
                     if ($pos < count($this->data->currIds) - 1) {
                         $retVal['nextRecord'] = $this->data->currIds[$pos + 1];
                     }
                     // recalculate the current position
                     $retVal['currentPosition'] = ($this->data->page - 1) * $this->data->limit + $pos + 1;
                     // update the search URL in the session
                     $lastSearch->getParams()->setPage($this->data->page);
                     $this->rememberSearch($lastSearch);
                     // and we're done
                     return $retVal;
                 }
             }
         }
     }
     return $retVal;
 }
Esempio n. 7
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('Solr', $driver->getUniqueId());
 }