Пример #1
0
 public function launch()
 {
     global $interface;
     global $user;
     //Load user ratings
     require_once ROOT_DIR . '/Drivers/marmot_inc/UserRating.php';
     $rating = new UserRating();
     $resource = new Resource();
     $rating->joinAdd($resource);
     $rating->userid = $user->id;
     $rating->find();
     $ratings = array();
     while ($rating->fetch()) {
         if ($rating->deleted == 0) {
             $ratings[] = array('id' => $rating->id, 'title' => $rating->title, 'author' => $rating->author, 'format' => $rating->format, 'rating' => $rating->rating, 'resourceId' => $rating->resourceid, 'fullId' => $rating->record_id, 'shortId' => $rating->shortId, 'link' => '/Record/' . $rating->record_id . '/Home', 'dateRated' => $rating->dateRated, 'ratingData' => array('user' => $rating->rating), 'source' => 'VuFind');
         }
     }
     //Load econtent ratings
     require_once ROOT_DIR . '/sys/eContent/EContentRating.php';
     $eContentRating = new EContentRating();
     $econtentRecord = new EContentRecord();
     $eContentRating->joinAdd($econtentRecord);
     $eContentRating->userId = $user->id;
     $eContentRating->find();
     while ($eContentRating->fetch()) {
         if ($eContentRating->status == 'active') {
             $resource = new Resource();
             $resource->record_id = $eContentRating->id;
             $resource->source = 'eContent';
             $resource->find(true);
             $ratings[] = array('id' => $eContentRating->id, 'title' => $eContentRating->title, 'author' => $eContentRating->author, 'format' => $resource->format_category, 'rating' => $eContentRating->rating, 'fullId' => $eContentRating->id, 'shortId' => $eContentRating->id, 'link' => '/EcontentRecord/' . $eContentRating->id . '/Home', 'dateRated' => $eContentRating->dateRated, 'ratingData' => array('user' => $eContentRating->rating), 'source' => 'eContent');
         }
     }
     asort($ratings);
     //Load titles the user is not interested in
     $notInterested = array();
     $notInterestedObj = new NotInterested();
     $resource = new Resource();
     $notInterestedObj->joinAdd($resource);
     $notInterestedObj->userId = $user->id;
     $notInterestedObj->deleted = 0;
     $notInterestedObj->selectAdd('user_not_interested.id as user_not_interested_id');
     $notInterestedObj->find();
     while ($notInterestedObj->fetch()) {
         if ($notInterestedObj->source == 'VuFind') {
             $link = '/Record/' . $notInterestedObj->record_id;
         } else {
             $link = '/EcontentRecord/' . $notInterestedObj->record_id;
         }
         if ($notInterestedObj->deleted == 0) {
             $notInterested[] = array('id' => $notInterestedObj->user_not_interested_id, 'title' => $notInterestedObj->title, 'author' => $notInterestedObj->author, 'dateMarked' => $notInterestedObj->dateMarked, 'link' => $link);
         }
     }
     $interface->assign('ratings', $ratings);
     $interface->assign('notInterested', $notInterested);
     $interface->setPageTitle('My Ratings');
     $interface->setTemplate('myRatings.tpl');
     $interface->display('layout.tpl');
 }
Пример #2
0
 public function launch()
 {
     global $interface;
     global $user;
     //Load user ratings
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserWorkReview.php';
     require_once ROOT_DIR . '/sys/Grouping/GroupedWork.php';
     require_once ROOT_DIR . '/RecordDrivers/GroupedWorkDriver.php';
     $rating = new UserWorkReview();
     $rating->userId = $user->id;
     $rating->find();
     $ratings = array();
     while ($rating->fetch()) {
         $groupedWorkDriver = new GroupedWorkDriver($rating->groupedRecordPermanentId);
         if ($groupedWorkDriver->isValid) {
             $ratings[] = array('id' => $rating->id, 'groupedWorkId' => $rating->groupedRecordPermanentId, 'title' => $groupedWorkDriver->getTitle(), 'author' => $groupedWorkDriver->getPrimaryAuthor(), 'rating' => $rating->rating, 'review' => $rating->review, 'link' => $groupedWorkDriver->getLinkUrl(), 'dateRated' => $rating->dateRated, 'ratingData' => $groupedWorkDriver->getRatingData());
         }
     }
     asort($ratings);
     //Load titles the user is not interested in
     $notInterested = array();
     require_once ROOT_DIR . '/sys/LocalEnrichment/NotInterested.php';
     $notInterestedObj = new NotInterested();
     $notInterestedObj->userId = $user->id;
     $notInterestedObj->find();
     while ($notInterestedObj->fetch()) {
         $groupedWorkId = $notInterestedObj->groupedRecordPermanentId;
         $groupedWorkDriver = new GroupedWorkDriver($groupedWorkId);
         if ($groupedWorkDriver->isValid) {
             $notInterested[] = array('id' => $notInterestedObj->id, 'title' => $groupedWorkDriver->getTitle(), 'author' => $groupedWorkDriver->getPrimaryAuthor(), 'dateMarked' => $notInterestedObj->dateMarked, 'link' => $groupedWorkDriver->getLinkUrl());
         }
     }
     $interface->assign('ratings', $ratings);
     $interface->assign('notInterested', $notInterested);
     $interface->assign('showNotInterested', false);
     $interface->setPageTitle('My Ratings');
     $interface->assign('sidebar', 'MyAccount/account-sidebar.tpl');
     $interface->setTemplate('myRatings.tpl');
     $interface->display('layout.tpl');
 }
Пример #3
0
 static function getSuggestions($userId = -1)
 {
     global $configArray;
     if ($userId == -1) {
         global $user;
         $userId = $user->id;
     }
     //Load all titles the user is not interested in
     $notInterestedTitles = array();
     $notInterested = new NotInterested();
     $resource = new Resource();
     $notInterested->joinAdd($resource);
     $notInterested->userId = $userId;
     $notInterested->find();
     while ($notInterested->fetch()) {
         if ($notInterested->source == 'VuFind') {
             $fullId = $notInterested->record_id;
         } else {
             $fullId = 'econtentRecord' . $notInterested->record_id;
         }
         $notInterestedTitles[$fullId] = $fullId;
     }
     //Load all titles the user has rated (print)
     $allRatedTitles = array();
     $allLikedRatedTitles = array();
     $ratings = new UserRating();
     $ratings->userid = $userId;
     $resource = new Resource();
     $notInterested->joinAdd($resource);
     $ratings->joinAdd($resource);
     $ratings->find();
     while ($ratings->fetch()) {
         $allRatedTitles[$ratings->record_id] = $ratings->record_id;
         if ($ratings->rating >= 4) {
             $allLikedRatedTitles[] = $ratings->record_id;
         }
     }
     //Load all titles the user has rated (eContent)
     $econtentRatings = new EContentRating();
     $econtentRatings->userId = $userId;
     $econtentRatings->find();
     while ($econtentRatings->fetch()) {
         $allRatedTitles['econtentRecord' . $econtentRatings->recordId] = 'econtentRecord' . $econtentRatings->recordId;
         if ($econtentRatings->rating >= 4) {
             $allLikedRatedTitles[] = 'econtentRecord' . $econtentRatings->recordId;
         }
     }
     // Setup Search Engine Connection
     $class = $configArray['Index']['engine'];
     $url = $configArray['Index']['url'];
     $db = new $class($url);
     if ($configArray['System']['debugSolr']) {
         $db->debug = true;
     }
     //Get a list of all titles the user has rated (3 star and above)
     $ratings = new UserRating();
     $ratings->whereAdd("userId = {$userId}", 'AND');
     $ratings->whereAdd('rating >= 3', 'AND');
     $ratings->orderBy('rating DESC, dateRated DESC, id DESC');
     //Use the 20 highest ratings to make real-time recommendations faster
     $ratings->limit(0, 5);
     $ratings->find();
     $suggestions = array();
     //echo("User has rated {$ratings->N} titles<br/>");
     if ($ratings->N > 0) {
         while ($ratings->fetch()) {
             $resourceId = $ratings->resourceid;
             //Load the resource
             $resource = new Resource();
             $resource->id = $resourceId;
             $resource->find();
             if ($resource->N != 1) {
                 //echo("Did not find resource for $resourceId<br/>");
             } else {
                 $resource->fetch();
                 //echo("Found resource for $resourceId - {$resource->title}<br/>");
                 $ratedTitles[$resource->record_id] = clone $ratings;
                 $numRecommendations = 0;
                 if ($resource->isbn) {
                     //If there is an isbn for the title, we can load similar titles based on Novelist.
                     $isbn = $resource->isbn;
                     $numRecommendations = Suggestions::getNovelistRecommendations($ratings, $isbn, $resource, $allRatedTitles, $suggestions, $notInterestedTitles);
                     //echo("&nbsp;- Found $numRecommendations for $isbn from Novelist<br/>");
                 }
                 if ($numRecommendations == 0) {
                     Suggestions::getSimilarlyRatedTitles($db, $ratings, $userId, $allRatedTitles, $suggestions, $notInterestedTitles);
                     //echo("&nbsp;- Found $numRecommendations based on ratings from other users<br/>");
                 }
             }
         }
     }
     //Also get eContent the user has rated highly
     $econtentRatings = new EContentRating();
     $econtentRatings->userId = $userId;
     $econtentRatings->whereAdd('rating >= 3');
     $econtentRatings->orderBy('rating DESC, dateRated DESC');
     $econtentRatings->limit(0, 5);
     $econtentRatings->find();
     //echo("User has rated {$econtentRatings->N} econtent titles<br/>");
     if ($econtentRatings->N > 0) {
         while ($econtentRatings->fetch()) {
             //echo("Processing eContent Rating {$econtentRatings->recordId}<br/>");
             //Load the resource
             $resource = new Resource();
             $resource->record_id = $econtentRatings->recordId;
             $resource->source = 'eContent';
             $resource->find();
             if ($resource->N != 1) {
                 //echo("Did not find resource for $resourceId<br/>");
             } else {
                 $resource->fetch();
                 //echo("Found resource for $resourceId - {$resource->title}<br/>");
                 $ratedTitles[$resource->record_id] = clone $econtentRatings;
                 $numRecommendations = 0;
                 if ($resource->isbn) {
                     //If there is an isbn for the title, we can load similar titles based on Novelist.
                     $isbn = $resource->isbn;
                     $numRecommendations = Suggestions::getNovelistRecommendations($ratings, $isbn, $resource, $allRatedTitles, $suggestions, $notInterestedTitles);
                     //echo("&nbsp;- Found $numRecommendations for $isbn from Novelist<br/>");
                 }
                 if ($numRecommendations == 0) {
                     Suggestions::getSimilarlyRatedTitles($db, $ratings, $userId, $allRatedTitles, $suggestions, $notInterestedTitles);
                     //echo("&nbsp;- Found $numRecommendations based on ratings from other users<br/>");
                 }
             }
         }
     }
     $groupedTitles = array();
     foreach ($suggestions as $suggestion) {
         $groupingTerm = $suggestion['titleInfo']['grouping_term'];
         $groupedTitles[] = $groupingTerm;
     }
     //If the user has not rated anything, return nothing.
     if (count($allLikedRatedTitles) == 0) {
         return array();
     }
     //Get recommendations based on everything I've rated using more like this functionality
     $class = $configArray['Index']['engine'];
     $url = $configArray['Index']['url'];
     /** @var Solr $db */
     $db = new $class($url);
     //$db->debug = true;
     $moreLikeTheseSuggestions = $db->getMoreLikeThese($allLikedRatedTitles);
     //print_r($moreLikeTheseSuggestions);
     if (count($suggestions) < 30) {
         foreach ($moreLikeTheseSuggestions['response']['docs'] as $suggestion) {
             $groupingTerm = $suggestion['grouping_term'];
             if (array_key_exists($groupingTerm, $groupedTitles)) {
                 //echo ($suggestion['grouping_term'] . " is already in the suggestions");
                 continue;
             }
             $groupedTitles[$groupingTerm] = $groupingTerm;
             //print_r($suggestion);
             if (!array_key_exists($suggestion['id'], $allRatedTitles) && !array_key_exists($suggestion['id'], $notInterestedTitles)) {
                 $suggestions[$suggestion['id']] = array('rating' => $suggestion['rating'] - 2.5, 'titleInfo' => $suggestion, 'basedOn' => 'MetaData for all titles rated');
             }
             if (count($suggestions) == 30) {
                 break;
             }
         }
     }
     //print_r($groupedTitles);
     //sort suggestions based on score from ascending to descending
     uasort($suggestions, 'Suggestions::compareSuggestions');
     //Only return up to 50 suggestions to make the page size reasonable
     $suggestions = array_slice($suggestions, 0, 30, true);
     //Return suggestions for use in the user interface.
     return $suggestions;
 }
Пример #4
0
 static function getSuggestions($userId = -1)
 {
     global $configArray;
     //Configuration for suggestions
     $doNovelistRecommendations = true;
     $numTitlesToLoadNovelistRecommendationsFor = 10;
     $doMetadataRecommendations = true;
     $doSimilarlyRatedRecommendations = false;
     $maxRecommendations = 30;
     if ($userId == -1) {
         global $user;
         $userId = $user->id;
     }
     //Load all titles the user is not interested in
     $notInterestedTitles = array();
     $notInterested = new NotInterested();
     $notInterested->userId = $userId;
     $notInterested->find();
     while ($notInterested->fetch()) {
         $notInterestedTitles[$notInterested->groupedRecordPermanentId] = $notInterested->groupedRecordPermanentId;
     }
     //Load all titles the user has rated
     $allRatedTitles = array();
     $allLikedRatedTitles = array();
     require_once ROOT_DIR . '/sys/LocalEnrichment/UserWorkReview.php';
     $ratings = new UserWorkReview();
     $ratings->userId = $userId;
     $ratings->find();
     while ($ratings->fetch()) {
         $allRatedTitles[$ratings->groupedRecordPermanentId] = $ratings->groupedRecordPermanentId;
         if ($ratings->rating >= 4) {
             $allLikedRatedTitles[] = $ratings->groupedRecordPermanentId;
         }
     }
     // Setup Search Engine Connection
     $class = $configArray['Index']['engine'];
     $url = $configArray['Index']['url'];
     $db = new $class($url);
     $suggestions = array();
     if ($doNovelistRecommendations) {
         //Get a list of all titles the user has rated (3 star and above)
         $ratings = new UserWorkReview();
         $ratings->whereAdd("userId = {$userId}", 'AND');
         $ratings->whereAdd('rating >= 3', 'AND');
         $ratings->orderBy('rating DESC, dateRated DESC, id DESC');
         //Use just recent ratings to make real-time recommendations faster
         $ratings->limit(0, $numTitlesToLoadNovelistRecommendationsFor);
         $ratings->find();
         //echo("User has rated {$ratings->N} titles<br/>");
         require_once ROOT_DIR . '/services/API/WorkAPI.php';
         $workApi = new WorkAPI();
         if ($ratings->N > 0) {
             while ($ratings->fetch()) {
                 $groupedWorkId = $ratings->groupedRecordPermanentId;
                 //echo("Found resource for $resourceId - {$resource->title}<br/>");
                 $ratedTitles[$ratings->groupedRecordPermanentId] = clone $ratings;
                 $isbns = $workApi->getIsbnsForWork($groupedWorkId);
                 Suggestions::getNovelistRecommendations($ratings, $groupedWorkId, $isbns, $allRatedTitles, $suggestions, $notInterestedTitles);
                 /*if (count($suggestions) >= $maxRecommendations){
                 			break;
                 		}*/
             }
         }
     }
     if ($doSimilarlyRatedRecommendations && count($suggestions) < $maxRecommendations) {
         //Get a list of all titles the user has rated (3 star and above)
         $ratings = new UserWorkReview();
         $ratings->whereAdd("userId = {$userId}", 'AND');
         $ratings->whereAdd('rating >= 3', 'AND');
         $ratings->orderBy('rating DESC, dateRated DESC, id DESC');
         //Use just recent ratings to make real-time recommendations faster
         $ratings->limit(0, $numTitlesToLoadNovelistRecommendationsFor);
         $ratings->find();
         //echo("User has rated {$ratings->N} titles<br/>");
         require_once ROOT_DIR . '/services/API/WorkAPI.php';
         $workApi = new WorkAPI();
         if ($ratings->N > 0) {
             while ($ratings->fetch()) {
                 Suggestions::getSimilarlyRatedTitles($workApi, $db, $ratings, $userId, $allRatedTitles, $suggestions, $notInterestedTitles);
             }
         }
     }
     //Get metadata recommendations if enabled, we have ratings, and we don't have enough suggestions yet
     if ($doMetadataRecommendations && count($allLikedRatedTitles) > 0 && count($suggestions) < $maxRecommendations) {
         //Get recommendations based on everything I've rated using more like this functionality
         $class = $configArray['Index']['engine'];
         $url = $configArray['Index']['url'];
         /** @var Solr $db */
         $db = new $class($url);
         //$db->debug = true;
         $moreLikeTheseSuggestions = $db->getMoreLikeThese($allLikedRatedTitles, $notInterestedTitles);
         foreach ($moreLikeTheseSuggestions['response']['docs'] as $suggestion) {
             if (!array_key_exists($suggestion['id'], $allRatedTitles) && !array_key_exists($suggestion['id'], $notInterestedTitles)) {
                 $suggestions[$suggestion['id']] = array('rating' => $suggestion['rating'] - 2.5, 'titleInfo' => $suggestion, 'basedOn' => 'MetaData for all titles rated');
             }
             if (count($suggestions) == $maxRecommendations) {
                 break;
             }
         }
     }
     //sort suggestions based on score from ascending to descending
     uasort($suggestions, 'Suggestions::compareSuggestions');
     //Only return up to $maxRecommendations suggestions to make the page size reasonable
     $suggestions = array_slice($suggestions, 0, $maxRecommendations, true);
     //Return suggestions for use in the user interface.
     return $suggestions;
 }
Пример #5
0
 function ClearNotInterested()
 {
     global $user;
     $idToClear = $_REQUEST['id'];
     require_once ROOT_DIR . '/sys/NotInterested.php';
     $notInterested = new NotInterested();
     $notInterested->userId = $user->id;
     $notInterested->id = $idToClear;
     $result = array('result' => false);
     if ($notInterested->find(true)) {
         $notInterested->delete();
         $result = array('result' => true);
     }
     return json_encode($result);
 }
Пример #6
0
 /**
  * Get filters based on scoping for the search
  * @param Library $searchLibrary
  * @param Location $searchLocation
  * @return array
  */
 public function getScopingFilters($searchLibrary, $searchLocation)
 {
     global $user;
     global $configArray;
     $filter = array();
     //*************************
     //Marmot overrides for filtering based on library system and location
     //Only show visible records
     if (!isset($configArray['Index']['ignoreBibSuppression']) || $configArray['Index']['ignoreBibSuppression'] == false) {
         $filter[] = '-bib_suppression:suppressed';
     }
     //Only include titles that the user has access to based on pType
     $pType = 0;
     $owningSystem = '';
     $owningLibrary = '';
     $canUseDefaultPType = !$this->scopingDisabled;
     if ($user) {
         $pType = $user->patronType;
     } elseif (isset($searchLocation) && $searchLocation->defaultPType > 0 && $canUseDefaultPType) {
         $pType = $searchLocation->defaultPType;
     } elseif (isset($searchLibrary) && $searchLibrary->defaultPType > 0 && $canUseDefaultPType) {
         $pType = $searchLibrary->defaultPType;
     }
     if (isset($searchLocation)) {
         $owningLibrary = $searchLocation->facetLabel;
     }
     if (isset($searchLibrary)) {
         $owningSystem = $searchLibrary->facetLabel;
     }
     if ($pType > 0 && $configArray['Index']['enableUsableByFilter'] == true) {
         $usableFilter = 'usable_by:(' . $pType . ' OR all)';
         if (strlen($owningLibrary) > 0) {
             $usableFilter .= " OR building:\"{$owningLibrary}\" OR building:\"{$owningLibrary} Online\"";
         }
         if (strlen($owningSystem) > 0) {
             $usableFilter .= " OR institution:\"{$owningSystem}\" OR building:\"{$owningSystem} Online\"";
         }
         $homeLibrary = Library::getPatronHomeLibrary();
         if ($homeLibrary && $homeLibrary != $searchLibrary) {
             $homeLibraryFacet = $homeLibrary->facetLabel;
             $usableFilter .= " OR building:\"{$homeLibraryFacet}\" OR building:\"{$homeLibraryFacet} Online\"";
         }
         $filter[] = '(' . $usableFilter . ')';
     }
     $blacklistRecords = null;
     if (isset($searchLocation) && strlen($searchLocation->recordsToBlackList) > 0) {
         $blacklistRecords = $searchLocation->recordsToBlackList;
     }
     if (isset($searchLibrary) && strlen($searchLibrary->recordsToBlackList) > 0) {
         if (is_null($blacklistRecords)) {
             $blacklistRecords = $searchLibrary->recordsToBlackList;
         } else {
             $blacklistRecords .= "\n" . $searchLibrary->recordsToBlackList;
         }
     }
     if (!is_null($blacklistRecords)) {
         $recordsToBlacklist = preg_split('/\\s|\\r\\n|\\r|\\n/s', $blacklistRecords);
         $blacklist = "NOT (";
         $numRecords = 0;
         foreach ($recordsToBlacklist as $curRecord) {
             if (strlen($curRecord) > 0) {
                 $numRecords++;
                 if ($numRecords > 1) {
                     $blacklist .= " OR ";
                 }
                 $blacklist .= "id:" . $curRecord;
             }
         }
         $blacklist .= ")";
         $filter[] = $blacklist;
     }
     //Process anything that the user is not interested in.
     require_once ROOT_DIR . '/sys/NotInterested.php';
     if ($user) {
         $notInterested = new NotInterested();
         $resource = new Resource();
         $notInterested->joinAdd($resource);
         $notInterested->userId = $user->id;
         $notInterested->find();
         if ($notInterested->N > 0) {
             $notInterestedFilter = " NOT(";
             $numRecords = 0;
             while ($notInterested->fetch()) {
                 $numRecords++;
                 if ($numRecords > 1) {
                     $notInterestedFilter .= " OR ";
                 }
                 if ($notInterested->source == 'VuFind') {
                     $notInterestedFilter .= "id:" . $notInterested->record_id;
                 } else {
                     $notInterestedFilter .= "id:econtentRecord" . $notInterested->record_id;
                 }
             }
             $notInterestedFilter .= ")";
             $filter[] = $notInterestedFilter;
         }
     }
     if ($this->scopingDisabled == false) {
         if (isset($searchLibrary)) {
             if ($searchLibrary->restrictSearchByLibrary && $searchLibrary->includeDigitalCollection) {
                 $filter[] = "(institution:\"{$searchLibrary->facetLabel}\" OR institution:\"Shared Digital Collection\" OR institution:\"Digital Collection\" OR institution:\"{$searchLibrary->facetLabel} Online\")";
             } else {
                 if ($searchLibrary->restrictSearchByLibrary) {
                     $filter[] = "institution:\"{$searchLibrary->facetLabel}\"";
                 } else {
                     if (!$searchLibrary->includeDigitalCollection) {
                         $filter[] = "!(institution:\"Digital Collection\" OR institution:\"{$searchLibrary->facetLabel} Online\")";
                     }
                 }
             }
         }
         if ($searchLocation != null) {
             if ($searchLocation->restrictSearchByLocation && $searchLocation->includeDigitalCollection) {
                 $filter[] = "(building:\"{$searchLocation->facetLabel}\" OR building:\"Shared Digital Collection\" OR building:\"Digital Collection\" OR building:\"{$searchLocation->facetLabel} Online\")";
             } else {
                 if ($searchLocation->restrictSearchByLocation) {
                     $filter[] = "(building:\"{$searchLocation->facetLabel}\")";
                 } else {
                     if (!$searchLocation->includeDigitalCollection) {
                         $filter[] = "!(building:\"Shared Digital Collection\" OR building:\"Digital Collection\" OR building:\"{$searchLibrary->facetLabel} Online\")";
                     }
                 }
             }
         }
         global $defaultCollection;
         if (isset($defaultCollection) && strlen($defaultCollection) > 0) {
             $filter[] = 'collection_group:"' . $defaultCollection . '"';
         }
         if ($this->searchSource == 'econtent') {
             $filter[] = 'recordtype:"econtentRecord"';
         }
     }
     return $filter;
 }