Skip to content

Commit

Permalink
rating MDL-23328 made date restriction of ratings work correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Davis committed Jul 16, 2010
1 parent a74bea1 commit 55d95d9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
2 changes: 0 additions & 2 deletions course/moodleform_mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,8 @@ function data_preprocessing(&$default_values){
}

if (empty($default_values['assessed'])){
//$default_values['userating'] = 0;//this was used by glossary to check/uncheck a 'use ratings' checkbox
$default_values['ratingtime'] = 0;
} else {
//$default_values['userating'] = 1;
$default_values['ratingtime']=
($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ function render_rating(rating $rating) {
//check the item we're rating was created in the assessable time window
$inassessablewindow = true;
if ( $rating->settings->assesstimestart && $rating->settings->assesstimefinish ) {
if ($rating->itemtimecreated < $rating->settings->assesstimestart || $item->itemtimecreated > $rating->settings->assesstimefinish) {
if ($rating->itemtimecreated < $rating->settings->assesstimestart || $rating->itemtimecreated > $rating->settings->assesstimefinish) {
$inassessablewindow = false;
}
}
Expand Down
4 changes: 1 addition & 3 deletions mod/data/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ function definition() {
}

function data_preprocessing(&$default_values){
if (empty($default_values['scale'])){
$default_values['assessed'] = 0;
}
parent::data_preprocessing($default_values);
}

}
Expand Down
2 changes: 2 additions & 0 deletions mod/forum/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ function definition_after_data() {
}

function data_preprocessing(&$default_values) {
parent::data_preprocessing($default_values);

// Set up the completion checkboxes which aren't part of standard data.
// We also make the default value (if you turn on the checkbox) for those
// numbers to be 1, this will not apply unless checkbox is ticked.
Expand Down
1 change: 1 addition & 0 deletions mod/glossary/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function definition_after_data() {
}

function data_preprocessing(&$default_values){
parent::data_preprocessing($default_values);
}

}
Expand Down
25 changes: 15 additions & 10 deletions rating/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,8 @@ public function get_ratings($options) {
$rating->aggregate = $rec->aggrrating; //unset($rec->aggrrating);
$rating->count = $rec->numratings; //unset($rec->numratings);
$rating->rating = $rec->usersrating; //unset($rec->usersrating);
if( !empty($item->created) ) {
$rating->itemtimecreated = $item->created;//the forum_posts table has created instead of timecreated
}
else if(!empty($item->timecreated)) {
$rating->itemtimecreated = $item->timecreated;
}
else {
$rating->itemtimecreated = null;
}
$rating->itemtimecreated = $this->get_item_time_created($item);

break;
}
}
Expand All @@ -402,7 +395,7 @@ public function get_ratings($options) {
$rating->itemid = $item->id;
$rating->userid = null;
$rating->scaleid = null;
$rating->itemtimecreated = null;
$rating->itemtimecreated = $this->get_item_time_created($item);
}

if( !empty($item->userid) ) {
Expand All @@ -428,6 +421,18 @@ public function get_ratings($options) {
return $options->items;
}

private function get_item_time_created($item) {
if( !empty($item->created) ) {
return $item->created;//the forum_posts table has created instead of timecreated
}
else if(!empty($item->timecreated)) {
return $item->timecreated;
}
else {
return null;
}
}

/**
* Returns an array of grades calculated by aggregating item ratings.
* @param object $options {
Expand Down

0 comments on commit 55d95d9

Please sign in to comment.