コード例 #1
0
 /**
  * Load titles that have been rated by other users which are similar to this.
  *
  * @param SearchObject_Solr|SearchObject_Base $db
  * @param UserRating $ratedTitle
  * @param integer $userId
  * @param array $ratedTitles
  * @param array $suggestions
  * @param integer[] $notInterestedTitles
  * @return int The number of suggestions for this title
  */
 static function getSimilarlyRatedTitles($db, $ratedTitle, $userId, $ratedTitles, &$suggestions, $notInterestedTitles)
 {
     $numRecommendations = 0;
     //If there is no ISBN, can we come up with an alternative algorithm?
     //Possibly using common ratings with other patrons?
     //Get a list of other patrons that have rated this title and that like it as much or more than the active user..
     $otherRaters = new UserRating();
     //Query the database to get items that other users who rated this liked.
     $sqlStatement = "SELECT resourceid, record_id, " . " sum(case rating when 5 then 10 when 4 then 6 end) as rating " . " FROM `user_rating` inner join resource on resource.id = user_rating.resourceid WHERE userId in " . " (select userId from user_rating where resourceId = " . $ratedTitle->resourceid . " and rating >= 4 " . " and userid != " . $userId . ") " . " and rating >= 4 " . " and resourceId != " . $ratedTitle->resourceid . " and deleted = 0 " . " group by resourceid order by rating desc limit 10";
     //Sort so the highest titles are on top and limit to 10 suggestions.
     $otherRaters->query($sqlStatement);
     if ($otherRaters->N > 0) {
         //Other users have also rated this title.
         while ($otherRaters->fetch()) {
             //Process the title
             disableErrorHandler();
             if (!($ownedRecord = $db->getRecord($otherRaters->record_id))) {
                 //Old record which has been removed? Ignore for purposes of suggestions.
                 continue;
             }
             enableErrorHandler();
             //get the title from the Solr Index
             if (isset($ownedRecord['isbn'])) {
                 if (strpos($ownedRecord['isbn'][0], ' ') > 0) {
                     $isbnInfo = explode(' ', $ownedRecord['isbn'][0]);
                     $isbn = $isbnInfo[0];
                 } else {
                     $isbn = $ownedRecord['isbn'][0];
                 }
                 $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn);
                 $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn);
             } else {
                 $isbn13 = '';
                 $isbn10 = '';
             }
             //See if we can get the series title from the record
             if (isset($ownedRecord['series'])) {
                 $series = $ownedRecord['series'][0];
             } else {
                 $series = '';
             }
             $similarTitle = array('title' => $ownedRecord['title'], 'title_short' => $ownedRecord['title_short'], 'author' => isset($ownedRecord['author']) ? $ownedRecord['author'] : '', 'publicationDate' => $ownedRecord['publishDate'], 'isbn' => $isbn13, 'isbn10' => $isbn10, 'upc' => isset($ownedRecord['upc']) ? $ownedRecord['upc'][0] : '', 'recordId' => $ownedRecord['id'], 'id' => $ownedRecord['id'], 'libraryOwned' => true, 'isCurrent' => false, 'shortId' => substr($ownedRecord['id'], 1), 'format_category' => isset($ownedRecord['format_category']) ? $ownedRecord['format_category'] : '', 'format' => $ownedRecord['format'], 'recordtype' => $ownedRecord['recordtype'], 'series' => $series, 'grouping_term' => $ownedRecord['grouping_term']);
             $numRecommendations++;
             Suggestions::addTitleToSuggestions($ratedTitle, $similarTitle['title'], $similarTitle['recordId'], $similarTitle, $ratedTitles, $suggestions, $notInterestedTitles);
         }
     }
     return $numRecommendations;
 }
コード例 #2
0
ファイル: Novelist.php プロジェクト: bryandease/VuFind-Plus
 function loadNoveListTitle($originalIsbn, $item, &$titleList, &$titlesOwned, $seriesName = '')
 {
     global $user;
     $isbnList = array();
     /** @var SimpleXMLElement $titleItem */
     foreach ($item->TitleList->TitleItem as $titleItem) {
         $tmpIsbn = (string) $titleItem->attributes()->value;
         if (strlen($tmpIsbn) == 10 || strlen($tmpIsbn) == 13) {
             $isbnList[] = (string) $titleItem->attributes()->value;
         }
     }
     //If there is no ISBN, don't bother loading the title
     if (count($isbnList) == 0) {
         return;
     }
     //run a search to get the record id for the isbns.
     //TODO:  cache this info since it can take a really long time to load
     $searchObj = SearchObjectFactory::initSearchObject();
     $searchObj->setBasicQuery(implode(' OR ', $isbnList), 'ISN');
     $searchObj->disableScoping();
     //Add a filter to only include books and DVDs
     $searchObj->processSearch(false, false);
     $matchingRecords = $searchObj->getResultRecordSet();
     $isCurrent = in_array($originalIsbn, $isbnList);
     if (isset($seriesName)) {
         $series = $seriesName;
     } else {
         $series = null;
     }
     $volume = '';
     if ($item->Volume) {
         $volume = (string) $item->Volume;
     }
     if (count($matchingRecords) > 0) {
         $ownedRecord = $matchingRecords[0];
         if (strpos($ownedRecord['isbn'][0], ' ') > 0) {
             $isbnInfo = explode(' ', $ownedRecord['isbn'][0]);
             $isbn = $isbnInfo[0];
         } else {
             $isbn = $ownedRecord['isbn'][0];
         }
         $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn);
         $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn);
         if (!isset($series)) {
             if (isset($ownedRecord['series'])) {
                 $series = $ownedRecord['series'][0];
             }
         }
         //Load rating data
         if ($ownedRecord['recordtype'] == 'marc') {
             $resource = new Resource();
             $resource->source = 'VuFind';
             $resource->record_id = $ownedRecord['id'];
             $resource->find(true);
             $ratingData = $resource->getRatingData($user);
             $fullRecordLink = '/Record/' . $ownedRecord['id'] . '/Home';
         } else {
             require_once ROOT_DIR . '/sys/eContent/EContentRating.php';
             $shortId = str_replace('econtentRecord', '', $ownedRecord['id']);
             $econtentRating = new EContentRating();
             $econtentRating->recordId = $shortId;
             $ratingData = $econtentRating->getRatingData($user, false);
             $fullRecordLink = '/EcontentRecord/' . $shortId . '/Home';
         }
         //See if we can get the series title from the record
         $titleList[] = array('title' => $ownedRecord['title'], 'title_short' => isset($ownedRecord['title_short']) ? $ownedRecord['title_short'] : $ownedRecord['title'], 'author' => isset($ownedRecord['author']) ? $ownedRecord['author'] : '', 'publicationDate' => (string) $item->PublicationDate, 'isbn' => $isbn13, 'isbn10' => $isbn10, 'upc' => isset($ownedRecord['upc'][0]) ? $ownedRecord['upc'][0] : '', 'recordId' => $ownedRecord['id'], 'recordtype' => $ownedRecord['recordtype'], 'id' => $ownedRecord['id'], 'libraryOwned' => true, 'isCurrent' => $isCurrent, 'shortId' => substr($ownedRecord['id'], 1), 'format_category' => $ownedRecord['format_category'], 'format' => $ownedRecord['format'], 'series' => $series, 'volume' => $volume, 'ratingData' => $ratingData, 'fullRecordLink' => $fullRecordLink);
         $titlesOwned++;
     } else {
         $isbn = $isbnList[0];
         $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn);
         $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn);
         $titleList[] = array('title' => (string) $item->Name, 'author' => (string) $item->Author, 'publicationDate' => (string) $item->PublicationDate, 'isbn' => $isbn13, 'isbn10' => $isbn10, 'recordId' => -1, 'libraryOwned' => false, 'isCurrent' => $isCurrent, 'series' => $series, 'volume' => $volume);
     }
 }
コード例 #3
0
 private function makeIsbn10And13()
 {
     if (!is_null($this->isn) && strlen($this->isn) >= 10) {
         require_once ROOT_DIR . '/Drivers/marmot_inc/ISBNConverter.php';
         if (strlen($this->isn) == 10) {
             //$this->log("Provided ISBN is 10 digits.", PEAR_LOG_INFO);
             $this->isbn10 = $this->isn;
             $this->isbn13 = ISBNConverter::convertISBN10to13($this->isbn10);
         } elseif (strlen($this->isn) == 13) {
             //$this->log("Provided ISBN is 13 digits.", PEAR_LOG_INFO);
             $this->isbn13 = $this->isn;
             $this->isbn10 = ISBNConverter::convertISBN13to10($this->isbn13);
         }
         $this->log("Loaded isbn10 {$this->isbn10} and isbn13 {$this->isbn13}.", PEAR_LOG_INFO);
         $this->logTime("create isbn 10 and isbn 13");
     }
 }
コード例 #4
0
ファイル: Novelist3.php プロジェクト: victorfcm/VuFind-Plus
 private function loadNoveListTitle($currentId, $item, &$titleList, &$titlesOwned, $seriesName = '')
 {
     global $user;
     global $timer;
     global $configArray;
     //Find the correct grouped work based on the isbns;
     require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php';
     require_once ROOT_DIR . '/sys/Grouping/GroupedWorkIdentifier.php';
     require_once ROOT_DIR . '/sys/Grouping/GroupedWorkIdentifierRef.php';
     $timer->logTime("Start loadNoveListTitle");
     /** @var SimpleXMLElement $titleItem */
     $permanentId = null;
     $concatenatedIsbns = "'" . implode("','", $item->isbns) . "'";
     $groupedWorkIdentifier = new GroupedWorkIdentifier();
     $groupedWorkIdentifier->type = "isbn";
     $groupedWorkIdentifier->whereAdd("identifier in ({$concatenatedIsbns})");
     if ($groupedWorkIdentifier->find()) {
         while ($groupedWorkIdentifier->fetch()) {
             $groupedWorkIdentifierRef = new GroupedWorkIdentifierRef();
             $groupedWorkIdentifierRef->identifier_id = $groupedWorkIdentifier->id;
             $groupedWorkIdentifierRef->find();
             if ($groupedWorkIdentifierRef->N == 1) {
                 $groupedWorkIdentifierRef->fetch();
                 $groupedWork = new GroupedWork();
                 $groupedWork->id = $groupedWorkIdentifierRef->grouped_work_id;
                 if ($groupedWork->find(true)) {
                     $permanentId = $groupedWork->permanent_id;
                     break;
                 }
             }
         }
     }
     $timer->logTime("Load Novelist Title - Find Grouped Work based on identifier {$permanentId}");
     $isCurrent = $currentId == $permanentId;
     if (isset($seriesName)) {
         $series = $seriesName;
     } else {
         $series = '';
     }
     $volume = '';
     if (isset($item->volume)) {
         $volume = $item->volume;
     }
     //We didn't find a match in the database so we don't own it
     if ($permanentId == null) {
         $isbn = reset($item->isbns);
         $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn);
         $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn);
         $curTitle = array('title' => $item->full_title, 'author' => $item->author, 'isbn' => $isbn13, 'isbn10' => $isbn10, 'recordId' => -1, 'libraryOwned' => false, 'isCurrent' => $isCurrent, 'series' => $series, 'volume' => $volume, 'reason' => isset($item->reason) ? $item->reason : '', 'smallCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=small&isn=" . $isbn13, 'mediumCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=medium&isn=" . $isbn13);
     } else {
         //Get more information from Solr
         /** @var GroupedWorkDriver $recordDriver */
         $recordDriver = new GroupedWorkDriver($permanentId);
         $timer->logTime("Find grouped work in solr");
         if ($recordDriver->isValid) {
             if (!isset($series)) {
                 if (isset($ownedRecord['series'])) {
                     $series = $ownedRecord['series'][0];
                 }
             }
             //Load data about the record
             $ratingData = $recordDriver->getRatingData($user);
             $timer->logTime("Get Rating data");
             $fullRecordLink = $recordDriver->getLinkUrl();
             //See if we can get the series title from the record
             $curTitle = array('title' => $recordDriver->getTitle(), 'title_short' => $recordDriver->getTitle(), 'author' => $recordDriver->getPrimaryAuthor(), 'isbn' => $recordDriver->getCleanISBN(), 'isbn10' => $recordDriver->getCleanISBN(), 'upc' => $recordDriver->getCleanUPC(), 'recordId' => $recordDriver->getPermanentId(), 'recordtype' => 'grouped_work', 'id' => $recordDriver->getPermanentId(), 'libraryOwned' => true, 'isCurrent' => $isCurrent, 'shortId' => $recordDriver->getPermanentId(), 'format_category' => $recordDriver->getFormatCategory(), 'series' => $series, 'volume' => $volume, 'ratingData' => $ratingData, 'fullRecordLink' => $fullRecordLink, 'reason' => isset($item->reason) ? $item->reason : '', 'recordDriver' => $recordDriver, 'smallCover' => $recordDriver->getBookcoverUrl('small'), 'mediumCover' => $recordDriver->getBookcoverUrl('medium'));
             $timer->logTime("Load title information");
             $titlesOwned++;
         } else {
             $isbn = reset($item->isbns);
             $isbn13 = strlen($isbn) == 13 ? $isbn : ISBNConverter::convertISBN10to13($isbn);
             $isbn10 = strlen($isbn) == 10 ? $isbn : ISBNConverter::convertISBN13to10($isbn);
             $curTitle = array('title' => $item->full_title, 'author' => $item->author, 'isbn' => $isbn13, 'isbn10' => $isbn10, 'recordId' => -1, 'libraryOwned' => false, 'isCurrent' => $isCurrent, 'series' => $series, 'volume' => $volume, 'reason' => isset($item->reason) ? $item->reason : '', 'smallCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=small&isn=" . $isbn13, 'mediumCover' => $cover = $configArray['Site']['coverUrl'] . "/bookcover.php?size=medium&isn=" . $isbn13);
         }
     }
     $titleList[] = $curTitle;
     return $curTitle;
 }