Anon user can't vote see #4200

skala
Julio Montoya 14 years ago
parent 4cae5300e0
commit 921688efc7
  1. 17
      main/inc/ajax/course.ajax.php
  2. 11
      main/inc/lib/course.lib.php
  3. 35
      main/inc/lib/display.lib.php
  4. 11
      main/template/default/layout/hot_courses.tpl

@ -12,12 +12,19 @@ $user_id = api_get_user_id();
switch ($action) {
case 'add_course_vote':
if (!api_is_anonymous()) {
$course_id = intval($_REQUEST['course_id']);
$star = intval($_REQUEST['star']);
$result = CourseManager::add_course_vote($user_id, $star, $course_id, 0);
echo $result;
$course_id = intval($_REQUEST['course_id']);
$star = intval($_REQUEST['star']);
if (!api_is_anonymous()) {
CourseManager::add_course_vote($user_id, $star, $course_id, 0);
}
$point_info = CourseManager::get_course_ranking($course_id, 0);
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$rating = Display::return_rating_system('star_'.$course_id, $ajax_url.'&course_id='.$course_id, $point_info, false);
echo $rating;
break;
default:
echo '';

@ -3617,16 +3617,7 @@ class CourseManager {
if (!empty($points_to_add)) {
self::update_course_ranking($course_id, $session_id, $url_id, $points_to_add, false, $add_user);
}
$point_info = CourseManager::get_course_ranking($course_id, 0);
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$rating = Display::return_rating_system('star_'.$course_id, $ajax_url.'&course_id='.$course_id, $point_info, false);
//return $action_done;
return $rating;
return $action_done;
}
/**

@ -1305,14 +1305,15 @@ class Display {
/**
* Return the five star HTML
*
* @param string id of the rating ul
* @param int percentage 0-100 %
* @param string url that will be added (for the jquery stuff)
* @param string show number of persons who voted for that item
* @param string id of the rating ul element
* @param string url that will be added (for jquery see hot_courses.tpl)
* @param string point info array see function CourseManager::get_course_ranking()
* @param bool add a div wrapper
* @todo use smarty
**/
public function return_rating_system($id, $url, $point_info = array(), $add_div_wrapper = true) {
$number_of_users_who_voted = isset($point_info['users_who_voted']) ? $point_info['users_who_voted'] : null;
$percentage = isset($point_info['point_average']) ? $point_info['point_average'] : 0;
if (!empty($percentage)) {
@ -1327,19 +1328,23 @@ class Display {
<li><a href="javascript:void(0)" rel="'.$url.'&star=3" title="'.get_lang('ThreeStarsOutOf5').'" class="three-stars">3</a></li>
<li><a href="javascript:void(0)" rel="'.$url.'&star=4" title="'.get_lang('FourStarsOutOf5').'" class="four-stars">4</a></li>
<li><a href="javascript:void(0)" rel="'.$url.'&star=5" title="'.get_lang('FiveStarsOutOf5').'" class="five-stars">5</a></li>
</ul>';
</ul>';
//if (!isset($number_of_users_who_voted)) {
$label = $number_of_users_who_voted == 1 ? get_lang('Vote') : get_lang('Votes');
$label_accesses = $accesses == 1 ? get_lang('Visite') : get_lang('Visites');
$label_average = $point_info['point_average_star'].' '.get_lang('Average');
$label_user = $point_info['user_vote'] ? get_lang('YouAlreadyVoted').' '.$point_info['user_vote'] : '';
$html .= Display::span($number_of_users_who_voted.' '.$label.' '.$accesses.' '.$label_accesses.' '.$label_average.' '.$label_user, array('id' => 'vote_label_'.$id));
$labels = array();
$labels[]= $number_of_users_who_voted == 1 ? $number_of_users_who_voted.' '.get_lang('Vote') : $number_of_users_who_voted.' '.get_lang('Votes');
$labels[]= $accesses == 1 ? $accesses.' '.get_lang('Visit') : $accesses.' '.get_lang('Visits');
$labels[]= $point_info['point_average_star'].' '.get_lang('Average');
$labels[]= $point_info['user_vote'] ? get_lang('YouAlreadyVoted').' '.$point_info['user_vote'] : '';
if (!$add_div_wrapper && api_is_anonymous()) {
$labels[]= get_lang('LoginToVote');
}
$html .= ' '.Display::span(' ', array('id' => 'vote_label2_'.$id));
//}
if ($add_div_wrapper) {
$html .= Display::span(implode(' ', $labels) , array('id' => 'vote_label_'.$id));
$html .= ' '.Display::span(' ', array('id' => 'vote_label2_'.$id));
if ($add_div_wrapper) {
$html = Display::div($html, array('id' => 'rating_wrapper_'.$id));
}
return $html;

@ -1,12 +1,10 @@
<script type="text/javascript">
$(document).ready( function() {
$('.star-rating li a').live('click', function(event) {
var id = $(this).parents('ul').attr('id');
$('#vote_label2_' + id).html("{'Loading'|get_lang}");
$('.star-rating li a').live('click', function(event) {
var id = $(this).parents('ul').attr('id');
$('#vote_label2_' + id).html("{'Loading'|get_lang}");
$.ajax({
url: $(this).attr('rel'),
success: function(data) {
@ -21,6 +19,7 @@ $(document).ready( function() {
}
})
});
});
</script>

Loading…
Cancel
Save