Fixing the refreshing issue when voting for courses + changing points to total_score in the ranking table see #4200

skala
Julio Montoya 14 years ago
parent 70f6889440
commit 80817a2eb9
  1. 31
      main/inc/lib/course.lib.php
  2. 2
      main/inc/lib/database.constants.inc.php
  3. 5
      main/inc/lib/display.lib.php
  4. 4
      main/install/db_main.sql
  5. 9
      main/template/default/auth/courses_categories.php
  6. 13
      main/template/default/layout/hot_courses.tpl

@ -3472,7 +3472,7 @@ class CourseManager {
'creation_date' => $now,
);
$result = Database::select('c_id, accesses, points, users', $table_course_ranking, array('where' => array('c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
$result = Database::select('c_id, accesses, total_score, users', $table_course_ranking, array('where' => array('c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
$point_average_in_percentage = 0;
$point_average_in_star = 0;
@ -3480,8 +3480,8 @@ class CourseManager {
if (!empty($result['users'])) {
$users_who_voted = $result['users'];
$point_average_in_percentage = round($result['points']/$result['users'] * 100 / 5, 2);
$point_average_in_star = round($result['points']/$result['users'], 1);
$point_average_in_percentage = round($result['total_score']/$result['users'] * 100 / 5, 2);
$point_average_in_star = round($result['total_score']/$result['users'], 1);
}
$result['user_vote'] = false;
@ -3522,7 +3522,7 @@ class CourseManager {
'creation_date' => $now,
);
$result = Database::select('id, accesses, points, users', $table_course_ranking, array('where' => array('c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
$result = Database::select('id, accesses, total_score, users', $table_course_ranking, array('where' => array('c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
// Problem here every thime we load the courses/XXXX/index.php course home page we update the access
@ -3532,7 +3532,7 @@ class CourseManager {
}
//The votes and users are empty
if (isset($points_to_add) && !empty($points_to_add)) {
$params['points'] = intval($points_to_add);
$params['total_score'] = intval($points_to_add);
}
if ($add_user) {
$params['users'] = 1;
@ -3545,7 +3545,7 @@ class CourseManager {
$my_params['accesses'] = intval($result['accesses']) + 1;
}
if (isset($points_to_add) && !empty($points_to_add)) {
$my_params['points'] = $result['points'] + $points_to_add;
$my_params['total_score'] = $result['total_score'] + $points_to_add;
}
if ($add_user) {
$my_params['users'] = $result['users'] + 1;
@ -3567,6 +3567,7 @@ class CourseManager {
* @param int course id
* @param int session id
* @param int url id
* @return mixed 'added', 'updated' or 'nothing'
*
*/
@ -3586,8 +3587,6 @@ class CourseManager {
$url_id = empty($url_id) ? api_get_current_access_url_id() : intval($url_id);
$vote = intval($vote);
$params = array(
'user_id' => intval($user_id),
'c_id' => $course_id,
@ -3596,7 +3595,7 @@ class CourseManager {
'vote' => $vote
);
$action_done = false;
$action_done = 'nothing';
$result = Database::select('id, vote', $table_user_course_vote, array('where' => array('user_id = ? AND c_id = ? AND session_id = ? AND url_id = ?' => $params)), 'first');
@ -3618,7 +3617,15 @@ class CourseManager {
if (!empty($points_to_add)) {
self::update_course_ranking($course_id, $session_id, $url_id, $points_to_add, false, $add_user);
}
return $action_done;
$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;
}
@ -3679,7 +3686,7 @@ class CourseManager {
$ajax_url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=add_course_vote';
$point_info = self::get_course_ranking($course_info['real_id'], 0);
$my_course['extra_info']['rating_html'] = Display::return_rating_system($course_info['code'].'_rating', $ajax_url.'&course_id='.$course_info['real_id'], $point_info);
$my_course['extra_info']['rating_html'] = Display::return_rating_system('star_'.$course_info['real_id'], $ajax_url.'&course_id='.$course_info['real_id'], $point_info);
}
}
return $courses;
@ -3689,7 +3696,7 @@ class CourseManager {
$table_course_ranking = Database::get_main_table(TABLE_STATISTIC_TRACK_COURSE_RANKING);
$params['url_id'] = api_get_current_access_url_id();
$result = Database::select('c_id, accesses, points, users', $table_course_ranking, array('where' => array('url_id = ?' => $params), 'order' => array('accesses DESC'), 'limit' => $limit), 'all', true);
$result = Database::select('c_id, accesses, total_score, users', $table_course_ranking, array('where' => array('url_id = ?' => $params), 'order' => array('accesses DESC'), 'limit' => $limit), 'all', true);
return $result;
}
} //end class CourseManager

@ -140,7 +140,7 @@ define('TABLE_STATISTIC_TRACK_C_REFERERS', 'track_c_referers');
//Course catalog stats see #4191
define('TABLE_STATISTIC_TRACK_COURSE_RANKING', 'track_course_ranking');
define('TABLE_MAIN_USER_REL_COURSE_VOTE', 'user_course_vote');
define('TABLE_MAIN_USER_REL_COURSE_VOTE', 'user_rel_course_vote');
// SCORM database tables

@ -1281,7 +1281,7 @@ class Display {
* @param string show number of persons who voted for that item
* @todo use smarty
**/
public function return_rating_system($id, $url, $point_info = array()) {
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;
@ -1309,6 +1309,9 @@ class Display {
$html .= ' '.Display::span(' ', array('id' => 'vote_label2_'.$id));
//}
if ($add_div_wrapper) {
$html = Display::div($html, array('id' => 'rating_wrapper_'.$id));
}
return $html;
}

@ -2824,7 +2824,7 @@ CREATE TABLE track_course_ranking (
session_id int unsigned not null default 0,
url_id int unsigned not null default 0,
accesses int unsigned not null default 0,
points int unsigned not null default 0,
total_score int unsigned not null default 0,
users int unsigned not null default 0,
creation_date datetime not null
);
@ -2834,7 +2834,7 @@ ALTER TABLE track_course_ranking ADD INDEX idx_tcc_sid (session_id);
ALTER TABLE track_course_ranking ADD INDEX idx_tcc_urlid (url_id);
ALTER TABLE track_course_ranking ADD INDEX idx_tcc_creation_date (creation_date);
CREATE TABLE user_course_vote(
CREATE TABLE user_rel_course_vote(
id int unsigned not null AUTO_INCREMENT PRIMARY KEY,
c_id int unsigned not null,
user_id int unsigned not null,

@ -23,7 +23,7 @@ $stok = Security::get_token();
?>
<script type="text/javascript">
$(document).ready( function() {
$('.star-rating li a').click(function(){
$('.star-rating li a').live('click', function(event) {
var id = $(this).parents('ul').attr('id');
@ -32,12 +32,13 @@ $stok = Security::get_token();
$.ajax({
url: $(this).attr('rel'),
success: function(data) {
$("#rating_wrapper_"+id).html(data);
if(data == 'added') {
//$('#vote_label_' + id).html('Saved');
$('#vote_label2_' + id).html("<?php echo get_lang('Saved')?>");
//$('#vote_label2_' + id).html("<?php echo get_lang('Saved')?>");
}
if(data == 'updated') {
$('#vote_label2_' + id).html("<?php echo get_lang('Saved')?>");
//$('#vote_label2_' + id).html("<?php echo get_lang('Saved')?>");
}
}
})
@ -155,7 +156,7 @@ $stok = Security::get_token();
$course_medium_image = api_get_path(WEB_IMG_PATH).'without_picture.png'; // without picture
}
$rating = Display::return_rating_system($course['code'].'_rating', $ajax_url.'&course_id='.$course['real_id'], $course['point_info']);
$rating = Display::return_rating_system('star_'.$course['real_id'], $ajax_url.'&course_id='.$course['real_id'], $course['point_info']);
//<div class="course-block-main-item"><div class="left">'.get_lang('Teacher').'</div><div class="course-block-teacher right">'.$tutor_name.'</div></div>
//<div class="course-block-main-item"><div class="left">'.get_lang('CreationDate').'</div><div class="course-block-date">'.api_format_date($creation_date,DATE_FORMAT_SHORT).'</div></div>

@ -1,19 +1,22 @@
<script type="text/javascript">
$(document).ready( function() {
$('.star-rating li a').click(function(){
var id = $(this).parents('ul').attr('id');
$('.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) {
$("#rating_wrapper_"+id).html(data);
if(data == 'added') {
$('#vote_label2_' + id).html("{'Saved'|get_lang}");
//$('#vote_label2_' + id).html("{'Saved'|get_lang}");
}
if(data == 'updated') {
$('#vote_label2_' + id).html("{'Saved'|get_lang}");
//$('#vote_label2_' + id).html("{'Saved'|get_lang}");
}
}
})

Loading…
Cancel
Save