]> git.mjollnir.org Git - moodle.git/commitdiff
- Grading enabled.... finally.
authorwillcast <willcast>
Fri, 21 Nov 2003 18:42:38 +0000 (18:42 +0000)
committerwillcast <willcast>
Fri, 21 Nov 2003 18:42:38 +0000 (18:42 +0000)
17 files changed:
lang/en/glossary.php
mod/glossary/TODO.txt
mod/glossary/backuplib.php
mod/glossary/db/mysql.php
mod/glossary/db/mysql.sql
mod/glossary/formats/2.php
mod/glossary/formats/3.php
mod/glossary/formats/4.php
mod/glossary/formats/5.php
mod/glossary/formats/6.php
mod/glossary/lib.php
mod/glossary/mod.html
mod/glossary/rate.php [new file with mode: 0644]
mod/glossary/report.php [new file with mode: 0644]
mod/glossary/restorelib.php
mod/glossary/version.php
mod/glossary/view.php

index 772dd5966be8e4c7c175b88c9791dc1f2a46eac5..d31d5acbb0cb0d15364e654d85cb47fcb7d3120f 100644 (file)
@@ -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';
index e05b3d7f18942a129c27a5bb7d47cc43f49b3830..874b90ebb97d677cba35653c54afca01d951c4bc 100644 (file)
@@ -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
index b24cf40e043d4376c1729ec49e1334176ebc61f6..1285f9b3e8ae22903b46ebbbe0e0eacd7d9d78bf 100644 (file)
                 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);
 
index 130941f6f480a11425aab88a5af3c8bb1a69d864..f2ea58974a7d75c4a79be7f9344cbede54e3f338 100644 (file)
@@ -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;
 }
 
 ?>
index 16f8c17184af18452a59bd390a37763661c5285c..cf11269917bdc66242d5a6af3b61a08e98efa6b1 100644 (file)
@@ -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`
 #
index 884ad2b2e914a5d1157962c28ce2fffe6dbdd65d..9fe1394314281659782e4b22474d815298db253e 100644 (file)
@@ -1,6 +1,6 @@
 <?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;
@@ -12,6 +12,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode="
 
     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);
 
@@ -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 "<center>";
@@ -45,6 +48,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode="
     echo "</td></tr>";
 
     echo "</table>\n";
+    return $return;
 }
 
 ?>
index 6ff8ef69f425a7e2d14b15a45063e9966f596276..23fdbb43a8bcef84245a7a425d070bd615831275 100644 (file)
@@ -12,6 +12,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode="
 
     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>";
@@ -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 "<center>";
@@ -50,6 +53,8 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry, $mode="
     echo "</td></tr>";
 
     echo "</table>\n";
+    
+    return $return;
 }
 
 ?>
index f8f1bc27b7206d50e98920c6d485e53cae25fc3c..704719402f97955bdd5a8a202bb9c72f2b29928c 100644 (file)
@@ -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 '</td></tr></table>';
 
     } else {
@@ -30,7 +32,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode=""
         print_string("noentry", "glossary");
         echo '</center>';
     }
-
+    return $return;
 }
 
 ?>
index 9d8e80686c4a1c64daae532e10b0c751b6771e7a..ecc94e7aade336fe6465e36a6635358d9e3e7f02 100644 (file)
@@ -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<table border=1 cellspacing=0 width=95% valign=top cellpadding=10>";
 
@@ -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 "<center>";
         print_string("noentry", "glossary");
@@ -29,7 +32,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode=""
     echo "</td></tr>";
 
     echo "</table>\n";
-
+    return $return;
 }
 
 ?>
index 19b53e94b3000f697203ea1d6260087dc59dd7ba..c43572a7eb1b8cea05ed2751092a494ab85d46cd 100644 (file)
@@ -4,6 +4,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode=""
     global $THEME, $USER;
 
     $colour = "#FFFFFF";
+    $return = false;
 
     echo "\n<table class=\"generalbox\" border=0 cellspacing=0 width=95% valign=top cellpadding=10>";
 
@@ -27,7 +28,7 @@ function glossary_print_entry_by_format($course, $cm, $glossary, $entry,$mode=""
     echo "</td></tr>";
 
     echo "</table>\n";
-
+    return $return;
 }
 
 ?>
index 0e3afef3952a0728df1e3bbd58b66e79da771466..633f7ade5fbc874cd728b6c22240c5b369e1dc43 100644 (file)
@@ -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] .= "<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;
 }
 
@@ -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 .= " <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);
@@ -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 ":</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");
@@ -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 "</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;
 
@@ -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...");
+}
+
 ?>
index 35e2a4bf0ac202b864fdc6d7c1bfc8ff8f3e6087..74abde940798668597e69d8a12caf63fb33b8b4b 100644 (file)
@@ -322,6 +322,83 @@ if (!$mainglossary or $mainglossary->id == $form->instance ) {
   </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) ?>">
diff --git a/mod/glossary/rate.php b/mod/glossary/rate.php
new file mode 100644 (file)
index 0000000..fc13368
--- /dev/null
@@ -0,0 +1,53 @@
+<?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");
+    }
+
+?>
diff --git a/mod/glossary/report.php b/mod/glossary/report.php
new file mode 100644 (file)
index 0000000..2f6fb50
--- /dev/null
@@ -0,0 +1,68 @@
+<?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>&nbsp;</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();
+
+?>
index b293128fc8e43a488618da750561d565cc385f7a..c30005cca8a8b0df113e846816de380607e6fdb8 100644 (file)
             $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);
 
index 27014bd401bc5eec05f520e2d7616d33c3366665..0adac13e94bdda2fe4e47ca884c9c350118fb1f7 100644 (file)
@@ -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
index 804cdce8d6d4dc459a71d4a68c52c765e67b22c1..daf1ec9a337f1355272810d9a75568a229cbcf01 100644 (file)
@@ -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;
         }
         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";
     }