$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?';
$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.';
$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';
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?
********* 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
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);
(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;
}
?>
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)
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`
#
<?PHP // $Id$
-function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1) {
+function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode="",$hook="",$printicons=1,$ratings=NULL) {
global $THEME, $CFG, $USER;
$colour = $THEME->cellheading2;
echo "\n<tr>";
echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostpicture\">";
+ $return = false;
if ($entry) {
print_user_picture($user->id, $course->id, $user->picture);
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 "<center>";
echo "</td></tr>";
echo "</table>\n";
+ return $return;
}
?>
echo "\n<tr>";
echo "\n<td bgcolor=\"$colour\" width=35 valign=top class=\"forumpostpicture\">";
+ $return = false;
if ($entry) {
print_user_picture($user->id, $course->id, $user->picture);
echo "</td>";
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 "<center>";
echo "</td></tr>";
echo "</table>\n";
+
+ return $return;
}
?>
function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode="",$hook="",$printicons=1) {
global $THEME, $USER;
-
+ $return = false;
if ( $entry ) {
$colour = $THEME->cellheading2;
glossary_print_entry_lower_section($course, $cm, $glossary, $entry, $mode, $hook,$printicons);
+ echo ' ';
+ $return = glossary_print_entry_ratings($course, $entry, $ratings);
echo '</td></tr></table>';
} else {
print_string("noentry", "glossary");
echo '</center>';
}
-
+ return $return;
}
?>
global $THEME, $USER;
$colour = $THEME->cellheading2;
+ $return = false;
echo "\n<table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
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 "<center>";
print_string("noentry", "glossary");
echo "</td></tr>";
echo "</table>\n";
-
+ return $return;
}
?>
global $THEME, $USER;
$colour = "#FFFFFF";
+ $return = false;
echo "\n<table class=\"generalbox\" border=0 cellspacing=0 width=95% valign=top cellpadding=10>";
echo "</td></tr>";
echo "</table>\n";
-
+ return $return;
}
?>
/// 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() ) {
$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);
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;
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] .= "<br />".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] .= "<br />".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;
}
}
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;
}
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;
}
}
$return .= " <a title=\"" . get_string("addcomment","glossary") . "\" href=\"comment.php?id=$cm->id&eid=$entry->id\"><img src=\"comment.gif\" height=16 width=16 border=0></a> ";
}
- 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);
}
}
-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;
echo ":</b> ";
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 "</td>";
echo "</TR>";
+ 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");
$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) {
$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 = "~*";
echo "</td></tr></table>";
}
+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;
$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));
}
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...");
+}
+
?>
</select> <?php helpbutton("shows", get_string("showall", "glossary"), "glossary") ?>
</TD>
</TR>
+<tr>
+ <td align=right valign=top><p><b><?php print_string("allowratings", "glossary") ?>:</b></p></td>
+ <td>
+ <?php
+ echo "<script>";
+ 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 "</script>";
+
+ echo "<input name=\"userating\" type=checkbox value=1 ";
+ echo " onclick=\"return lockoptions('form','userating', subitemsall)\" ";
+ if ($form->assessed) {
+ echo " checked ";
+ }
+ echo ">";
+ echo get_string("ratingsuse", "glossary").":";
+ echo "<br />";
+
+ // 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 "<br />";
+
+ echo get_string("grade").":";
+ print_grade_menu($course->id, "scale", $form->scale, false);
+ echo "<br />";
+
+ echo "<input name=\"ratingtime\" type=checkbox value=1 ";
+ echo " onclick=\"return lockoptions('form','ratingtime', subitemstime)\" ";
+ if ($form->assesstimestart and $form->assesstimefinish and $form->assessed) {
+ $form->ratingtime = 1;
+ echo " checked ";
+ }
+ echo ">";
+
+ print_string("ratingtime", "glossary");
+ echo "<table align=left><tr><td align=right nowrap>";
+ echo get_string("from").":";
+ print_date_selector("startday", "startmonth", "startyear", $form->assesstimestart);
+ print_time_selector("starthour", "startminute", $form->assesstimestart);
+ echo "<br />";
+ echo get_string("to").":";
+ print_date_selector("finishday", "finishmonth", "finishyear", $form->assesstimefinish);
+ print_time_selector("finishhour", "finishminute", $form->assesstimefinish);
+ echo "<br />";
+ echo "</td></tr></table>";
+ echo "<input type=\"hidden\" name=\"hratingtime\" value=0>";
+ echo "<input type=\"hidden\" name=\"hassessed\" value=0>";
+ echo "<input type=\"hidden\" name=\"hscale\" value=0>";
+ echo "<input type=\"hidden\" name=\"hstartday\" value=0>";
+ echo "<input type=\"hidden\" name=\"hstartmonth\" value=0>";
+ echo "<input type=\"hidden\" name=\"hstartyear\" value=0>";
+ echo "<input type=\"hidden\" name=\"hstarthour\" value=0>";
+ echo "<input type=\"hidden\" name=\"hstartminute\" value=0>";
+ echo "<input type=\"hidden\" name=\"hfinishday\" value=0>";
+ echo "<input type=\"hidden\" name=\"hfinishmonth\" value=0>";
+ echo "<input type=\"hidden\" name=\"hfinishyear\" value=0>";
+ echo "<input type=\"hidden\" name=\"hfinishhour\" value=0>";
+ echo "<input type=\"hidden\" name=\"hfinishminute\" value=0>";
+
+ echo "<script>";
+ echo "lockoptions('form','userating', subitemsall);";
+ echo "</script>";
+
+ if (empty($form->ratingtime)) {
+ echo "<script>";
+ echo "lockoptions('form','ratingtime', subitemstime);";
+ echo "</script>";
+ }
+ ?>
+ </td>
+</tr>
</TABLE>
<!-- These hidden variables are always the same -->
<INPUT type="hidden" name=course value="<?php p($form->course) ?>">
--- /dev/null
+<?PHP
+
+// Collect ratings, store them, then return to where we came from
+
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ if (isguest()) {
+ error("Guests are not allowed to rate entries.", $_SERVER["HTTP_REFERER"]);
+ }
+
+ require_variable($id); // The course these ratings are part of
+
+ if (! $course = get_record("course", "id", $id)) {
+ error("Course ID was incorrect");
+ }
+
+ require_login($course->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");
+ }
+
+?>
--- /dev/null
+<?PHP
+// For a given entry, shows a report of all the ratings it has
+
+ require_once("../../config.php");
+ require_once("lib.php");
+
+ require_variable($id);
+ global $USER;
+
+ if (! $entry = get_record("glossary_entries", "id", $id)) {
+ error("Entry ID was incorrect");
+ }
+
+ if (! $glossary = get_record("glossary", "id", $entry->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 "<table border=0 cellpadding=3 cellspacing=3 class=generalbox width=100%>";
+ echo "<tr>";
+ echo "<th> </th>";
+ echo "<th><a href=report.php?id=$entry->id&sort=u.firstname>$strname</a>";
+ echo "<th width=100%><a href=report.php?id=$entry->id&sort=r.rating>$strrating</a>";
+ echo "<th><a href=report.php?id=$entry->id&sort=r.time>$strtime</a>";
+ foreach ($ratings as $rating) {
+ if (isteacher($glossary->course, $rating->id)) {
+ echo "<tr bgcolor=\"$THEME->cellcontent2\">";
+ } else {
+ echo "<tr bgcolor=\"$THEME->cellcontent\">";
+ }
+ echo "<td>";
+ print_user_picture($rating->id, $glossary->course, $rating->picture);
+ echo "<td nowrap><p><font size=-1>$rating->firstname $rating->lastname</p>";
+ echo "<td nowrap align=center><p><font size=-1>".$scalemenu[$rating->rating]."</p>";
+ echo "<td nowrap align=center><p><font size=-1>".userdate($rating->time)."</p>";
+ echo "</tr>\n";
+ }
+ echo "</table>";
+ echo "<br />";
+ }
+
+ close_window_button();
+
+?>
$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);
/// 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
/// 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();
}
/// setting the defaut number of entries per page if not set
- global $CFG, $THEME, $USER;
if ( !$entriesbypage = $glossary->entbypage ) {
$entriesbypage = $CFG->glossary_entbypage;
}
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 "<form name=form method=post action=rate.php>";
+ echo "<input type=hidden name=id value=\"$course->id\">";
+ }
+ }
+
foreach ($allentries as $entry) {
/// Setting the pivot for the current entry
$pivot = $entry->pivot;
}
/// 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++;
}
if ( !$entriesshown ) {
print_simple_box('<center>' . get_string("noentries","glossary") . '</center>',"center","95%");
}
+
+ if ($ratingsmenuused) {
+ echo "<center><input type=\"submit\" value=\"".get_string("sendinratings", "glossary")."\">";
+ if ($glossary->scale < 0) {
+ if ($scale = get_record("scale", "id", abs($glossary->scale))) {
+ print_scale_menu_helpbutton($course->id, $scale );
+ }
+ }
+ echo "</center>";
+ echo "</form>";
+ }
+
if ( $paging ) {
echo "<hr />$paging";
}