upgrade_main_savepoint($result, 2010021800);
}
- if ($result && $oldversion < 2010031602) {
+ if ($result && $oldversion < 2010031800) {
//drop the erroneously created ratings table
$table = new xmldb_table('ratings');
if ($dbman->table_exists($table)) {
//create the rating table (replaces module specific rating implementations)
$table = new xmldb_table('rating');
+ if ($dbman->table_exists($table)) {
+ $dbman->drop_table($table);
+ }
/// Adding fields to table rating
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$dbman->create_table($table);
}
- //migrate ratings out of the modules into the central rating table
+ //pull in the ratings from the modules into the central rating table
//migrate forumratings
//forum ratings only have a single time column so use it for both time created and modified
//migrate glossary_ratings
//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.id AS mid, g.scale
-FROM {glossary_ratings} r INNER JOIN {glossary_entries} ge ON ge.id=r.entryid
+ $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
+INNER JOIN {glossary_entries} ge ON ge.id=r.entryid
INNER JOIN {glossary} g ON g.id=ge.glossaryid';
$result = $result && upgrade_module_ratings($ratingssql,'glossary');
//migrate data_ratings
//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 INNER JOIN {data_records} re ON r.recordid=re.id
+FROM {data_ratings} r
+INNER JOIN {data_records} re ON r.recordid=re.id
INNER JOIN {data} d ON d.id=re.dataid';
$result = $result && upgrade_module_ratings($ratingssql,'data');
-
- //todo set permissions based on current value of glossary.assessed
//todo drop forum_ratings, data_ratings and glossary_ratings
- upgrade_main_savepoint($result, 2010031602);
+ upgrade_main_savepoint($result, 2010031800);
}
- //upgrade.php was out of step with install.xml for 16 hours. Its theoretically possible someone could
- //have done a fresh install during that time with version 2010031602 and wound up with a table called 'ratings'
- if ($result && $oldversion < 2010031700) {
- $table = new xmldb_table('ratings');
-
- if ( $dbman->table_exists($table) ) {
- $dbman->rename_table($table, 'rating');
- }
-
- upgrade_main_savepoint($result, 2010031700);
- }
-
-
return $result;
}
$strrate = get_string("rate", "rating");
$strratings = ''; //the string we'll return
- if($rating->settings->permissions[RATING_VIEW] || $rating->settings->permissions[RATING_VIEW_ALL]) {
+ if($rating->settings->permissions->canview || $rating->settings->permissions->canviewall) {
switch ($rating->settings->aggregationmethod) {
case RATING_AGGREGATE_AVERAGE :
$strratings .= get_string("aggregateavg", "forum");
$aggstr = "{$ratingstr} / $scalemax ({$rating->count}) ";
- if ($rating->settings->permissions[RATING_VIEW_ALL]) {
+ if ($rating->settings->permissions->canviewall) {
$link = new moodle_url("/rating/index.php?contextid={$rating->context->id}&itemid={$rating->itemid}&scaleid={$rating->scaleid}");
$action = new popup_action('click', $link, 'ratings', array('height' => 400, 'width' => 600));
$strratings .= $this->action_link($link, $aggstr, $action);
- } else if ($rating->settings->permissions[RATING_VIEW_ALL]) {
+ } else if ($rating->settings->permissions->canview) {
$strratings .= $aggstr;
}
}
//todo andrew alter the below if to deny guest users the ability to post ratings.
//Petr to define "guest"
$formstart = null;
- if($rating->settings->permissions[RATING_POST]) {
+ if($rating->settings->permissions->canrate) {
//dont use $rating->userid below as it will be null if the user hasnt already rated the item
$formstart = <<<END
<form id="postrating{$rating->itemid}" class="postratingform" method="post" action="rating/rate.php">
upgrade_mod_savepoint($result, 2009110800, 'glossary');
}
+ //todo andrew set rating permissions based on current value of glossary.assessed
+
return $result;
}
}
$PAGE->set_url($url);
-$permissions = rating::get_rating_permissions(context);
-if (!$permissions[RATING_VIEW]) {
+if ( !has_capability(RATING_VIEW,$context) ) {
print_error('noviewrate', 'rating');
}
-if (!$permissions[RATING_VIEW_ALL] and $USER->id != $item->userid) {
+if ( !has_capability(RATING_VIEW,$context) and $USER->id != $item->userid) {
print_error('noviewanyrate', 'rating');
}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-define('RATING_VIEW','view');
-define('RATING_VIEW_ALL','viewall');
-define('RATING_POST','post');
+define('RATING_VIEW','moodle/rating:view');
+define('RATING_VIEW_ALL','moodle/rating:viewall');
+define('RATING_RATE','moodle/rating:rate');
define('RATING_UNSET_RATING', -999);
*/
public $userid;
+ /**
+ * settings for this rating. Necessary to render the rating.
+ * @var stdclass
+ */
+ public $settings;
+
/**
* Constructor.
* @param context $context the current context object
$ratingsrecords = $DB->get_records_sql($sql, $params);
//now create the rating sub objects
- $permissions = rating::get_rating_permissions($context);
-
$scaleobj = new stdClass();
$scalemax = null;
$scalemax = $scaleid;
}
+ //should $settings and $settings->permissions be declared as proper classes?
$settings = new stdclass(); //settings that are common to all ratings objects in this context
$settings->scale = $scaleobj; //the scale to use now
- $settings->permissions = $permissions;
$settings->aggregationmethod = $aggregate;
$settings->returnurl = $returnurl;
+ $settings->permissions = new stdclass();
+ $settings->permissions->canview = has_capability(RATING_VIEW,$context);
+ $settings->permissions->canviewall = has_capability(RATING_VIEW_ALL,$context);
+ $settings->permissions->canrate = has_capability(RATING_RATE,$context);
+
$rating = null;
foreach($items as $item) {
$rating = null;
}
return $items;
}
-
- /**
- * Static method that retrieves the current user's permissions to do with ratings
- * @param context $contextid the current context
- * @return returns the array of permissions
- */
- public static function get_rating_permissions($context) {
- return array(RATING_VIEW=>has_capability('moodle/rating:view',$context), RATING_VIEW_ALL=>has_capability('moodle/rating:viewall',$context), RATING_POST=>has_capability('moodle/rating:rate',$context));
- }
} //end rating class definition
\ No newline at end of file
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);
-$permissions = rating::get_rating_permissions($context);
-if( !$permissions[RATING_POST] ) {
+if( !has_capability(RATING_RATE,$context) ) {
if( $returnurl ) { //if its a non-ajax request
echo $OUTPUT->header();
echo get_string('ratepermissiondenied', 'ratings');
$userid = $USER->id;
$PAGE->set_url('/lib/rate.php', array(
- 'contextid'=>$contextid,
- 'itemid'=>$itemid,
- 'scaleid'=>$scaleid,
- 'rating'=>$userrating,
- 'userid'=>$userid,
- 'returnurl'=>$returnurl,
+ 'contextid'=>$contextid
));
//todo how can we validate the forum post,glossary entry or whatever id?
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2010031700; // YYYYMMDD = date of the last version bump
+ $version = 2010031800; // YYYYMMDD = date of the last version bump
// XX = daily increments
$release = '2.0 dev (Build: 20100318)'; // Human-friendly version name