From: willcast Date: Fri, 21 Nov 2003 18:42:38 +0000 (+0000) Subject: - Grading enabled.... finally. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=63dd5fb2817bc1c472547cd023dcf5500789014b;p=moodle.git - Grading enabled.... finally. --- diff --git a/lang/en/glossary.php b/lang/en/glossary.php index 772dd5966b..d31d5acbb0 100644 --- a/lang/en/glossary.php +++ b/lang/en/glossary.php @@ -5,11 +5,12 @@ $string['addcomment'] = 'Add comment'; $string['addentry'] = 'Add a new entry'; $string['addingcomment'] = 'Add a comment'; -$string['aliases'] = 'Alias(es)'; +$string['aliases'] = 'Keyword(s)'; $string['allcategories'] = 'All Categories'; $string['allentries'] = 'ALL'; $string['allowcomments'] = 'Allow comments on entries'; $string['allowduplicatedentries'] = 'Duplicated entries allowed'; +$string['allowratings'] = 'Allow entries to be rated?'; $string['answer'] = 'Answer'; $string['approve'] = 'Approve'; $string['areyousuredelete'] = 'Are you sure you want to delete this entry?'; @@ -91,6 +92,7 @@ $string['exportedentry'] = 'Exported entry'; $string['exportedfile'] = 'Exported file'; $string['exportentries'] = 'Export entries'; $string['exportglossary'] = 'Export glossary'; +$string['exportentries'] = 'Export entries'; $string['exporttomainglossary'] = 'Export to main glossary'; $string['filetoimport'] = 'File to import'; $string['fillfields'] = 'Concept and definition are mandatory fields.'; @@ -121,10 +123,20 @@ $string['numberofentries'] = 'Number of entries'; $string['onebyline'] = '(one by line)'; $string['printerfriendly'] = 'Printer-friendly version'; $string['question'] = 'Question'; +$string['rate'] = 'Rate'; +$string['rating'] = 'Rating'; +$string['ratingeveryone'] = 'Everyone can rate entries'; +$string['ratingno'] = 'No ratings'; +$string['ratingonlyteachers'] = 'Only $a can rate entries'; +$string['ratings'] = 'Ratings'; +$string['ratingssaved'] = 'Ratings saved'; +$string['ratingsuse'] = 'Use ratings'; +$string['ratingtime'] = 'Restrict ratings to entries with dates in this range:'; $string['rejectedentries'] = 'Rejected entries'; $string['rejectionrpt'] = 'Rejection Report'; $string['searchindefinition'] = 'Search full text'; $string['secondaryglossary'] = 'Secondary glossary'; +$string['sendinratings'] = 'Send in my latest ratings'; $string['showall'] = 'Show \'ALL\' link'; $string['showalphabet'] = 'Show alphabet'; $string['showspecial'] = 'Show \'Special\' link'; diff --git a/mod/glossary/TODO.txt b/mod/glossary/TODO.txt index e05b3d7f18..874b90ebb9 100644 --- a/mod/glossary/TODO.txt +++ b/mod/glossary/TODO.txt @@ -1,14 +1,5 @@ Things that are in the inkpot yet: ================================== - - -- Adding a way to specify default values for display formats: - * Default view - * Default Order - * Show (or do not) the group breaks. - * Default view for automatic links, entry view, etc. - * What else? Post in http://moodle.org/mod/forum/view.php?id=742 - - Allow grading of entries * Evaluation * Self-evaluation? @@ -16,7 +7,9 @@ Things that are in the inkpot yet: ********* IN BETA RIGHT NOW ********* -- Allow to export/import entries (in beta now) -- Add Alias to concepts in order to use dynalinks on them. (in beta now) -- Allow to set default values for glossaries and entries settings (done) -- Add printer friendly version of glossaries (in beta) +- Adding a way to specify default values for display formats: + * Default view + * Default Order + * Show (or do not) the group breaks. + * Default view for automatic links, entry view, etc. + * What else? Post in http://moodle.org/mod/forum/view.php?id=742 diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index b24cf40e04..1285f9b3e8 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -58,6 +58,10 @@ fwrite ($bf,full_tag("ENTBYPAGE",4,false,$glossary->entbypage)); fwrite ($bf,full_tag("TIMECREATED",4,false,$glossary->timecreated)); fwrite ($bf,full_tag("TIMEMODIFIED",4,false,$glossary->timemodified)); + fwrite ($bf,full_tag("ASSESSED",4,false,$glossary->assessed)); + fwrite ($bf,full_tag("ASSESSTIMESTART",4,false,$glossary->assesstimestart)); + fwrite ($bf,full_tag("ASSESSTIMEFINISH",4,false,$glossary->assesstimefinish)); + fwrite ($bf,full_tag("SCALE",4,false,$glossary->scale)); backup_glossary_entries($bf,$preferences,$glossary->id, $preferences->mods["glossary"]->userinfo); diff --git a/mod/glossary/db/mysql.php b/mod/glossary/db/mysql.php index 130941f6f4..f2ea58974a 100644 --- a/mod/glossary/db/mysql.php +++ b/mod/glossary/db/mysql.php @@ -214,12 +214,31 @@ function glossary_upgrade($oldversion) { (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible) VALUES (5,5,'letter','ALL','CREATION','asc',1,1)"); // Entry list - execute_sql(" INSERT INTO {$CFG->prefix}glossary_displayformats + execute_sql("INSERT INTO {$CFG->prefix}glossary_displayformats (fid, relatedview, defaultmode, defaulthook, sortkey, sortorder, showgroup, visible) VALUES (6,0,'letter','ALL','CREATION','asc',1,1)"); } - return true; + + if ($oldversion < 2003112100) { + table_column("glossary", "", "assessed", "integer", "10", "unsigned", "0"); + table_column("glossary", "", "assesstimestart", "integer", "10", "unsigned", "0", "", "assessed"); + table_column("glossary", "", "assesstimefinish", "integer", "10", "unsigned", "0", "", "assesstimestart"); + + execute_sql("CREATE TABLE {$CFG->prefix}glossary_ratings ( + `id` int(10) unsigned NOT NULL auto_increment, + `userid` int(10) unsigned NOT NULL default '0', + `entryid` int(10) unsigned NOT NULL default '0', + `time` int(10) unsigned NOT NULL default '0', + `rating` tinyint(4) NOT NULL default '0', + PRIMARY KEY (`id`) + ) COMMENT='Contains user ratings for entries'"); + } + + if ($oldversion < 2003112101) { + table_column("glossary", "", "scale", "integer", "10", "signed", "0", "", "assesstimefinish"); + } + return true; } ?> diff --git a/mod/glossary/db/mysql.sql b/mod/glossary/db/mysql.sql index 16f8c17184..cf11269917 100644 --- a/mod/glossary/db/mysql.sql +++ b/mod/glossary/db/mysql.sql @@ -25,6 +25,10 @@ CREATE TABLE prefix_glossary ( defaultapproval tinyint(2) unsigned NOT NULL default '1', globalglossary tinyint(2) unsigned NOT NULL default '0', entbypage tinyint(3) unsigned NOT NULL default '10', + assessed int(10) unsigned NOT NULL default '0', + assesstimestart int(10) unsigned NOT NULL default '0', + assesstimefinish int(10) unsigned NOT NULL default '0', + scale int(10) NOT NULL default '0', timecreated int(10) unsigned NOT NULL default '0', timemodified int(10) unsigned NOT NULL default '0', PRIMARY KEY (id) @@ -115,6 +119,20 @@ CREATE TABLE prefix_glossary_displayformats ( PRIMARY KEY (id) ) TYPE=MyISAM COMMENT='Setting of the display formats'; +# +# Table structure for table `forum_ratings` +# + +CREATE TABLE prefix_glossary_ratings ( + id int(10) unsigned NOT NULL auto_increment, + userid int(10) unsigned NOT NULL default '0', + entryid int(10) unsigned NOT NULL default '0', + time int(10) unsigned NOT NULL default '0', + rating tinyint(4) NOT NULL default '0', + PRIMARY KEY (id) +) COMMENT='Contains user ratings for entries'; +# -------------------------------------------------------- + # # Dumping data for table `log_display` # diff --git a/mod/glossary/formats/2.php b/mod/glossary/formats/2.php index 884ad2b2e9..9fe1394314 100644 --- a/mod/glossary/formats/2.php +++ b/mod/glossary/formats/2.php @@ -1,6 +1,6 @@ cellheading2; @@ -12,6 +12,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode=" echo "\n"; echo "\n"; + $return = false; if ($entry) { print_user_picture($user->id, $course->id, $user->picture); @@ -36,6 +37,8 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode=" glossary_print_entry_definition($entry); glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons); + echo ' '; + $return = glossary_print_entry_ratings($course, $entry, $ratings); } else { echo "
"; @@ -45,6 +48,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode=" echo ""; echo "\n"; + return $return; } ?> diff --git a/mod/glossary/formats/3.php b/mod/glossary/formats/3.php index 6ff8ef69f4..23fdbb43a8 100644 --- a/mod/glossary/formats/3.php +++ b/mod/glossary/formats/3.php @@ -12,6 +12,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode=" echo "\n"; echo "\n"; + $return = false; if ($entry) { print_user_picture($user->id, $course->id, $user->picture); echo ""; @@ -41,6 +42,8 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode=" glossary_print_entry_definition($entry); glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons); + echo ' '; + $return = glossary_print_entry_ratings($course, $entry, $ratings); } else { echo "
"; @@ -50,6 +53,8 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode=" echo ""; echo "\n"; + + return $return; } ?> diff --git a/mod/glossary/formats/4.php b/mod/glossary/formats/4.php index f8f1bc27b7..704719402f 100644 --- a/mod/glossary/formats/4.php +++ b/mod/glossary/formats/4.php @@ -2,7 +2,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1) { global $THEME, $USER; - + $return = false; if ( $entry ) { $colour = $THEME->cellheading2; @@ -23,6 +23,8 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons); + echo ' '; + $return = glossary_print_entry_ratings($course, $entry, $ratings); echo ''; } else { @@ -30,7 +32,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" print_string("noentry", "glossary"); echo '
'; } - + return $return; } ?> diff --git a/mod/glossary/formats/5.php b/mod/glossary/formats/5.php index 9d8e80686c..ecc94e7aad 100644 --- a/mod/glossary/formats/5.php +++ b/mod/glossary/formats/5.php @@ -4,6 +4,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" global $THEME, $USER; $colour = $THEME->cellheading2; + $return = false; echo "\n"; @@ -21,6 +22,8 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" glossary_print_entry_definition($entry); glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons); + echo ' '; + $return = glossary_print_entry_ratings($course, $entry, $ratings); } else { echo "
"; print_string("noentry", "glossary"); @@ -29,7 +32,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" echo ""; echo "
\n"; - + return $return; } ?> diff --git a/mod/glossary/formats/6.php b/mod/glossary/formats/6.php index 19b53e94b3..c43572a7eb 100644 --- a/mod/glossary/formats/6.php +++ b/mod/glossary/formats/6.php @@ -4,6 +4,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" global $THEME, $USER; $colour = "#FFFFFF"; + $return = false; echo "\n"; @@ -27,7 +28,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="" echo ""; echo "
\n"; - + return $return; } ?> diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 0e3afef395..633f7ade5f 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -27,6 +27,20 @@ function glossary_add_instance($glossary) { /// will create a new instance and return the id number /// of the new instance. + if (!$glossary->userating) { + $glossary->assessed = 0; + } + + if (!empty($glossary->ratingtime)) { + $glossary->assesstimestart = make_timestamp($glossary->startyear, $glossary->startmonth, $glossary->startday, + $glossary->starthour, $glossary->startminute, 0); + $glossary->assesstimefinish = make_timestamp($glossary->finishyear, $glossary->finishmonth, $glossary->finishday, + $glossary->finishhour, $glossary->finishminute, 0); + } else { + $glossary->assesstimestart = 0; + $glossary->assesstimefinish = 0; + } + if ( !isset($glossary->globalglossary) ) { $glossary->globalglossary = 0; } elseif ( !isadmin() ) { @@ -54,6 +68,20 @@ global $CFG; $glossary->timemodified = time(); $glossary->id = $glossary->instance; + if (!$glossary->userating) { + $glossary->assessed = 0; + } + + if (!empty($glossary->ratingtime)) { + $glossary->assesstimestart = make_timestamp($glossary->startyear, $glossary->startmonth, $glossary->startday, + $glossary->starthour, $glossary->startminute, 0); + $glossary->assesstimefinish = make_timestamp($glossary->finishyear, $glossary->finishmonth, $glossary->finishday, + $glossary->finishhour, $glossary->finishminute, 0); + } else { + $glossary->assesstimestart = 0; + $glossary->assesstimefinish = 0; + } + $return = update_record("glossary", $glossary); if ($return and $glossary->defaultapproval) { execute_sql("update {$CFG->prefix}glossary_entries SET approved = 1 where approved != 1 and glossaryid = " . $glossary->id,false); @@ -117,8 +145,8 @@ function glossary_user_outline($course, $user, $mod, $glossary) { if ($entries = glossary_get_user_entries($glossary->id, $user->id)) { $result->info = count($entries) . ' ' . get_string("entries", "glossary"); - $lastpost = array_pop($entries); - $result->time = $lastpost->timemodified; + $lastentry = array_pop($entries); + $result->time = $lastentry->timemodified; return $result; } return NULL; @@ -236,10 +264,66 @@ function glossary_cron () { function glossary_grades($glossaryid) { /// Must return an array of grades for a given instance of this module, /// indexed by user. It also returns a maximum allowed grade. + if (!$glossary = get_record("glossary", "id", $glossaryid)) { + return false; + } + if (!$glossary->assessed) { + return false; + } + $scalemenu = make_grades_menu($glossary->scale); + + $currentuser = 0; + $ratingsuser = array(); + + if ($ratings = glossary_get_user_grades($glossaryid)) { + foreach ($ratings as $rating) { // Ordered by user + if ($currentuser and $rating->userid != $currentuser) { + if (!empty($ratingsuser)) { + if ($glossary->scale < 0) { + $return->grades[$currentuser] = glossary_get_ratings_mean(0, $scalemenu, $ratingsuser); + $return->grades[$currentuser] .= "
".glossary_get_ratings_summary(0, $scalemenu, $ratingsuser); + } else { + $total = 0; + $count = 0; + foreach ($ratingsuser as $ra) { + $total += $ra; + $count ++; + } + $return->grades[$currentuser] = format_float($total/$count, 2); + } + } else { + $return->grades[$currentuser] = ""; + } + $ratingsuser = array(); + } + $ratingsuser[] = $rating->rating; + $currentuser = $rating->userid; + } + if (!empty($ratingsuser)) { + if ($glossary->scale < 0) { + $return->grades[$currentuser] = glossary_get_ratings_mean(0, $scalemenu, $ratingsuser); + $return->grades[$currentuser] .= "
".glossary_get_ratings_summary(0, $scalemenu, $ratingsuser); + } else { + $total = 0; + $count = 0; + foreach ($ratingsuser as $ra) { + $total += $ra; + $count ++; + } + $return->grades[$currentuser] = format_float((float)$total/(float)$count, 2); + } + } else { + $return->grades[$currentuser] = ""; + } + } else { + $return->grades = array(); + } - $return->grades = NULL; - $return->maxgrade = NULL; - + if ($glossary->scale < 0) { + $return->maxgrade = ""; + } else { + $return->maxgrade = $glossary->scale; + } return $return; } @@ -313,11 +397,11 @@ global $CFG; } return get_records_sql("SELECT $pivot ge.* FROM {$CFG->prefix}glossary_entries ge, {$CFG->prefix}glossary_entries_categories c - WHERE (ge.id = c.entryid and c.categoryid = $hook) and + WHERE (ge.id = c.entryidid and c.categoryid = $hook) and (ge.glossaryid = $glossary->id or ge.sourceglossaryid = $glossary->id) $where $orderby"); } -function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons = 1, $displayformat = -1) { +function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons = 1, $displayformat = -1, $ratings = NULL) { global $THEME, $USER, $CFG; if ( $displayformat < 0 ) { $displayformat = $glossary->displayformat; @@ -341,14 +425,14 @@ function glossary_print_entry($course, $cm, $glossary, $entry, $mode="",$hook="" } if ( !$basicformat and $permissiongranted or $displayformat >= 2) { - glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode,$hook,$printicons); + return glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings); } else { switch ( $displayformat ) { case GLOSSARY_FORMAT_SIMPLE: - glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode,$hook,$printicons); + return glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings); break; case GLOSSARY_FORMAT_CONTINUOUS: - glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode,$hook,$printicons); + return glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode,$hook,$printicons,$ratings); break; } } @@ -451,7 +535,7 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry,$mode="",$ho $return .= " id&eid=$entry->id\"> "; } - if ($isteacher or $glossary->studentcanpost and $entry->userid == $USER->id) { + if ($isteacher or $glossary->studentcanentry and $entry->userid == $USER->id) { // only teachers can export entries so check it out if ($isteacher and !$ismainglossary and !$importedentry) { $mainglossary = get_record("glossary","mainglossary",1,"course",$course->id); @@ -548,7 +632,7 @@ function glossary_print_entry_approval($cm, $entry, $mode) { } } -function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1) { +function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1, $ratings=NULL) { global $THEME, $USER; $colour = $THEME->cellheading2; @@ -562,12 +646,16 @@ function glossary_print_entry_by_default($course, $cm, $glossary, $entry,$mode=" echo ": "; glossary_print_entry_definition($entry); glossary_print_entry_lower_section($course, $cm, $glossary, $entry,$mode,$hook,$printicons); + echo ' '; + $return = glossary_print_entry_ratings($course, $entry, $ratings); echo ""; echo ""; + return $return; } -function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1) { +function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1, $ratings = NULL) { global $THEME, $USER; + $return = false; if ($entry) { glossary_print_entry_approval($cm, $entry, $mode); glossary_print_entry_attachment($entry,"html","right"); @@ -579,7 +667,9 @@ function glossary_print_entry_continuous($course, $cm, $glossary, $entry,$mode=" $icons = glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode, $hook,"html"); echo "($icons)"; } + $return = glossary_print_entry_ratings($course, $entry, $ratings); } + return $return; } function glossary_search_entries($searchterms, $glossary, $includedefinition) { @@ -599,8 +689,8 @@ function glossary_search_entries($searchterms, $glossary, $includedefinition) { $onlyvisibletable = ""; } - /// Some differences in syntax for PostgreSQL - if ($CFG->dbtype == "postgres7") { + /// Some differences in syntax for entrygreSQL + if ($CFG->dbtype == "entrygres7") { $LIKE = "ILIKE"; // case-insensitive $NOTLIKE = "NOT ILIKE"; // case-insensitive $REGEXP = "~*"; @@ -1274,6 +1364,34 @@ function glossary_print_comment($course, $cm, $glossary, $entry, $comment) { echo ""; } +function glossary_print_entry_ratings($course, $entry, $ratings = NULL) { +global $USER; + $ratingsmenuused = false; + if (!empty($ratings) and !empty($USER->id)) { + $useratings = true; + if ($ratings->assesstimestart and $ratings->assesstimefinish) { + if ($entry->timecreated < $ratings->assesstimestart or $entry->timecreated > $ratings->assesstimefinish) { + $useratings = false; + } + } + if ($useratings) { + if (isteacher($course->id)) { + glossary_print_ratings_mean($entry->id, $ratings->scale); + if ($USER->id != $entry->userid) { + glossary_print_rating_menu($entry->id, $USER->id, $ratings->scale); + $ratingsmenuused = true; + } + } else if ($USER->id == $entry->userid) { + glossary_print_ratings_mean($entry->id, $ratings->scale); + } else if (!empty($ratings->allow) ) { + glossary_print_rating_menu($entry->id, $USER->id, $ratings->scale); + $ratingsmenuused = true; + } + } + } + return $ratingsmenuused; +} + function glossary_print_dynaentry($courseid, $entries, $displayformat = -1) { global $THEME, $USER; @@ -1314,7 +1432,7 @@ global $CFG; $status = fwrite ($h,glossary_start_tag("INFO",1,true)); fwrite ($h,glossary_full_tag("NAME",2,false,$glossary->name)); fwrite ($h,glossary_full_tag("INTRO",2,false,$glossary->intro)); - fwrite ($h,glossary_full_tag("STUDENTCANPOST",2,false,$glossary->studentcanpost)); + fwrite ($h,glossary_full_tag("STUDENTCANentry",2,false,$glossary->studentcanentry)); fwrite ($h,glossary_full_tag("ALLOWDUPLICATEDENTRIES",2,false,$glossary->allowduplicatedentries)); fwrite ($h,glossary_full_tag("SHOWSPECIAL",2,false,$glossary->showspecial)); fwrite ($h,glossary_full_tag("SHOWALPHABET",2,false,$glossary->showalphabet)); @@ -1507,4 +1625,172 @@ function glossary_check_dir_exists($dir,$create=false) { } return $status; } +/* +* Adding grading functions +*/ + +function glossary_get_ratings($entryid, $sort="u.firstname ASC") { +/// Returns a list of ratings for a particular entry - sorted. + global $CFG; + return get_records_sql("SELECT u.*, r.rating, r.time + FROM {$CFG->prefix}glossary_ratings r, + {$CFG->prefix}user u + WHERE r.entryid = '$entryid' + AND r.userid = u.id + ORDER BY $sort"); +} + +function glossary_get_user_grades($glossaryid) { +/// Get all user grades for a glossary + global $CFG; + + return get_records_sql("SELECT r.id, e.userid, r.rating + FROM {$CFG->prefix}glossary_entries e, + {$CFG->prefix}glossary_ratings r + WHERE e.glossaryid = '$glossaryid' + AND r.entryid = e.id + ORDER by e.userid "); +} + +function glossary_count_unrated_entries($glossaryid, $userid) { +// How many unrated entries are in the given glossary for a given user? + global $CFG; + if ($entries = get_record_sql("SELECT count(*) as num + FROM {$CFG->prefix}glossary_entries + WHERE glossaryid = '$glossaryid' + AND userid <> '$userid' ")) { + + if ($rated = get_record_sql("SELECT count(*) as num + FROM {$CFG->prefix}glossary_entries e, + {$CFG->prefix}glossary_ratings r + WHERE e.glossaryid = '$glossaryid' + AND e.id = r.entryid + AND r.userid = '$userid'")) { + $difference = $entries->num - $rated->num; + if ($difference > 0) { + return $difference; + } else { + return 0; // Just in case there was a counting error + } + } else { + return $entries->num; + } + } else { + return 0; + } +} + +function glossary_print_ratings_mean($entryid, $scale) { +/// Print the multiple ratings on a entry given to the current user by others. +/// Scale is an array of ratings + + static $strrate; + + $mean = glossary_get_ratings_mean($entryid, $scale); + + if ($mean !== "") { + + if (empty($strratings)) { + $strratings = get_string("ratings", "glossary"); + } + + echo "$strratings: "; + link_to_popup_window ("/mod/glossary/report.php?id=$entryid", "ratings", $mean, 400, 600); + } +} + + +function glossary_get_ratings_mean($entryid, $scale, $ratings=NULL) { +/// Return the mean rating of a entry given to the current user by others. +/// Scale is an array of possible ratings in the scale +/// Ratings is an optional simple array of actual ratings (just integers) + + if (!$ratings) { + $ratings = array(); + if ($rates = get_records("glossary_ratings", "entryid", $entryid)) { + foreach ($rates as $rate) { + $ratings[] = $rate->rating; + } + } + } + + $count = count($ratings); + + if ($count == 0) { + return ""; + + } else if ($count == 1) { + return $scale[$ratings[0]]; + + } else { + $total = 0; + foreach ($ratings as $rating) { + $total += $rating; + } + $mean = round( ((float)$total/(float)$count) + 0.001); // Little fudge factor so that 0.5 goes UP + + if (isset($scale[$mean])) { + return $scale[$mean]." ($count)"; + } else { + return "$mean ($count)"; // Should never happen, hopefully + } + } +} + +function glossary_get_ratings_summary($entryid, $scale, $ratings=NULL) { +/// Return a summary of entry ratings given to the current user by others. +/// Scale is an array of possible ratings in the scale +/// Ratings is an optional simple array of actual ratings (just integers) + + if (!$ratings) { + $ratings = array(); + if ($rates = get_records("glossary_ratings", "entryid", $entryid)) { + foreach ($rates as $rate) { + $rating[] = $rate->rating; + } + } + } + + + if (!$count = count($ratings)) { + return ""; + } + + + foreach ($scale as $key => $scaleitem) { + $sumrating[$key] = 0; + } + + foreach ($ratings as $rating) { + $sumrating[$rating]++; + } + + $summary = ""; + foreach ($scale as $key => $scaleitem) { + $summary = $sumrating[$key].$summary; + if ($key > 1) { + $summary = "/$summary"; + } + } + return $summary; +} + +function glossary_print_rating_menu($entryid, $userid, $scale) { +/// Print the menu of ratings as part of a larger form. +/// If the entry has already been - set that value. +/// Scale is an array of ratings + + static $strrate; + + if (!$rating = get_record("glossary_ratings", "userid", $userid, "entryid", $entryid)) { + $rating->rating = 0; + } + + if (empty($strrate)) { + $strrate = get_string("rate", "glossary"); + } + + choose_from_menu($scale, $entryid, $rating->rating, "$strrate..."); +} + ?> diff --git a/mod/glossary/mod.html b/mod/glossary/mod.html index 35e2a4bf0a..74abde9407 100644 --- a/mod/glossary/mod.html +++ b/mod/glossary/mod.html @@ -322,6 +322,83 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) { + +

:

+ + "; + echo " var subitemstime = ['startday','startmonth','startyear','starthour', 'startminute',". + "'finishday','finishmonth','finishyear','finishhour','finishminute'];"; + echo " var subitemsall = ['assessed', 'ratingtime', 'scale', 'startday','startmonth','startyear','starthour', 'startminute',". + "'finishday','finishmonth','finishyear','finishhour','finishminute'];"; + echo ""; + + echo "assessed) { + echo " checked "; + } + echo ">"; + echo get_string("ratingsuse", "glossary").":"; + echo "
"; + + // The odd order below was to maintain backward compatibility + unset($options); + $options[2] = get_string("ratingonlyteachers", "glossary", moodle_strtolower($course->teachers)); + $options[1] = get_string("ratingeveryone", "glossary"); + echo get_string("users").":"; + choose_from_menu($options, "assessed", $form->assessed, ""); + echo "
"; + + echo get_string("grade").":"; + print_grade_menu($course->id, "scale", $form->scale, false); + echo "
"; + + echo "assesstimestart and $form->assesstimefinish and $form->assessed) { + $form->ratingtime = 1; + echo " checked "; + } + echo ">"; + + print_string("ratingtime", "glossary"); + echo "
"; + echo get_string("from").":"; + print_date_selector("startday", "startmonth", "startyear", $form->assesstimestart); + print_time_selector("starthour", "startminute", $form->assesstimestart); + echo "
"; + echo get_string("to").":"; + print_date_selector("finishday", "finishmonth", "finishyear", $form->assesstimefinish); + print_time_selector("finishhour", "finishminute", $form->assesstimefinish); + echo "
"; + echo "
"; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + + echo ""; + + if (empty($form->ratingtime)) { + echo ""; + } + ?> + + diff --git a/mod/glossary/rate.php b/mod/glossary/rate.php new file mode 100644 index 0000000000..fc1336842d --- /dev/null +++ b/mod/glossary/rate.php @@ -0,0 +1,53 @@ +id); + + if ($data = data_submitted("$CFG->wwwroot/mod/glossary/view.php")) { // form submitted + + foreach ($data as $entry => $rating) { + if ($entry == "id") { + continue; + } + if ($oldrating = get_record("glossary_ratings", "userid", $USER->id, "entryid", $entry)) { + if ($rating != $oldrating->rating) { + $oldrating->rating = $rating; + $oldrating->time = time(); + if (! update_record("glossary_ratings", $oldrating)) { + error("Could not update an old rating ($entry = $rating)"); + } + } + } else if ($rating) { + unset($newrating); + $newrating->userid = $USER->id; + $newrating->time = time(); + $newrating->entryid = $entry; + $newrating->rating = $rating; + + if (! insert_record("glossary_ratings", $newrating)) { + error("Could not insert a new rating ($entry = $rating)"); + } + } + } + redirect($_SERVER["HTTP_REFERER"], get_string("ratingssaved", "glossary")); + + } else { + error("This page was not accessed correctly"); + } + +?> diff --git a/mod/glossary/report.php b/mod/glossary/report.php new file mode 100644 index 0000000000..2f6fb50d3c --- /dev/null +++ b/mod/glossary/report.php @@ -0,0 +1,68 @@ +glossaryid)) { + error("Glossary ID was incorrect"); + } + + if (! $course = get_record("course", "id", $glossary->course)) { + error("Course ID was incorrect"); + } + + if (!isteacher($course->id) and $USER->id != $entry->userid) { + error("You can only look at results for your own entries"); + } + + if (!isset($sort)) { + $sort = "r.time"; + } + + $scalemenu = make_grades_menu($glossary->scale); + + $strratings = get_string("ratings", "glossary"); + $strrating = get_string("rating", "glossary"); + $strname = get_string("name"); + $strtime = get_string("time"); + + print_header("$strratings: $entry->subject"); + + if (!$ratings = glossary_get_ratings($entry->id, $sort)) { + error("No ratings for this entry: \"$entry->subject\""); + + } else { + echo ""; + echo ""; + echo ""; + echo "cellcontent2\">"; + } else { + echo "cellcontent\">"; + } + echo "\n"; + } + echo "
 id&sort=u.firstname>$strname"; + echo "id&sort=r.rating>$strrating"; + echo "id&sort=r.time>$strtime"; + foreach ($ratings as $rating) { + if (isteacher($glossary->course, $rating->id)) { + echo "
"; + print_user_picture($rating->id, $glossary->course, $rating->picture); + echo "

$rating->firstname $rating->lastname

"; + echo "

".$scalemenu[$rating->rating]."

"; + echo "

".userdate($rating->time)."

"; + echo "
"; + echo "
"; + } + + close_window_button(); + +?> diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index b293128fc8..c30005cca8 100644 --- a/mod/glossary/restorelib.php +++ b/mod/glossary/restorelib.php @@ -63,6 +63,11 @@ $glossary->timecreated = backup_todb($info['MOD']['#']['TIMECREATED']['0']['#']); $glossary->timemodified = backup_todb($info['MOD']['#']['TIMEMODIFIED']['0']['#']); + $glossary->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']); + $glossary->assesstimestart = backup_todb($info['MOD']['#']['ASSESSTIMESTART']['0']['#']); + $glossary->assesstimefinish = backup_todb($info['MOD']['#']['ASSESSTIMEFINISH']['0']['#']); + $glossary->scale = backup_todb($info['MOD']['#']['SCALE']['0']['#']); + //The structure is equal to the db, so insert the glossary $newid = insert_record ("glossary",$glossary); diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 27014bd401..0adac13e94 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2003111800; // The current module version (Date: YYYYMMDDXX) +$module->version = 2003112101; // The current module version (Date: YYYYMMDDXX) $module->cron = 0; // Period for cron to check this module (secs) $release = "0.5 development"; // User-friendly version number diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 804cdce8d6..daf1ec9a33 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -2,6 +2,7 @@ /// This page prints a particular instance of glossary require_once("../../config.php"); require_once("lib.php"); + global $CFG, $THEME, $USER; $debug = 0; $CFG->startpagetime = microtime(); @@ -40,7 +41,6 @@ } /// setting the defaut number of entries per page if not set - global $CFG, $THEME, $USER; if ( !$entriesbypage = $glossary->entbypage ) { $entriesbypage = $CFG->glossary_entbypage; @@ -275,6 +275,23 @@ } echo $paging; + $ratings = NULL; + $ratingsmenuused = false; + if ($glossary->assessed and !empty($USER->id)) { + if ($ratings->scale = make_grades_menu($glossary->scale)) { + $ratings->assesstimestart = $glossary->assesstimestart; + $ratings->assesstimefinish = $glossary->assesstimefinish; + if ($glossary->assessed == 2 and !isteacher($course->id)) { + $ratings->allow = false; + } else { + $ratings->allow = true; + } + + echo "
"; + echo "id\">"; + } + } + foreach ($allentries as $entry) { /// Setting the pivot for the current entry $pivot = $entry->pivot; @@ -383,7 +400,9 @@ } /// and finally print the entry. - glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat); + if ( glossary_print_entry($course, $cm, $glossary, $entry, $mode, $hook,1,$displayformat,$ratings) ) { + $ratingsmenuused = true; + } $entriesshown++; } @@ -399,6 +418,18 @@ if ( !$entriesshown ) { print_simple_box('
' . get_string("noentries","glossary") . '
',"center","95%"); } + + if ($ratingsmenuused) { + echo "
"; + if ($glossary->scale < 0) { + if ($scale = get_record("scale", "id", abs($glossary->scale))) { + print_scale_menu_helpbutton($course->id, $scale ); + } + } + echo "
"; + echo "
"; + } + if ( $paging ) { echo "
$paging"; }