예제 #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
 /**
  * Get ratings as a tab separated file
  *
  * First column : ItemId
  * Second Column : Rating Average (should be between 0 and 5, decimals are accepted)
  * Third column : Total votes
  * It is VERY important that the frist column represents the "itemId"
  * has the same id that the one you are sending us with your catalog,
  * because that is what we use to link your products with its ratings
  */
 function getRatingInfo()
 {
     require_once ROOT_DIR . '/Drivers/marmot_inc/UserRating.php';
     $ratings = new UserRating();
     $ratings->query("SELECT record_id, AVG(rating) as averageRating, count(resource.id) as numRatings from user_rating INNER JOIN resource on resourceid = resource.id GROUP BY record_id");
     $tabbedData = '';
     while ($ratings->fetch()) {
         $tabbedData .= "{$ratings->record_id}\t{$ratings->averageRating}\t{$ratings->numRatings}\r\n";
     }
     //Get eContent Ratings as well
     require_once ROOT_DIR . '/sys/eContent/EContentRating.php';
     $eContentRatings = new EContentRating();
     $eContentRatings->query("SELECT recordId, AVG(rating)as averageRating, count(id) as numRatings FROM `econtent_rating` GROUP BY recordId");
     while ($eContentRatings->fetch()) {
         $tabbedData .= "econtentRecord{$eContentRatings->recordId}\t{$eContentRatings->averageRating}\t{$eContentRatings->numRatings}\r\n";
     }
     return $tabbedData;
 }
예제 #3
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;
 }
예제 #4
0
 function getRatingData($user = null)
 {
     global $configArray;
     if ($user == null) {
         global $user;
     }
     require_once ROOT_DIR . '/Drivers/marmot_inc/UserRating.php';
     //Set default rating data
     $ratingData = array('average' => 0, 'count' => 0, 'user' => 0);
     //Get rating data for the resource
     $sql = "SELECT AVG(rating) average, count(rating) count from user_rating inner join resource on user_rating.resourceid = resource.id where resource.record_id =  '{$this->record_id}'";
     $rating = new UserRating();
     $rating->query($sql);
     if ($rating->N > 0) {
         $rating->fetch();
         $ratingData['average'] = number_format($rating->average, 2);
         $ratingData['count'] = $rating->count;
     }
     //Get user rating
     if (isset($user) && $user != false) {
         $rating = new UserRating();
         $rating->userid = $user->id;
         $rating->resourceid = $this->id;
         $rating->find();
         if ($rating->N) {
             $rating->fetch();
             $ratingData['user'] = $rating->rating;
         }
     }
     return $ratingData;
 }