示例#1
0
require_once 'include/course_settings.php';

$is_link = false;

if ($_GET['rtype'] == 'blogpost') {
	$setting_id = SETTING_BLOG_RATING_ENABLE;
} elseif ($_GET['rtype'] == 'course') {
    $setting_id = SETTING_COURSE_RATING_ENABLE;
} elseif ($_GET['rtype'] == 'forum_post') {
    $setting_id = SETTING_FORUM_RATING_ENABLE;
} elseif ($_GET['rtype'] == 'link') {
    $is_link = true; //there is no rating setting for social bookmarks, rating is always enabled
}

if ($is_link || setting_get($setting_id, $course_id) == 1) {
    if (Rating::permRate($is_editor, $uid, $course_id, $_GET['rtype'])) {
        $widget = $_GET['widget'];
        $rtype = $_GET['rtype'];
        $rid = intval($_GET['rid']);
        $value = intval($_GET['value']);
        
        //response array
        $response = array();
        
        $rating = new Rating($widget, $rtype, $rid);
        $had_rated = $rating->userHasRated($uid);
        $action = $rating->castRating($value, $uid);
        
        if ($widget == 'up_down') {
            $up_value = $rating->getUpRating();
            $down_value = $rating->getDownRating();
示例#2
0
 public function put($isEditor, $uid, $courseId)
 {
     global $langUserHasRated, $langRatingVote, $langRatingVotes, $langRatingAverage, $langRateIt, $urlServer;
     $this->rating_add_js();
     if ($this->widget == 'up_down') {
         $out = "<div class=\"rating\">";
         $onclick_up = $onclick_down = "";
         //disable icons when user hasn't permission to vote
         if (Rating::permRate($isEditor, $uid, $courseId, $this->rtype)) {
             $onclick_up = "onclick=\"Rate('" . $this->widget . "'," . $this->rid . ",'" . $this->rtype . "',1,'" . $urlServer . "modules/rating/rate.php')\"";
             $onclick_down = "onclick=\"Rate('" . $this->widget . "'," . $this->rid . ",'" . $this->rtype . "',-1,'" . $urlServer . "modules/rating/rate.php')\"";
         }
         $has_rated = $this->userHasRated($uid);
         if ($has_rated !== false) {
             $value = $has_rated;
             $has_rated = true;
             if ($value == 1) {
                 $img_up = 'thumbs_up_active.png';
                 $img_down = 'thumbs_down_inactive.png';
             } elseif ($value == -1) {
                 $img_up = 'thumbs_up_inactive.png';
                 $img_down = 'thumbs_down_active.png';
             }
         } else {
             $has_rated = false;
             $img_up = 'thumbs_up_inactive.png';
             $img_down = 'thumbs_down_inactive.png';
         }
         $out .= "<img id=\"rate_" . $this->rid . "_img_up\" src=\"" . $urlServer . "modules/rating/" . $img_up . "\" " . $onclick_up . "/>&nbsp;";
         $out .= "<span id=\"rate_" . $this->rid . "_up\">" . $this->getUpRating() . "</span>&nbsp;&nbsp;";
         $out .= "<img id=\"rate_" . $this->rid . "_img_down\" src=\"" . $urlServer . "modules/rating/" . $img_down . "\" " . $onclick_down . "/>&nbsp;";
         $out .= "<span id=\"rate_" . $this->rid . "_down\">" . $this->getDownRating() . "</span>";
         $out .= "<div class=\"smaller\" id=\"rate_msg_" . $this->rid . "\">";
         if ($has_rated) {
             $out .= $langUserHasRated;
         }
         $out .= "</div>";
         $out .= "</div>";
     } elseif ($this->widget == 'thumbs_up') {
         $out = "<div class=\"rating\">";
         $onclick_up = "";
         //disable icons when user hasn't permission to vote
         if (Rating::permRate($isEditor, $uid, $courseId, $this->rtype)) {
             $onclick_up = "onclick=\"Rate('" . $this->widget . "'," . $this->rid . ",'" . $this->rtype . "',1,'" . $urlServer . "modules/rating/rate.php')\"";
         }
         $has_rated = $this->userHasRated($uid);
         if ($has_rated !== false) {
             $has_rated = true;
             $img_up = 'thumbs_up_active.png';
         } else {
             $has_rated = false;
             $img_up = 'thumbs_up_inactive.png';
         }
         $out .= "<img id=\"rate_" . $this->rid . "_img\" src=\"" . $urlServer . "modules/rating/" . $img_up . "\" " . $onclick_up . "/>&nbsp;";
         $out .= "<span id=\"rate_" . $this->rid . "_up\">" . $this->getThumbsUpRating() . "</span>";
         $out .= "<div class=\"smaller\" id=\"rate_msg_" . $this->rid . "\">";
         if ($has_rated) {
             $out .= $langUserHasRated;
         }
         $out .= "</div>";
         $out .= "</div>";
     } elseif ($this->widget == 'fivestar') {
         $out = "<div class=\"rating\">";
         $num_ratings = $this->getRatingsNum();
         if (Rating::permRate($isEditor, $uid, $courseId, $this->rtype)) {
             $avg = $this->getFivestarRating();
             $avg_datavalue = 'data-rateit-value="' . $avg . '" data-rateit-ispreset="true" data-rateit-readonly="true"';
             $out .= '<div class="rateit" id="rateit-avg-' . $this->rtype . '-' . $this->rid . '" ' . $avg_datavalue . '></div>';
             $out .= '<div id="rateit-info-' . $this->rtype . '-' . $this->rid . '">';
             if ($num_ratings['fivestar'] != 0) {
                 $out .= $langRatingAverage . $avg . ', ';
             }
             if ($num_ratings['fivestar'] == 1) {
                 $out .= $num_ratings['fivestar'] . $langRatingVote . '</div>';
             } else {
                 $out .= $num_ratings['fivestar'] . $langRatingVotes . '</div>';
             }
             $out .= '<div id="rateitwrapdiv-' . $this->rtype . '-' . $this->rid . '" ><a href="javascript:void(0)">' . $langRateIt . '</a></div>';
             $userRating = "";
             if ($this->userHasRated($uid) !== false) {
                 $userRating = 'data-rateit-value="' . $this->getFivestarUserRating($uid) . '"';
             }
             $out .= '<div class="hideratewidget" id="rateitwidgetdiv-' . $this->rtype . '-' . $this->rid . '">';
             $out .= '<div class="rateit" id="rateit-' . $this->rtype . '-' . $this->rid . '" ' . $userRating . '></div>';
             $out .= '</div>';
             $out .= '<script type="text/javascript">';
             $out .= ' $("#rateitwrapdiv-' . $this->rtype . '-' . $this->rid . '").click(function() {$("#rateitwidgetdiv-' . $this->rtype . '-' . $this->rid . '").toggle()});';
             $out .= ' $("#rateit-' . $this->rtype . '-' . $this->rid . '").bind(\'rated\', function (event, value) { 
                 $.ajax({
                      url: \'' . $urlServer . 'modules/rating/rate.php\',
                      data: { rtype: "' . $this->rtype . '", rid: ' . $this->rid . ', widget: "' . $this->widget . '",value: value }, 
                      type: \'GET\',
                      success: function (data) {
                          response = JSON.parse(data);
                          $("#rateit-info-' . $this->rtype . '-' . $this->rid . '").text(response[0]);
                          $("#rateit-avg-' . $this->rtype . '-' . $this->rid . '").rateit("value",response[1]);
                      },
                  });
             });';
             $out .= ' $("#rateit-' . $this->rtype . '-' . $this->rid . '").bind(\'reset\', function (event, value) {
                 $.ajax({
                      url: \'' . $urlServer . 'modules/rating/rate.php\',
                      data: { rtype: "' . $this->rtype . '", rid: ' . $this->rid . ', widget: "' . $this->widget . '",value: 0 }, 
                      type: \'GET\',
                      success: function (data) {
                          response = JSON.parse(data);
                          $("#rateit-info-' . $this->rtype . '-' . $this->rid . '").text(response[0]);
                          $("#rateit-avg-' . $this->rtype . '-' . $this->rid . '").rateit("value",response[1]);
                      },
                  });
             });';
             $out .= '</script>';
         } else {
             $avg_datavalue = "";
             if ($num_ratings['fivestar'] != 0) {
                 $avg = $this->getFivestarRating();
                 $avg_datavalue = 'data-rateit-value="' . $avg . '"';
             }
             $out .= '<div class="rateit" ' . $avg_datavalue . ' data-rateit-ispreset="true" data-rateit-readonly="true"></div>';
             $out .= '<div id="rateit-info-' . $this->rtype . '-' . $this->rid . '">';
             if ($num_ratings['fivestar'] != 0) {
                 $out .= $langRatingAverage . $avg . ', ';
             }
             if ($num_ratings['fivestar'] == 1) {
                 $out .= $num_ratings['fivestar'] . $langRatingVote . '</div>';
             } else {
                 $out .= $num_ratings['fivestar'] . $langRatingVotes . '</div>';
             }
         }
         $out .= "</div>";
     }
     return $out;
 }