예제 #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
 /**
  * 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;
 }
 public function getUserratings($rating, $email, $terminal_id, $action)
 {
     $date = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     $business_id = Business::getBusinessIdByTerminalId($terminal_id);
     $user = User::searchByEmail($email);
     $user_id = $user["user_id"];
     $terminal_user_id = Auth::id();
     UserRating::rateUser($date, $business_id, $rating, $user_id, $terminal_user_id, $action);
     return json_encode(['success' => 1]);
 }
예제 #5
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;
 }
예제 #6
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;
 }
 public static function count_rate_row_by_id($id)
 {
     return UserRating::where('id_user', '=', $id)->count();
 }
 public function give_rate_by_id_kom($id)
 {
     $data['id_user'] = Users::where('id', '=', Session::get('user_id'))->first()->id;
     $data['id_komunitas'] = $id;
     $data['rating'] = Input::get('rating');
     $jml = $this->rating->count_rate_row_by_id($data['id_user']);
     $jmlplus = $jml + 1;
     $total = $this->rating->count_all_rating_by_id($data['id_user']);
     $totalplus = $total + $data['rating'];
     $avgrate['avg_rate'] = $totalplus / $jmlplus;
     $jml2 = $this->komunitas->count_komunitas_rate_by_id($id);
     $jml2plus = $jml2 + 1;
     $ratetotal = $this->komunitas->count_totalrate_by_idkom($id);
     $totalrate = $ratetotal + $data['rating'];
     $ratekom['avg_rate'] = $totalrate / $jml2plus;
     UserRating::create($data);
     UserAvgRate::where('id_user', '=', Session::get('user_id'))->update($avgrate);
     Komunitas::where('id', '=', $id)->update($ratekom);
     $totrate = $this->rating->count_rate_row_by_id($data['id_user']);
     if ($totrate > 1) {
         $ratesim = $this->rating->get_all_user_rate($data['id_user'], $id);
         //$ratesim = $this->komunitas->get_komunitas_rated_except($id);
         foreach ($ratesim as $rated) {
             $similar['id_kom1'] = $id;
             $similar['id_kom2'] = $rated->id_komunitas;
             //$similar['id_kom2'] = $rated->id;
             $user_avg = $this->average->get_average_rate($data['id_user']);
             $rate1 = $this->rating->get_rating_only($data['id_user'], $similar['id_kom1']);
             $rate2 = $this->rating->get_rating_only($data['id_user'], $similar['id_kom2']);
             $similar['similarity'] = ($rate1 - $user_avg) * ($rate2 - $user_avg) / (sqrt(pow($rate1 - $user_avg, 2)) * sqrt(pow($rate2 - $user_avg, 2)));
             $check = $this->komsimilarity->is_compared($similar['id_kom1'], $similar['id_kom2']);
             if ($check == TRUE) {
                 KomSimilarity::where('id_kom1', '=', $id)->where('id_kom2', '=', $rated->id_komunitas)->update($similar);
             } else {
                 KomSimilarity::create($similar);
             }
         }
         // $allkom = Komunitas::get();
         $allkom = $this->komunitas->get_komunitas_rated_except($id);
         foreach ($allkom as $kom) {
             $israted = $this->rating->is_rated($data['id_user'], $kom->id);
             if ($israted == FALSE) {
                 $ceksimilarity = $this->komsimilarity->get_similarity($kom->id);
                 foreach ($ceksimilarity as $mirip) {
                     // $ratekomp = $this->rating->get_rating_only($data['id_user'], $mirip->id_kom2);
                     $ratekomp = $this->rating->get_rating($mirip->id_kom2);
                     $simvalue = $this->komsimilarity->get_similarity_value($mirip->id_kom1, $mirip->id_kom2);
                     $predict['id_user'] = $data['id_user'];
                     $predict['id_komunitas'] = $mirip->id_kom2;
                     $predict['rate_predict'] = $ratekomp * $simvalue / ABS($simvalue);
                     $ceki = $this->predict->is_predicted($data['id_user'], $mirip->id_kom2);
                     if ($ceki == TRUE) {
                         KomRatePredict::where('id_user', '=', $data['id_user'])->where('id_komunitas', '=', $mirip->id_kom2)->update($predict);
                     } else {
                         KomRatePredict::create($predict);
                     }
                 }
             }
         }
     }
     // // $allkom = Komunitas::get();
     // $allkom = $this->komunitas->get_komunitas_rated_except($id);
     // foreach ($allkom as $kom) {
     // 	$israted  = $this->rating->is_rated($data['id_user'], $kom->id);
     // 	if ($israted == FALSE) {
     // 		$ceksimilarity = $this->komsimilarity->get_similarity($kom->id);
     // 		foreach ($ceksimilarity as $mirip) {
     // 			$cekrating  = $this->rating->is_rated($data['id_user'], $mirip->id_kom2);
     // 			if ($cekrating == FALSE) {
     // 				$ratekomp = $this->rating->get_rating_only($data['id_user'], $mirip->id_kom1);
     // 				$simvalue = $this->komsimilarity->get_similarity_value($mirip->id_kom1, $mirip->id_kom2);
     // 				$predict['id_user'] = $data['id_user'];
     // 				$predict['id_komunitas'] = $mirip->id_kom2;
     // 				$predict['rate_predict'] = (($ratekomp * $simvalue)/(ABS($simvalue)));
     // 				$ceki = $this->predict->is_predicted($data['id_user'], $mirip->id_kom2);
     // 				if ($ceki == TRUE) {
     // 					KomRatePredict::update($predict);
     // 				} else {
     // 					KomRatePredict::create($predict);
     // 				}
     // 			}
     // 		}
     // 	}
     // }
     $slug = Komunitas::where('id', '=', $id)->first()->slug;
     return Redirect::to('/komunitas/' . $slug);
 }
예제 #9
0
function __rate_user($fromid, $toid, $score, $comment, $reason)
{
    $rating = new UserRating();
    $rating->user_from = $fromid;
    $rating->user_to = $toid;
    $rating->score = $score;
    $rating->comment = $comment;
    $rating->reason = $reason;
    $rating->save();
}
예제 #10
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);
 }
 /**
  * @author Ruffy Heredia
  * @desc
  * @param $transaction_number
  * @param int $timestamp
  * @return mixed
  */
 public function getTransactionRatingInfo($transaction_number, $timestamp = 0)
 {
     $current_date = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
     try {
         $rating = UserRating::getUserRating($transaction_number);
         $rating->is_rated = '1';
         $rating->can_be_rated = '0';
     } catch (Exception $e) {
         $rating = null;
     }
     return Response::json($rating ? $rating : ['can_be_rated' => $current_date == $timestamp ? '1' : '0'], 200, array(), JSON_PRETTY_PRINT);
 }
예제 #12
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;
     }
 }