mirror of
https://github.com/moodle/moodle.git
synced 2025-04-25 18:35:14 +02:00
rating MDL-21657 changes based on Petr's feedback
This commit is contained in:
parent
75ba5fe41a
commit
67e4713ca7
lib
mod
rating
@ -395,4 +395,60 @@ function upgrade_cleanup_unwanted_block_contexts($contextidarray) {
|
||||
$outcome4 = $DB->delete_records_select('context', 'id IN ('.$blockcontextidsstring.')');
|
||||
|
||||
return ($outcome1 && $outcome2 && $outcome4 && $outcome4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts ratings from modules into the central rating table
|
||||
*
|
||||
* @param string $ratingssql sql to return the module's rating
|
||||
* @param string $modulename the name of the module
|
||||
* @return boolean success flag
|
||||
*/
|
||||
function upgrade_module_ratings($ratingssql, $modulename) {
|
||||
global $DB;
|
||||
$contextid = null;
|
||||
$contextarray = array();
|
||||
$result = true;
|
||||
$i=0;
|
||||
|
||||
$ratings = $DB->get_recordset_sql($ratingssql);
|
||||
|
||||
foreach ($ratings as $old_rating) {
|
||||
if($i++%500==0) {
|
||||
upgrade_set_timeout(60);//prevent a timeout
|
||||
}
|
||||
|
||||
//all posts within a given forum, glossary etc will have the same context id so store them in an array
|
||||
if( !array_key_exists($old_rating->mid, $contextarray) ) {
|
||||
$sql = "SELECT cxt.id
|
||||
FROM {context} cxt
|
||||
JOIN {course_modules} cm ON cm.id = cxt.instanceid
|
||||
JOIN {modules} m ON cm.module = m.id
|
||||
WHERE m.name = :modulename AND cm.instance = :moduleinstanceid AND cxt.contextlevel = :contextmodule";
|
||||
$params = array();
|
||||
$params['modulename'] = $modulename;
|
||||
$params['moduleinstanceid'] = $old_rating->mid;
|
||||
$params['contextmodule'] = CONTEXT_MODULE;
|
||||
$results = $DB->get_record_sql($sql, $params);
|
||||
$contextarray[$old_rating->mid] = $results->id;
|
||||
}
|
||||
$contextid = $contextarray[$old_rating->mid];
|
||||
|
||||
$rating = new stdclass();
|
||||
$rating->contextid = $contextid;
|
||||
$rating->scaleid = $old_rating->scale;
|
||||
$rating->itemid = $old_rating->itemid;
|
||||
$rating->rating = $old_rating->rating;
|
||||
$rating->userid = $old_rating->userid;
|
||||
$rating->timecreated = $old_rating->timecreated;
|
||||
$rating->timemodified = $old_rating->timemodified;
|
||||
|
||||
if( !$DB->insert_record('rating', $rating) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$ratings->close();
|
||||
|
||||
return true;
|
||||
}
|
@ -1508,54 +1508,3 @@ function admin_mnet_method_profile(Zend_Server_Reflection_Function_Abstract $fun
|
||||
}
|
||||
return $profile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts ratings from modules into the central rating table
|
||||
*
|
||||
* @param string $ratingssql sql to return the module's rating
|
||||
* @param string $modulename the name of the module
|
||||
* @return boolean success flag
|
||||
*/
|
||||
function upgrade_module_ratings($ratingssql, $modulename) {
|
||||
global $DB;
|
||||
$contextid = null;
|
||||
$contextarray = array();
|
||||
$result = true;
|
||||
$i=0;
|
||||
|
||||
$ratings = $DB->get_records_sql($ratingssql);
|
||||
|
||||
foreach ($ratings as $old_rating) {
|
||||
if($i++%500==0) {
|
||||
upgrade_set_timeout(60);//prevent a timeout
|
||||
}
|
||||
|
||||
//all posts within a given forum, glossary etc will have the same context id so store them in an array
|
||||
if( !array_key_exists($old_rating->mid, $contextarray) ) {
|
||||
$sql = 'select cxt.id from {course_modules} cm inner join {modules} m on cm.module=m.id
|
||||
inner join {context} cxt on cxt.instanceid=cm.id
|
||||
where m.name=:modulename and cm.instance=:moduleinstanceid and cxt.contextlevel='.CONTEXT_MODULE;
|
||||
$params = array();
|
||||
$params['moduleinstanceid'] = $old_rating->mid;
|
||||
$params['modulename'] = $modulename;
|
||||
$results = $DB->get_record_sql($sql, $params);
|
||||
$contextarray[$old_rating->mid] = $results->id;
|
||||
}
|
||||
$contextid = $contextarray[$old_rating->mid];
|
||||
|
||||
$rating = new stdclass;
|
||||
$rating->contextid = $contextid;
|
||||
$rating->scaleid = $old_rating->scale;
|
||||
$rating->itemid = $old_rating->itemid;
|
||||
$rating->rating = $old_rating->rating;
|
||||
$rating->userid = $old_rating->userid;
|
||||
$rating->timecreated = $old_rating->timecreated;
|
||||
$rating->timemodified = $old_rating->timemodified;
|
||||
|
||||
$result = $result && $DB->insert_record('rating', $rating);
|
||||
}
|
||||
|
||||
//$ratings->close();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
@ -255,6 +255,8 @@ function xmldb_data_upgrade($oldversion) {
|
||||
|
||||
if($result && $oldversion < 2010031800) {
|
||||
//migrate data_ratings to the central rating table
|
||||
require_once('../lib/db/upgradelib.php');
|
||||
|
||||
//data ratings didnt store time created and modified so Im using the times from the record the rating was attached to
|
||||
$ratingssql = 'SELECT r.id AS rid, r.recordid AS itemid, r.rating, r.userid, re.timecreated, re.timemodified, d.scale, d.id AS mid
|
||||
FROM {data_ratings} r
|
||||
|
@ -287,6 +287,8 @@ function xmldb_forum_upgrade($oldversion) {
|
||||
|
||||
if($result && $oldversion < 2010031800) {
|
||||
//migrate forumratings to the central rating table
|
||||
require_once('../lib/db/upgradelib.php');
|
||||
|
||||
//forum ratings only have a single time column so use it for both time created and modified
|
||||
$ratingssql = 'SELECT r.id AS rid, r.post AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified, f.scale, f.id AS mid
|
||||
FROM {forum_ratings} r
|
||||
|
@ -259,6 +259,8 @@ function xmldb_glossary_upgrade($oldversion) {
|
||||
|
||||
if($result && $oldversion < 2010031800) {
|
||||
//migrate glossary_ratings to the central rating table
|
||||
require_once('../lib/db/upgradelib.php');
|
||||
|
||||
//glossary ratings only have a single time column so use it for both time created and modified
|
||||
$ratingssql = 'SELECT r.id AS rid, r.entryid AS itemid, r.rating, r.userid, r.time AS timecreated, r.time AS timemodified, g.scale, g.id AS mid
|
||||
FROM {glossary_ratings} r
|
||||
|
@ -225,6 +225,8 @@ class rating_manager {
|
||||
list($itemidtest, $params) = $DB->get_in_or_equal(
|
||||
$itemids, SQL_PARAMS_NAMED, 'itemid0000');
|
||||
|
||||
//note: all the group bys arent really necessary but PostgreSQL complains
|
||||
//about selecting a mixture of grouped and non-grouped columns
|
||||
$sql = "SELECT r.itemid, ur.id, ur.userid, ur.scaleid,
|
||||
$aggregatestr(r.rating) AS aggrrating,
|
||||
COUNT(r.rating) AS numratings,
|
||||
@ -236,7 +238,7 @@ class rating_manager {
|
||||
WHERE
|
||||
r.contextid = :contextid AND
|
||||
r.itemid $itemidtest
|
||||
GROUP BY r.itemid, ur.rating
|
||||
GROUP BY r.itemid, ur.rating, ur.id, ur.userid, ur.scaleid
|
||||
ORDER BY r.itemid";
|
||||
|
||||
$params['userid'] = $options->userid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user