예제 #1
0
 function clearUserRating()
 {
     global $user;
     $source = $_REQUEST['source'];
     $recordId = $_REQUEST['recordId'];
     $result = array('result' => false);
     if ($source == 'VuFind') {
         require_once ROOT_DIR . '/Drivers/marmot_inc/UserRating.php';
         $resource = new Resource();
         $resource->record_id = $recordId;
         $resource->source = 'VuFind';
         if ($resource->find(true)) {
             $rating = new UserRating();
             $rating->userid = $user->id;
             $rating->resourceid = $resource->id;
             if ($rating->find(true)) {
                 if ($rating->delete()) {
                     $result = array('result' => true, 'message' => 'deleted user rating for resource ' . $rating->resourceid);
                 }
             }
         }
     } else {
         require_once ROOT_DIR . '/sys/eContent/EContentRating.php';
         $econtentRating = new EContentRating();
         $econtentRating->userId = $user->id;
         $econtentRating->recordId = $recordId;
         if ($econtentRating->find(true)) {
             if ($econtentRating->delete()) {
                 $result = array('result' => true);
             }
         }
     }
     return json_encode($result);
 }
예제 #2
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');
 }
예제 #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
 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;
 }
예제 #5
0
파일: API.php 프로젝트: Alex--Jin/homerapi
 /**
  * @api {post} /user/rating/reply Reply to rating
  * @apiVersion 1.0.0
  * @apiName ReplyRating
  * @apiGroup User
  * 
  * @apiHeader {String} Authorization Users unique access-key.
  * @apiParam {Number} rating_id Rating id
  * @apiParam {String} reply reply
  */
 function reply_rating()
 {
     $params = ['rating_id', 'reply'];
     $result = validateParam($params);
     if ($result === true) {
         $token = $_SERVER['Authorization'];
         $user = __get_user_from_token($token);
         extract($_POST);
         if ($user == NULL) {
             $result = array('success' => 'false', 'message' => 'Invalid token');
         } else {
             $rating = UserRating::find($rating_id);
             if ($rating == NULL) {
                 $result = array('success' => 'false', 'message' => 'No such rating to reply');
             } else {
                 if ($rating->user_to != $user->id) {
                     $result = array('success' => 'false', 'message' => "You can't reply to rating that is not yours");
                 } else {
                     $rating->reply = $reply;
                     $rating->save();
                     // foreach ($rating->userFrom->logins as $login){          // send notification to the user who rated this.
                     //     if ($login->push_type == 2){
                     //         if ($login->push_token == NULL || strlen($login->push_token) < 10){
                     //             continue;
                     //         }
                     //         $devices[] = $login->push_token;
                     //     }
                     // }
                     // if (count($devices) > 0){
                     if (count($rating->userFrom->logins) > 0) {
                         $message = $user->full_name . ' has just replied to your rating';
                         // sendGcmMessage($message, $devices);
                         // sendGCMMessage($devices, array(
                         //     'message' => $message,
                         //     'replier_id' => $user->id
                         //     ));
                         sendPush($rating->userForm->logins, array('message' => $message, 'replier_id' => $user->id));
                     }
                     $result = array('success' => 'true', 'message' => 'Successfully replied to the comment');
                 }
             }
         }
     }
     echo json_encode($result);
 }
예제 #6
0
 function hasRatings()
 {
     require_once ROOT_DIR . '/Drivers/marmot_inc/UserRating.php';
     $rating = new UserRating();
     $rating->userid = $this->id;
     $rating->find();
     if ($rating->N > 0) {
         return true;
     } else {
         return false;
     }
 }