]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-20345, use new comments api in glossary module"
authorDongsheng Cai <unoter@gmail.com>
Sun, 8 Nov 2009 14:12:12 +0000 (14:12 +0000)
committerDongsheng Cai <unoter@gmail.com>
Sun, 8 Nov 2009 14:12:12 +0000 (14:12 +0000)
12 files changed:
mod/glossary/backuplib.php
mod/glossary/comment.php [deleted file]
mod/glossary/comment_form.php [deleted file]
mod/glossary/comments.php [deleted file]
mod/glossary/db/install.php
mod/glossary/db/install.xml
mod/glossary/db/upgrade.php
mod/glossary/deleteentry.php
mod/glossary/lib.php
mod/glossary/restorelib.php
mod/glossary/version.php
mod/glossary/view.php

index f9fc4e55b97622d66a364a459bec3faacab6173e..cc9e64aa1c0c354fce8628c3a6acd848bd60a3f7 100644 (file)
         global $CFG, $DB;
 
         $status = true;
+        $params = array();
+        $params[] = $entryid;
+        $sql = 'SELECT g.id AS glossaryid, g.course as courseid FROM {glossary_entries} e, {glossary} g WHERE e.glossaryid = g.id AND e.id=?';
+        $result = $DB->get_record_sql($sql, $params);
+        if ($cm = get_coursemodule_from_instance('glossary', $result->glossaryid, $result->courseid)) {
+            $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+        }
 
-        $comments = $DB->get_records("glossary_comments", array("entryid"=>$entryid));
+        $comments = $DB->get_records('comments', array('itemid'=>$entryid, 'commentarea'=>'glossary_entry', 'contextid'=>$context->id));
         if ($comments) {
             $status =fwrite ($bf,start_tag("COMMENTS",6,true));
             foreach ($comments as $comment) {
 
                 fwrite ($bf,full_tag("ID",8,false,$comment->id));
                 fwrite ($bf,full_tag("USERID",8,false,$comment->userid));
-                fwrite ($bf,full_tag("ENTRYCOMMENT",8,false,$comment->entrycomment));
-                fwrite ($bf,full_tag("FORMAT",8,false,$comment->entrycommentformat));
-                fwrite ($bf,full_tag("TIMEMODIFIED",8,false,$comment->timemodified));
+                fwrite ($bf,full_tag("CONTENT",8,false,$comment->content));
+                fwrite ($bf,full_tag("COMMENTAREA",8,false,$comment->commentarea));
+                fwrite ($bf,full_tag("FORMAT",8,false,$comment->format));
+                fwrite ($bf,full_tag("TIMECREATED",8,false,$comment->timecreated));
 
                 $status =fwrite ($bf,end_tag("COMMENT",7,true));
             }
diff --git a/mod/glossary/comment.php b/mod/glossary/comment.php
deleted file mode 100644 (file)
index 2d59774..0000000
+++ /dev/null
@@ -1,237 +0,0 @@
-<?php
-
-require_once('../../config.php');
-require_once('lib.php');
-require_once('comment_form.php');
-
-$action = optional_param('action','add', PARAM_ACTION);
-
-$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/comment.php', array('action'=>$action)));
-
-if (has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false)) {
-    print_error('guestnocomment');
-}
-
-switch ($action) {
-    case 'add':
-        glossary_comment_add();
-        die;
-    case 'delete':
-        glossary_comment_delete();
-        die;
-    case 'edit':
-        glossary_comment_edit();
-        die;
-    default:
-        print_error('invalidaction');
-}
-
-/**
- * Add new comment
- */
-function glossary_comment_add() {
-    global $USER, $DB;
-
-    $entryid = optional_param('entryid', 0, PARAM_INT); // Entry ID
-
-    if (!$entry = $DB->get_record('glossary_entries', array('id'=>$entryid))) {
-        print_error('invalidentry');
-    }
-    if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
-        print_error('invalidid', 'glossary');
-    }
-    if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
-        print_error('invalidcoursemodule');
-    }
-    if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    require_login($course, false, $cm);
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-    /// Both the configuration and capability must allow comments
-    if (!$glossary->allowcomments or !has_capability('mod/glossary:comment', $context)) {
-        print_error('nopermissiontocomment');
-    }
-
-    $commentoptions = array('trusttext'=>true, 'maxfiles'=>0, 'context'=>$context);
-
-    $comment = new object();
-    $comment->id      = null;
-    $comment->action  = 'add';
-    $comment->entryid = $entry->id;
-
-    $comment = file_prepare_standard_editor($comment, 'entrycomment', $commentoptions, $context);
-
-    $mform = new mod_glossary_comment_form(null, array('current'=>$comment, 'commentoptions'=>$commentoptions));
-
-    if ($mform->is_cancelled()) {
-        redirect("comments.php?id=$cm->id&amp;eid=$entry->id");
-    }
-
-    if ($newcomment = $mform->get_data()) {
-
-        $newcomment = file_postupdate_standard_editor($newcomment, 'entrycomment', $commentoptions, $context);//no files - can be used before insert
-        $newcomment->timemodified = time();
-        $newcomment->userid       = $USER->id;
-
-        $newcomment->id = $DB->insert_record('glossary_comments', $newcomment);
-
-        add_to_log($course->id, 'glossary', 'add comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$newcomment->id", $cm->id);
-        redirect("comments.php?id=$cm->id&eid=$entry->id");
-
-    } else {
-        glossary_comment_print_header($course, $cm, $glossary, $entry, 'add');
-        $mform->display();
-        echo $OUTPUT->footer();
-        die;
-    }
-}
-
-/**
- * Deleting existing comments
- */
-function glossary_comment_delete() {
-    global $USER, $DB, $OUTPUT;
-
-    $id      = optional_param('id', 0, PARAM_INT);      // Comment ID
-    $confirm = optional_param('confirm', 0, PARAM_BOOL); // delete confirmation
-
-    if (!$comment = $DB->get_record('glossary_comments', array('id'=>$id))) {
-        print_error('invalidcomment');
-    }
-    if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
-        print_error('invalidentry');
-    }
-    if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
-        print_error('invalidid', 'glossary');
-    }
-    if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
-        print_error('invalidcoursemodule');
-    }
-    if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    require_login($course, false, $cm);
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-    if (($comment->userid <> $USER->id) and !has_capability('mod/glossary:managecomments', $context)) {
-        print_error('nopermissiontodelcomment', 'glossary');
-    }
-    if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) {
-        print_error('nopermissiontodelinglossary', 'glossary');
-    }
-
-    if (data_submitted() and $confirm) {
-        $DB->delete_records('glossary_comments', array('id'=>$id));
-        add_to_log($course->id, 'glossary', 'delete comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$comment->id",$cm->id);
-        redirect("comments.php?id=$cm->id&amp;eid=$entry->id");
-
-    } else {
-        $linkyes    = 'comment.php';
-        $optionsyes = array('action'=>'delete', 'id'=>$id, 'confirm'=>1);
-        $linkno     = 'comments.php';
-        $optionsno  = array('id'=>$cm->id, 'entryid'=>$entry->id);
-        $strdeletewarning = get_string('areyousuredeletecomment','glossary');
-
-        glossary_comment_print_header($course, $cm, $glossary, $entry, 'delete');
-        glossary_print_comment($course, $cm, $glossary, $entry, $comment);
-        echo $OUTPUT->confirm($strdeletewarning, new moodle_url($linkyes, $optionsyes), new moodle_url($linkno, $optionsno));
-        echo $OUTPUT->footer();
-        die;
-    }
-}
-
-/**
- * Edit existing comments
- */
-function glossary_comment_edit() {
-    global $CFG, $USER, $DB, $OUTPUT;
-
-    $id = optional_param('id', 0, PARAM_INT); // Comment ID
-
-    if (!$comment = $DB->get_record('glossary_comments', array('id'=>$id))) {
-        print_error('invalidcomment');
-    }
-    if (!$entry = $DB->get_record('glossary_entries', array('id'=>$comment->entryid))) {
-        print_error('invalidentry');
-    }
-    if (!$glossary = $DB->get_record('glossary', array('id'=>$entry->glossaryid))) {
-        print_error('invalidid', 'glossary');
-    }
-    if (!$cm = get_coursemodule_from_instance('glossary', $glossary->id)) {
-        print_error('invalidcoursemodule');
-    }
-    if (!$course = $DB->get_record('course', array('id'=>$cm->course))) {
-        print_error('coursemisconf');
-    }
-
-    require_login($course, false, $cm);
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-    if (!$glossary->allowcomments and !has_capability('mod/glossary:managecomments', $context)) {
-        print_error('nopermissiontodelinglossary', 'glossary');
-    }
-    if (($comment->userid <> $USER->id) and !has_capability('mod/glossary:managecomments', $context)) {
-        print_error('nopermissiontoeditcomment');
-    }
-    $ineditperiod = ((time() - $comment->timemodified <  $CFG->maxeditingtime) || $glossary->editalways);
-    if ((!has_capability('mod/glossary:comment', $context) or !$ineditperiod) and !has_capability('mod/glossary:managecomments', $context)) {
-        print_error('cannoteditcommentexpired');
-    }
-
-    $commentoptions = array('trusttext'=>true, 'maxfiles'=>0);
-
-    $comment->action  = 'edit';
-    $comment = file_prepare_standard_editor($comment, 'entrycomment', $commentoptions, $context);
-
-    $mform = new mod_glossary_comment_form(null, array('current'=>$comment, 'commentoptions'=>$commentoptions));
-
-    if ($updatedcomment = $mform->get_data()) {
-
-        $updatedcomment = file_postupdate_standard_editor($updatedcomment, 'entrycomment', $commentoptions, $context);
-        $updatedcomment->timemodified = time();
-
-        $DB->update_record('glossary_comments', $updatedcomment);
-        add_to_log($course->id, 'glossary', 'update comment', "comments.php?id=$cm->id&amp;eid=$entry->id", "$updatedcomment->id",$cm->id);
-
-        redirect("comments.php?id=$cm->id&eid=$entry->id");
-
-    } else {
-        glossary_comment_print_header($course, $cm, $glossary, $entry, 'edit');
-        $mform->display();
-        echo $OUTPUT->footer();
-        die;
-    }
-}
-
-//////////////////////////////////
-/// utility functions
-//////////////////////////////////
-
-function glossary_comment_print_header($course, $cm, $glossary, $entry, $action) {
-    global $PAGE, $OUTPUT;
-    switch ($action){
-        case 'add':
-            $straction = get_string('addingcomment','glossary');
-            break;
-        case 'edit':
-            $straction = get_string('editingcomment','glossary');
-            break;
-        case 'delete':
-            $straction = get_string('deletingcomment','glossary');
-            break;
-    }
-
-    $strglossary   = get_string('modulename', 'glossary');
-    $strcomments   = get_string('comments', 'glossary');
-
-    $PAGE->navbar->add($strcomments, new moodle_url($CFG->wwwroot.'/mod/glossary/comments.php', array('id'=>$cm->id,'eid'=>$entry->id)));
-    $PAGE->navbar->add($straction);
-    $PAGE->set_title(format_string($glossary->name));
-    $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
-    echo $OUTPUT->header();
-
-/// print original glossary entry for any comment action (add, update, delete)
-    glossary_print_entry($course, $cm, $glossary, $entry, 'approval', '', false);
-}
-
diff --git a/mod/glossary/comment_form.php b/mod/glossary/comment_form.php
deleted file mode 100644 (file)
index 14d0e1f..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-require_once $CFG->libdir.'/formslib.php';
-
-class mod_glossary_comment_form extends moodleform {
-    function definition() {
-        $mform =& $this->_form;
-
-        $current        = $this->_customdata['current'];
-        $commentoptions = $this->_customdata['commentoptions'];
-
-        // visible elements
-        $mform->addElement('editor', 'entrycomment_editor', get_string('comment', 'glossary'), null, $commentoptions);
-        $mform->addRule('entrycomment_editor', get_string('required'), 'required', null, 'client');
-        $mform->setType('entrycomment_editor', PARAM_RAW); // processed by trust text or cleaned before the display
-
-        // hidden optional params
-        $mform->addElement('hidden', 'id', 0);
-        $mform->setType('id', PARAM_INT);
-
-        $mform->addElement('hidden', 'entryid', 0);
-        $mform->setType('entryid', PARAM_INT);
-
-        $mform->addElement('hidden', 'action', '');
-        $mform->setType('action', PARAM_ACTION);
-
-//-------------------------------------------------------------------------------
-        // buttons
-        $this->add_action_buttons(false);
-
-//-------------------------------------------------------------------------------
-        $this->set_data($current);
-    }
-}
diff --git a/mod/glossary/comments.php b/mod/glossary/comments.php
deleted file mode 100644 (file)
index 70de4cc..0000000
+++ /dev/null
@@ -1,77 +0,0 @@
-<?php
-
-/// This page prints a particular instance of glossary
-require_once('../../config.php');
-require_once('lib.php');
-
-$id  = required_param('id', PARAM_INT);           // Course Module ID
-$eid = required_param('eid', PARAM_INT);          // Entry ID
-
-$PAGE->set_url(new moodle_url($CFG->wwwroot.'/mod/glossary/comments.php', array('id'=>$id,'eid'=>$eid)));
-
-if (! $cm = get_coursemodule_from_id('glossary', $id)) {
-    print_error('invalidcoursemodule');
-}
-
-if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
-    print_error('coursemisconf');
-}
-
-if (! $glossary = $DB->get_record("glossary", array("id"=>$cm->instance))) {
-    print_error('invalidcousemodule');
-}
-
-if (! $entry = $DB->get_record("glossary_entries", array("id"=>$eid))) {
-    print_error('invalidentry');
-}
-
-$context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
-require_login($course->id, false, $cm);
-
-add_to_log($course->id, "glossary", "view", "view.php?id=$cm->id", "$glossary->id",$cm->id);
-
-$strglossaries = get_string("modulenameplural", "glossary");
-$strglossary = get_string("modulename", "glossary");
-$strallcategories = get_string("allcategories", "glossary");
-$straddentry = get_string("addentry", "glossary");
-$strnoentries = get_string("noentries", "glossary");
-$strsearchconcept = get_string("searchconcept", "glossary");
-$strsearchindefinition = get_string("searchindefinition", "glossary");
-$strsearch = get_string("search");
-$strcomments = get_string("comments", "glossary");
-$straddcomment = get_string("addcomment", "glossary");
-
-$PAGE->navbar->add($strcomments);
-$PAGE->set_title(strip_tags("$strcomments: $entry->concept"));
-$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'glossary'));
-echo $OUTPUT->header();
-
-/// original glossary entry
-
-echo "<div class=\"boxaligncenter\">";
-glossary_print_entry($course, $cm, $glossary, $entry, "", "", false);
-echo "</div>";
-
-/// comments
-
-echo $OUTPUT->heading(format_string(get_string('commentson','glossary')." <b>\"$entry->concept\"</b>"));
-
-if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
-    echo $OUTPUT->heading("<a href=\"comment.php?action=add&amp;entryid=$entry->id\">$straddcomment <img title=\"$straddcomment\" src=\"comment.gif\" class=\"iconsmall\" alt=\"$straddcomment\" /></a>");
-}
-
-if ($comments = $DB->get_records("glossary_comments", array("entryid"=>$entry->id), "timemodified ASC")) {
-    foreach ($comments as $comment) {
-        glossary_print_comment($course, $cm, $glossary, $entry, $comment);
-        echo '<br />';
-    }
-} else {
-    echo $OUTPUT->heading(get_string("nocomments","glossary"));
-}
-
-
-/// Finish the page
-
-echo $OUTPUT->footer();
-
index 33ad579511aa5fc175a3d52f828436f692a1995e..e5e98281ee63237c14ce0b948a828d12578741fa 100644 (file)
@@ -18,9 +18,6 @@ function xmldb_glossary_install() {
     update_log_display_entry('glossary', 'add category', 'glossary', 'name');
     update_log_display_entry('glossary', 'update category', 'glossary', 'name');
     update_log_display_entry('glossary', 'delete category', 'glossary', 'name');
-    update_log_display_entry('glossary', 'add comment', 'glossary', 'name');
-    update_log_display_entry('glossary', 'update comment', 'glossary', 'name');
-    update_log_display_entry('glossary', 'delete comment', 'glossary', 'name');
     update_log_display_entry('glossary', 'approve entry', 'glossary', 'name');
     update_log_display_entry('glossary', 'view entry', 'glossary_entries', 'concept');
 
index 00e063465c1f060e2aeb15c8d66f2124e7cc456e..880531e102b7210cbf4a95b055b0ff3064d3d2a7 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/glossary/db" VERSION="20090420" COMMENT="XMLDB file for Moodle mod/glossary"
+<XMLDB PATH="mod/glossary/db" VERSION="20090925" COMMENT="XMLDB file for Moodle mod/glossary"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
 >
@@ -91,7 +91,7 @@
         <KEY NAME="glossaryid" TYPE="foreign" FIELDS="glossaryid" REFTABLE="glossary" REFFIELDS="id" PREVIOUS="primary"/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="glossary_entries_categories" COMMENT="categories of each glossary entry" PREVIOUS="glossary_categories" NEXT="glossary_comments">
+    <TABLE NAME="glossary_entries_categories" COMMENT="categories of each glossary entry" PREVIOUS="glossary_categories" NEXT="glossary_formats">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="categoryid"/>
         <FIELD NAME="categoryid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="entryid"/>
         <KEY NAME="entryid" TYPE="foreign" FIELDS="entryid" REFTABLE="glossary_entries" REFFIELDS="id" PREVIOUS="categoryid"/>
       </KEYS>
     </TABLE>
-    <TABLE NAME="glossary_comments" COMMENT="comments on glossary entries" PREVIOUS="glossary_entries_categories" NEXT="glossary_formats">
-      <FIELDS>
-        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="entryid"/>
-        <FIELD NAME="entryid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="userid"/>
-        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="entryid" NEXT="entrycomment"/>
-        <FIELD NAME="entrycomment" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="userid" NEXT="entrycommentformat"/>
-        <FIELD NAME="entrycommentformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="entrycomment" NEXT="entrycommenttrust"/>
-        <FIELD NAME="entrycommenttrust" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="entrycommentformat" NEXT="timemodified"/>
-        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="entrycommenttrust"/>
-      </FIELDS>
-      <KEYS>
-        <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="entryid"/>
-        <KEY NAME="entryid" TYPE="foreign" FIELDS="entryid" REFTABLE="glossary_entries" REFFIELDS="id" PREVIOUS="primary"/>
-      </KEYS>
-      <INDEXES>
-        <INDEX NAME="userid" UNIQUE="false" FIELDS="userid"/>
-      </INDEXES>
-    </TABLE>
-    <TABLE NAME="glossary_formats" COMMENT="Setting of the display formats" PREVIOUS="glossary_comments" NEXT="glossary_ratings">
+    <TABLE NAME="glossary_formats" COMMENT="Setting of the display formats" PREVIOUS="glossary_entries_categories" NEXT="glossary_ratings">
       <FIELDS>
         <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="name"/>
         <FIELD NAME="name" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" PREVIOUS="id" NEXT="popupformatname"/>
index 61e90844a400f3c5f53288003645c3bababb2001..9d0fd5c6b8f96f4459833b2796e940f710a14d46 100644 (file)
@@ -204,6 +204,55 @@ function xmldb_glossary_upgrade($oldversion) {
     /// glossary savepoint reached
         upgrade_mod_savepoint($result, 2009042006, 'glossary');
     }
+    if ($result && $oldversion < 2009110800) {
+        require_once($CFG->libdir . '/commentlib.php');
+    /// Define table glossary_comments to be dropped
+        $table = new xmldb_table('glossary_comments');
+
+    /// Conditionally launch drop table for glossary_comments
+        if ($dbman->table_exists($table)) {
+            $sql = 'SELECT e.glossaryid AS glossaryid,
+                g.course AS courseid,
+                e.id AS itemid,
+                c.id AS old_id,
+                c.entrycomment AS comment,
+                c.entrycommentformat AS format,
+                c.entrycommenttrust AS trust,
+                c.timemodified AS timemodified
+                FROM {glossary_comments} c, {glossary_entries} e, {glossary} g
+                WHERE c.entryid=e.id AND e.glossaryid=g.id';
+        /// move glossary comments to new comments table
+            $error = false;
+            if ($rs = $DB->get_recordset_sql($sql)) {
+                foreach($rs as $res) {
+                    if ($cm = get_coursemodule_from_instance('glossary', $res->glossaryid, $res->courseid)) {
+                        $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+                        $cmt = new stdclass;
+                        $cmt->contextid = $context->id;
+                        $cmt->courseid  = $res->courseid;
+                        $cmt->area      = 'glossary_entry';
+                        $cmt->itemid    = $res->itemid;
+                        $comment = new comment($cmt);
+                        try {
+                            $cmt = $comment->add($res->comment, $res->format);
+                        } catch (comment_exception $e) {
+                            add_to_log($res->courseid, 'comments', 'add', '', 'Cannot migrate glossary comment with ID# '.$res->old_id);
+                            $error = true;
+                        }
+                    }
+                }
+            }
+            if (empty($error)) {
+                $dbman->drop_table($table);
+            } else {
+                print_error('error');
+            }
+        }
+
+    /// glossary savepoint reached
+        upgrade_mod_savepoint($result, 2009110800, 'glossary');
+    }
 
     return $result;
 }
index 5cc13c0b944ef1c081753053be0d3ca9ce260f49..674f017c801691b3895feae14e563e7861dfd280 100644 (file)
@@ -92,7 +92,7 @@ if ($confirm and confirm_sesskey()) { // the operation was confirmed.
     } else {
         $fs = get_file_storage();
         $fs->delete_area_files($context->id, 'glossary_attachment', $entry->id);
-        $DB->delete_records("glossary_comments", array("entryid"=>$entry->id));
+        $DB->delete_records("comments", array('itemid'=>$entry->id, 'commentarea'=>'glossary_entry', 'contextid'=>$context->id));
         $DB->delete_records("glossary_alias", array("entryid"=>$entry->id));
         $DB->delete_records("glossary_ratings", array("entryid"=>$entry->id));
         $DB->delete_records("glossary_entries", array("id"=>$entry->id));
@@ -115,4 +115,3 @@ if ($confirm and confirm_sesskey()) { // the operation was confirmed.
 
     echo $OUTPUT->footer();
 }
-
index 934abf379772b4da9406c90878a64f2fdf2aeadd..5f32cdb1f0654f44db83409bb8e3dfeacc723f7d 100644 (file)
@@ -198,7 +198,7 @@ function glossary_delete_instance($id) {
 
     // Delete any dependent records
     $entry_select = "SELECT id FROM {glossary_entries} WHERE glossaryid = ?";
-    $DB->delete_records_select('glossary_comments', "entryid IN ($entry_select)", array($id));
+    $DB->delete_records_select('comments', "contextid={$context->id} AND commentarea='glossary_entry' AND itemid IN ($entry_select)", array($id));
     $DB->delete_records_select('glossary_alias',    "entryid IN ($entry_select)", array($id));
     $DB->delete_records_select('glossary_ratings',  "entryid IN ($entry_select)", array($id));
 
@@ -948,13 +948,6 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
         $output = true;
         $return .= get_string('entryishidden','glossary');
     }
-    $return .= glossary_print_entry_commentslink($course, $cm, $glossary, $entry,$mode,$hook,'html');
-
-    if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
-        $output = true;
-        $return .= ' <a title="' . get_string('addcomment','glossary') . '" href="comment.php?action=add&amp;entryid='.$entry->id.'"><img src="comment.gif" class="iconsmall" alt="'.get_string('addcomment','glossary').$altsuffix.'" /></a>';
-    }
-
 
     if (has_capability('mod/glossary:manageentries', $context) or (!empty($USER->id) and has_capability('mod/glossary:write', $context) and $entry->userid == $USER->id)) {
         // only teachers can export entries so check it out
@@ -998,6 +991,21 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
 
     $return .= '</span>';
 
+    if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) {
+        $output = true;
+        if (!empty($CFG->usecomments)) {
+            require_once($CFG->libdir . '/commentlib.php');
+            $cmt = new stdclass;
+            $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+            $cmt->area    = 'glossary_entry';
+            $cmt->context = $modcontext;
+            $cmt->itemid  = $entry->id;
+            $cmt->showcount = true;
+            $comment = new comment($cmt);
+            $return .= '<div style="width:500px">'.$comment->init(true).'</div>';
+        }
+    }
+
     //If we haven't calculated any REAL thing, delete result ($return)
     if (!$output) {
         $return = '';
@@ -1010,41 +1018,6 @@ function glossary_print_entry_icons($course, $cm, $glossary, $entry, $mode='',$h
     }
 }
 
-/**
- * @global object
- * @param object $course
- * @param object $cm
- * @param object $glossary
- * @param object $entry
- * @param string $mode
- * @param string $hook
- * @param string $type
- * @return string|void
- */
-function glossary_print_entry_commentslink($course, $cm, $glossary, $entry,$mode,$hook, $type = 'print') {
-    global $DB;
-
-    $return = '';
-
-    $count = $DB->count_records('glossary_comments', array('entryid'=>$entry->id));
-    if ($count) {
-        $return = '';
-        $return .= "<a href=\"comments.php?id=$cm->id&amp;eid=$entry->id\">$count ";
-        if ($count == 1) {
-            $return .= get_string('comment', 'glossary');
-        } else {
-            $return .= get_string('comments', 'glossary');
-        }
-        $return .= '</a>';
-    }
-
-    if ($type == 'print') {
-        echo $return;
-    } else {
-        return $return;
-    }
-}
-
 /**
  * @param object $course
  * @param object $cm
@@ -1748,65 +1721,6 @@ function glossary_sort_entries ( $entry0, $entry1 ) {
     }
 }
 
-/**
- * @global object
- * @global object
- * @global object
- * @param object $course
- * @param object $cm
- * @param object $glossary
- * @param object $entry
- * @param object $comment
- */
-function glossary_print_comment($course, $cm, $glossary, $entry, $comment) {
-    global $CFG, $USER, $DB, $OUTPUT;
-
-    $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
-    $user = $DB->get_record('user', array('id'=>$comment->userid));
-    $strby = get_string('writtenby','glossary');
-    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
-
-    echo '<div class="boxaligncenter">';
-    echo '<table class="glossarycomment" cellspacing="0">';
-    echo '<tr valign="top">';
-    echo '<td class="left picture">';
-    echo $OUTPUT->user_picture(moodle_user_picture::make($user, $course->id));
-    echo '</td>';
-    echo '<td class="entryheader">';
-
-    $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)));
-    $by = new object();
-    $by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&amp;course='.$course->id.'">'.$fullname.'</a>';
-    $by->date = userdate($comment->timemodified);
-    echo '<span class="author">'.get_string('bynameondate', 'forum', $by).'</span>';
-
-    echo '</td></tr>';
-
-    echo '<tr valign="top"><td class="left side">';
-    echo '&nbsp;';
-    echo '</td><td class="entry">';
-
-    $options = new object();
-    $options->trusted = $comment->entrycommenttrust;
-    echo format_text($comment->entrycomment, $comment->entrycommentformat, $options);
-
-    echo '<div class="icons commands">';
-
-    $ineditperiod = ((time() - $comment->timemodified <  $CFG->maxeditingtime) || $glossary->editalways);
-    if ( ($glossary->allowcomments &&  $ineditperiod && $USER->id == $comment->userid)  || has_capability('mod/glossary:managecomments', $context)) {
-        echo "<a href=\"comment.php?id=$comment->id&amp;action=edit\"><img
-               alt=\"" . get_string("edit") . "\" src=\"" . $OUTPUT->old_icon_url('t/edit') . "\" class=\"iconsmall\" /></a> ";
-    }
-    if ( ($glossary->allowcomments && $USER->id == $comment->userid) || has_capability('mod/glossary:managecomments', $context) ) {
-        echo "<a href=\"comment.php?id=$comment->id&amp;action=delete\"><img
-               alt=\"" . get_string("delete") . "\" src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" /></a>";
-    }
-
-    echo '</div></td></tr>';
-    echo '</table></div>';
-
-}
 
 /**
  * @global object
@@ -2495,7 +2409,7 @@ function glossary_get_view_actions() {
  * @return array
  */
 function glossary_get_post_actions() {
-    return array('add category','add comment','add entry','approve entry','delete category','delete comment','delete entry','edit category','update comment','update entry');
+    return array('add category','add entry','approve entry','delete category','delete entry','edit category','update entry');
 }
 
 
@@ -2589,7 +2503,8 @@ function glossary_reset_userdata($data) {
          or (!empty($data->reset_glossary_types) and in_array('main', $data->reset_glossary_types) and in_array('secondary', $data->reset_glossary_types))) {
 
         $DB->delete_records_select('glossary_ratings', "entryid IN ($allentriessql)", $params);
-        $DB->delete_records_select('glossary_comments', "entryid IN ($allentriessql)", $params);
+        // TODO: delete comments 
+        //$DB->delete_records_select('comments', "entryid IN ($allentriessql)", array());
         $DB->delete_records_select('glossary_entries', "glossaryid IN ($allglossariessql)", $params);
 
         // now get rid of all attachments
@@ -2706,7 +2621,7 @@ function glossary_reset_userdata($data) {
         $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallratings'), 'error'=>false);
     }
 
-    // remove all comments
+    // TODO: remove all comments
     if (!empty($data->reset_glossary_comments)) {
         $DB->delete_records_select('glossary_comments', "entryid IN ($allentriessql)", $params);
         $status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
index 9d8d4d3f7502a08c40888745ff4521dd3e385686..360bc0e0eeb5bb89febb5aa659760a94b5f8bcc7 100644 (file)
                     //Restore glossary_alias
                     $status = glossary_alias_restore_mods($oldid,$newid,$ent_info,$restore);
                     //Now restore glossary_comments
-                    $status = glossary_comments_restore_mods($oldid,$newid,$ent_info,$restore);
+                    $status = glossary_comments_restore_mods($oldid,$newid,$old_glossary_id,$new_glossary_id,$ent_info,$restore);
                     //Now restore glossary_ratings
                     $status = glossary_ratings_restore_mods($oldid,$newid,$ent_info,$restore);
                     //Now copy moddata associated files if needed
     }
 
     //This function restores the glossary_comments
-    function glossary_comments_restore_mods($old_entry_id,$new_entry_id,$info,$restore) {
+    function glossary_comments_restore_mods($old_entry_id,$new_entry_id,$old_gid,$new_gid,$info,$restore) {
         global $CFG, $DB;
 
         $status = true;
 
+        $newmodcontext = restore_get_new_context($restore, 'course_modules', CONTEXT_MODULE, $old_gid);
+
+
         //Get the comments array
         $comments = isset($info['#']['COMMENTS']['0']['#']['COMMENT'])?$info['#']['COMMENTS']['0']['#']['COMMENT']:array();
 
             $oldid = backup_todb($com_info['#']['ID']['0']['#']);
 
             //Now, build the GLOSSARY_COMMENTS record structure
-            $comment->entryid = $new_entry_id;
-            $comment->userid = backup_todb($com_info['#']['USERID']['0']['#']);
+            $comment->itemid = $new_entry_id;
             if (isset($com_info['#']['COMMENT']['0']['#'])) {
-                $comment->entrycomment = backup_todb($com_info['#']['COMMENT']['0']['#']);
+                $comment->content = backup_todb($com_info['#']['COMMENT']['0']['#']);
             } else {
-                $comment->entrycomment = backup_todb($com_info['#']['ENTRYCOMMENT']['0']['#']);
+                $comment->content = backup_todb($com_info['#']['ENTRYCOMMENT']['0']['#']);
             }
-            $comment->timemodified = backup_todb($com_info['#']['TIMEMODIFIED']['0']['#']);
-            $comment->entrycommentformat = backup_todb($com_info['#']['FORMAT']['0']['#']);
+            $comment->userid = backup_todb($com_info['#']['USERID']['0']['#']);
+            $comment->timecreated = backup_todb($com_info['#']['TIMECREATED']['0']['#']);
+            $comment->format = backup_todb($com_info['#']['FORMAT']['0']['#']);
+            $comment->commentarea = backup_todb($com_info['#']['COMMENTAREA']['0']['#']);
+            $comment->contextid = $newmodcontext->id;
 
             //We have to recode the userid field
             $user = backup_getid($restore->backup_unique_code,"user",$comment->userid);
             }
 
             //The structure is equal to the db, so insert the glossary_comments
-            $newid = $DB->insert_record ("glossary_comments",$comment);
+            $newid = $DB->insert_record ("comments", $comment);
 
             //Do some output
             if (($i+1) % 50 == 0) {
index 7643837617d4b29e4c7c0b7b639def043276a620..f6c5bb1192c8200db0a4f6aafd9e38762f88e4d4 100644 (file)
@@ -5,7 +5,7 @@
 ///  This fragment is called by moodle_needs_upgrading() and /admin/index.php
 /////////////////////////////////////////////////////////////////////////////////
 
-$module->version  = 2009042006;
+$module->version  = 2009110800;
 $module->requires = 2009041700;  // Requires this Moodle version
 $module->cron     = 0;           // Period for cron to check this module (secs)
 
index 5f4a6f03e1c9d6426a67d698189e907f2e91e1e5..f1d3fdb04d34915f69715b20c7a5fc7c460690e0 100644 (file)
@@ -49,6 +49,8 @@ if (!empty($id)) {
 require_course_login($course->id, true, $cm);
 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
 
+    require_once($CFG->libdir . '/commentlib.php');
+    comment::js();
 /// Loading the textlib singleton instance. We are going to need it.
 $textlib = textlib_get_instance();