From: Dongsheng Cai Date: Sun, 8 Nov 2009 14:12:12 +0000 (+0000) Subject: "MDL-20345, use new comments api in glossary module" X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c8092ea5e368a4164b03912edc92296e015499a6;p=moodle.git "MDL-20345, use new comments api in glossary module" --- diff --git a/mod/glossary/backuplib.php b/mod/glossary/backuplib.php index f9fc4e55b9..cc9e64aa1c 100644 --- a/mod/glossary/backuplib.php +++ b/mod/glossary/backuplib.php @@ -217,8 +217,15 @@ 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) { @@ -226,9 +233,10 @@ 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 index 2d59774855..0000000000 --- a/mod/glossary/comment.php +++ /dev/null @@ -1,237 +0,0 @@ -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&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&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&eid=$entry->id", "$comment->id",$cm->id); - redirect("comments.php?id=$cm->id&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&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 index 14d0e1f52c..0000000000 --- a/mod/glossary/comment_form.php +++ /dev/null @@ -1,34 +0,0 @@ -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 index 70de4cccad..0000000000 --- a/mod/glossary/comments.php +++ /dev/null @@ -1,77 +0,0 @@ -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 "
"; -glossary_print_entry($course, $cm, $glossary, $entry, "", "", false); -echo "
"; - -/// comments - -echo $OUTPUT->heading(format_string(get_string('commentson','glossary')." \"$entry->concept\"")); - -if (has_capability('mod/glossary:comment', $context) and $glossary->allowcomments) { - echo $OUTPUT->heading("id\">$straddcomment \"$straddcomment\""); -} - -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 '
'; - } -} else { - echo $OUTPUT->heading(get_string("nocomments","glossary")); -} - - -/// Finish the page - -echo $OUTPUT->footer(); - diff --git a/mod/glossary/db/install.php b/mod/glossary/db/install.php index 33ad579511..e5e98281ee 100644 --- a/mod/glossary/db/install.php +++ b/mod/glossary/db/install.php @@ -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'); diff --git a/mod/glossary/db/install.xml b/mod/glossary/db/install.xml index 00e063465c..880531e102 100644 --- a/mod/glossary/db/install.xml +++ b/mod/glossary/db/install.xml @@ -1,5 +1,5 @@ - @@ -91,7 +91,7 @@ - +
@@ -103,25 +103,7 @@
- - - - - - - - - - - - - - - - - -
- +
diff --git a/mod/glossary/db/upgrade.php b/mod/glossary/db/upgrade.php index 61e90844a4..9d0fd5c6b8 100644 --- a/mod/glossary/db/upgrade.php +++ b/mod/glossary/db/upgrade.php @@ -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; } diff --git a/mod/glossary/deleteentry.php b/mod/glossary/deleteentry.php index 5cc13c0b94..674f017c80 100644 --- a/mod/glossary/deleteentry.php +++ b/mod/glossary/deleteentry.php @@ -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(); } - diff --git a/mod/glossary/lib.php b/mod/glossary/lib.php index 934abf3797..5f32cdb1f0 100644 --- a/mod/glossary/lib.php +++ b/mod/glossary/lib.php @@ -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 .= ' '.get_string('addcomment','glossary').$altsuffix.''; - } - 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 .= ''; + 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 .= '
'.$comment->init(true).'
'; + } + } + //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 .= "id&eid=$entry->id\">$count "; - if ($count == 1) { - $return .= get_string('comment', 'glossary'); - } else { - $return .= get_string('comments', 'glossary'); - } - $return .= ''; - } - - 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 '
'; - echo '
'; - echo ''; - echo ''; - echo ''; - - echo ''; - echo '
'; - echo $OUTPUT->user_picture(moodle_user_picture::make($user, $course->id)); - echo ''; - - $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); - $by = new object(); - $by->name = ''.$fullname.''; - $by->date = userdate($comment->timemodified); - echo ''.get_string('bynameondate', 'forum', $by).''; - - echo '
'; - echo ' '; - echo ''; - - $options = new object(); - $options->trusted = $comment->entrycommenttrust; - echo format_text($comment->entrycomment, $comment->entrycommentformat, $options); - - echo '
'; - - $ineditperiod = ((time() - $comment->timemodified < $CFG->maxeditingtime) || $glossary->editalways); - if ( ($glossary->allowcomments && $ineditperiod && $USER->id == $comment->userid) || has_capability('mod/glossary:managecomments', $context)) { - echo "id&action=edit\">\""old_icon_url('t/edit') . "\" class=\"iconsmall\" /> "; - } - if ( ($glossary->allowcomments && $USER->id == $comment->userid) || has_capability('mod/glossary:managecomments', $context) ) { - echo "id&action=delete\">\""old_icon_url('t/delete') . "\" class=\"iconsmall\" />"; - } - - echo '
'; - -} /** * @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); diff --git a/mod/glossary/restorelib.php b/mod/glossary/restorelib.php index 9d8d4d3f75..360bc0e0ee 100644 --- a/mod/glossary/restorelib.php +++ b/mod/glossary/restorelib.php @@ -205,7 +205,7 @@ //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 @@ -223,11 +223,14 @@ } //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(); @@ -242,15 +245,17 @@ $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); @@ -259,7 +264,7 @@ } //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) { diff --git a/mod/glossary/version.php b/mod/glossary/version.php index 7643837617..f6c5bb1192 100644 --- a/mod/glossary/version.php +++ b/mod/glossary/version.php @@ -5,7 +5,7 @@ /// This fragment is called by moodle_needs_upgrading() and /admin/index.php ///////////////////////////////////////////////////////////////////////////////// -$module->version = 2009042006; +$module->version = 2009110800; $module->requires = 2009041700; // Requires this Moodle version $module->cron = 0; // Period for cron to check this module (secs) diff --git a/mod/glossary/view.php b/mod/glossary/view.php index 5f4a6f03e1..f1d3fdb04d 100644 --- a/mod/glossary/view.php +++ b/mod/glossary/view.php @@ -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();