$string['cannotmapfield'] = 'Mapping collision detected - two fields maps to the same grade item $a';
$string['cannotmarktopic'] = 'Could not mark that topic for this course';
$string['cannotmetacourse'] = 'Cannot not add the selected course to this meta course!';
+$string['cannotmigratedatacomments'] = 'Cannot migrate data module comments';
$string['cannotmoverolewithid'] = 'Cannot move role with ID $a';
$string['cannotmodulename'] = 'Cannot get the module name in build navigation';
$string['cannotmoduletype'] = 'Cannot get the module type in build navigation';
global $CFG, $DB;
$status = true;
- $data_comments = $DB->get_records("data_comments", array("recordid"=>$recordid));
+
+ $lastrecord = $DB->get_record_sql('SELECT d.id AS dataid, d.course AS course FROM {data} d, {data_records} r
+ WHERE r.dataid = d.id AND r.id = ?', array($recordid));
+
+ $params = array();
+ $params[] = $recordid;
+ $sql = 'SELECT d.id, d.course FROM {data_records} r, {data} d WHERE r.dataid = d.id AND r.id=?';
+ $result = $DB->get_record_sql($sql, $params);
+ if ($cm = get_coursemodule_from_instance('data', $result->id, $result->course)) {
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ }
+ $data_comments = $DB->get_records('comments', array(
+ 'itemid'=>$recordid,
+ 'commentarea'=>'database_entry',
+ 'contextid'=>$context->id)
+ );
//If there is submissions
if ($data_comments) {
foreach ($data_comments as $com_sub) {
//Start submission
$status =fwrite ($bf,start_tag("COMMENT",7,true));
+
//Print submission contents
fwrite ($bf,full_tag("ID",8,false,$com_sub->id));
- fwrite ($bf,full_tag("RECORDID",8,false,$com_sub->recordid));
fwrite ($bf,full_tag("USERID",8,false,$com_sub->userid));
fwrite ($bf,full_tag("CONTENT",8,false,$com_sub->content));
- fwrite ($bf,full_tag("CREATED",8,false,$com_sub->created));
- fwrite ($bf,full_tag("MODIFIED",8,false,$com_sub->modified));
+ fwrite ($bf,full_tag("COMMENTAREA",8,false,'database_entry'));
+ fwrite ($bf,full_tag("FORMAT",8,false,$com_sub->format));
+ fwrite ($bf,full_tag("TIMECREATED",8,false,$com_sub->timecreated));
//End submission
+
$status =fwrite ($bf,end_tag("COMMENT",7,true));
}
//Write end tag
<?xml version="1.0" encoding="UTF-8" ?>
-<XMLDB PATH="mod/data/db" VERSION="20090420" COMMENT="XMLDB file for Moodle mod/data"
+<XMLDB PATH="mod/data/db" VERSION="20091006" COMMENT="XMLDB file for Moodle mod/data"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<KEY NAME="dataid" TYPE="foreign" FIELDS="dataid" REFTABLE="data" REFFIELDS="id" PREVIOUS="primary"/>
</KEYS>
</TABLE>
- <TABLE NAME="data_content" COMMENT="the content introduced in each record/fields" PREVIOUS="data_records" NEXT="data_comments">
+ <TABLE NAME="data_content" COMMENT="the content introduced in each record/fields" PREVIOUS="data_records" NEXT="data_ratings">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="fieldid"/>
<FIELD NAME="fieldid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="recordid"/>
<KEY NAME="fieldid" TYPE="foreign" FIELDS="fieldid" REFTABLE="data_fields" REFFIELDS="id" PREVIOUS="recordid"/>
</KEYS>
</TABLE>
- <TABLE NAME="data_comments" COMMENT="to comment data records" PREVIOUS="data_content" NEXT="data_ratings">
- <FIELDS>
- <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
- <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="recordid"/>
- <FIELD NAME="recordid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="userid" NEXT="content"/>
- <FIELD NAME="content" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="recordid" NEXT="format"/>
- <FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="content" NEXT="created"/>
- <FIELD NAME="created" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="format" NEXT="modified"/>
- <FIELD NAME="modified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="created"/>
- </FIELDS>
- <KEYS>
- <KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="recordid"/>
- <KEY NAME="recordid" TYPE="foreign" FIELDS="recordid" REFTABLE="data_records" REFFIELDS="id" PREVIOUS="primary"/>
- </KEYS>
- </TABLE>
- <TABLE NAME="data_ratings" COMMENT="to rate data records" PREVIOUS="data_comments">
+ <TABLE NAME="data_ratings" COMMENT="to rate data records" PREVIOUS="data_content">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="userid"/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="id" NEXT="recordid"/>
upgrade_mod_savepoint($result, 2009042000, 'data');
}
+ if ($result && $oldversion < 2009111700) {
+ require_once($CFG->libdir . '/commentlib.php');
+
+ /// Define table data_comments to be dropped
+ $table = new xmldb_table('data_comments');
+
+ /// Conditionally launch drop table for data_comments
+ if ($dbman->table_exists($table)) {
+ $sql = 'SELECT d.id AS dataid,
+ d.course AS courseid,
+ r.id AS itemid,
+ c.content AS comment,
+ c.format AS format,
+ c.created AS timemodified
+ FROM {data_comments} c, {data_records} r, {data} d
+ WHERE c.recordid=r.id AND r.dataid=d.id';
+ /// move data comments to new comments table
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ $error = false;
+ foreach($rs as $res) {
+ if ($cm = get_coursemodule_from_instance('data', $res->dataid, $res->courseid)) {
+ $context = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $cmt = new stdclass;
+ $cmt->contextid = $context->id;
+ $cmt->courseid = $res->courseid;
+ $cmt->area = 'database_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 data module comment with ID# '.$res->old_id);
+ $error = true;
+ }
+ }
+ }
+ }
+ if (empty($error)) {
+ $dbman->drop_table($table);
+ } else {
+ print_error('cannotmigratedatacomments');
+ }
+ }
+
+ /// data savepoint reached
+ upgrade_mod_savepoint($result, 2009111700, 'data');
+ }
return $result;
}
WHERE r.dataid = ? AND u.id = r.userid", array($dataid));
$comments = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
- FROM {user} u, {data_records} r, {data_comments} c
- WHERE r.dataid = ? AND u.id = r.userid AND r.id = c.recordid", array($dataid));
+ FROM {user} u, {data_records} r, {comments} c
+ WHERE r.dataid = ? AND u.id = r.userid AND r.id = c.itemid AND c.commentarea='database_entry'", array($dataid));
$ratings = $DB->get_records_sql("SELECT DISTINCT u.id, u.id
FROM {user} u, {data_records} r, {data_ratings} a
$patterns[]='##comments##';
if (($template == 'listtemplate') && ($data->comments)) {
- $comments = $DB->count_records('data_comments', array('recordid'=>$record->id));
- $replacement[] = '<a href="view.php?rid='.$record->id.'#comments">'.get_string('commentsn','data', $comments).'</a>';
+
+ if (!empty($CFG->usecomments)) {
+ require_once($CFG->libdir . '/commentlib.php');
+ $cmt = new stdclass;
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $cmt->area = 'database_entry';
+ $cmt->context = $context;
+ $cmt->itemid = $record->id;
+ $cmt->showcount = true;
+ $comment = new comment($cmt);
+ $replacement[] = $comment->init(true);
+ }
} else {
$replacement[] = '';
}
* Printing Ratings Form *
*********************************/
if (($template == 'singletemplate') && ($data->comments)) { //prints ratings options
-
- data_print_comments($data, $record, $page);
+ if (!empty($CFG->usecomments)) {
+ require_once($CFG->libdir . '/commentlib.php');
+ $cmt = new stdclass;
+ $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id);
+ $cmt->area = 'database_entry';
+ $cmt->context = $context;
+ $cmt->itemid = $record->id;
+ $cmt->showcount = true;
+ $comment = new comment($cmt);
+ $comment->init(false);
+ }
}
}
}
ORDER BY $sort", array($recordid));
}
-/**
- * Prints all comments + a text box for adding additional comment
- *
- * @global object
- * @global object
- * @param object $data
- * @param object $record
- * @param int $page
- * @param bool $mform
- * @return void Output is echo'd
- */
-function data_print_comments($data, $record, $page=0, $mform=false) {
- global $CFG, $DB;
-
- $cm = get_coursemodule_from_instance('data', $data->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
- $cancomment = has_capability('mod/data:comment', $context);
- echo '<a name="comments"></a>';
-
- if ($comments = $DB->get_records('data_comments', array('recordid'=>$record->id))) {
- foreach ($comments as $comment) {
- data_print_comment($data, $comment, $page);
- }
- echo '<br />';
- }
-
- if (!isloggedin() or has_capability('moodle/legacy:guest', get_context_instance(CONTEXT_SYSTEM), 0, false) or !$cancomment) {
- return;
- }
-
- $editor = optional_param('addcomment', 0, PARAM_BOOL);
-
- if (!$mform and !$editor) {
- echo '<div class="newcomment" style="text-align:center">';
- echo '<a href="view.php?d='.$data->id.'&rid='.$record->id.'&mode=single&addcomment=1">'.get_string('addcomment', 'data').'</a>';
- echo '</div>';
- } else {
- if (!$mform) {
- require_once('comment_form.php');
- $mform = new mod_data_comment_form('comment.php');
- $mform->set_data(array('mode'=>'add', 'page'=>$page, 'rid'=>$record->id));
- }
- echo '<div class="newcomment" style="text-align:center">';
- $mform->display();
- echo '</div>';
- }
-}
-
-/**
- * prints a single comment entry
- *
- * @global object
- * @global object
- * @global object
- * @uses CONTEXT_MODULE
- * @param object $data
- * @param string $comment
- * @param int $page
- * @return void Output is echo'd
- */
-function data_print_comment($data, $comment, $page=0) {
- global $USER, $CFG, $DB, $OUTPUT;
-
- $cm = get_coursemodule_from_instance('data', $data->id);
- $context = get_context_instance(CONTEXT_MODULE, $cm->id);
-
- $stredit = get_string('edit');
- $strdelete = get_string('delete');
-
- $user = $DB->get_record('user', array('id'=>$comment->userid));
-
- echo '<table cellspacing="0" align="center" width="50%" class="datacomment forumpost">';
-
- echo '<tr class="header"><td class="picture left">';
- echo $OUTPUT->user_picture(moodle_user_picture::make($user, $data->course));
- echo '</td>';
-
- echo '<td class="topic starter" align="left"><div class="author">';
- $fullname = fullname($user, has_capability('moodle/site:viewfullnames', $context));
- $by = new object();
- $by->name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.
- $user->id.'&course='.$data->course.'">'.$fullname.'</a>';
- $by->date = userdate($comment->modified);
- print_string('bynameondate', 'data', $by);
- echo '</div></td></tr>';
-
- echo '<tr><td class="left side">';
- if ($groups = groups_get_all_groups($data->course, $comment->userid, $cm->groupingid)) {
- print_group_picture($groups, $data->course, false, false, true);
- } else {
- echo ' ';
- }
-
-// Actual content
-
- echo '</td><td class="content" align="left">'."\n";
-
- // Print whole message
- echo format_text($comment->content, $comment->format);
-
-// Commands
-
- echo '<div class="commands">';
- if (data_isowner($comment->recordid) or has_capability('mod/data:managecomments', $context)) {
- echo '<a href="'.$CFG->wwwroot.'/mod/data/comment.php?rid='.$comment->recordid.'&mode=edit&commentid='.$comment->id.'&page='.$page.'">'.$stredit.'</a>';
- echo '| <a href="'.$CFG->wwwroot.'/mod/data/comment.php?rid='.$comment->recordid.'&mode=delete&commentid='.$comment->id.'&page='.$page.'">'.$strdelete.'</a>';
- }
-
- echo '</div>';
-
- echo '</td></tr></table>'."\n\n";
-}
-
-
/**
* For Participantion Reports
*
// delete entries if requested
if (!empty($data->reset_data)) {
$DB->delete_records_select('data_ratings', "recordid IN ($allrecordssql)", array($data->courseid));
- $DB->delete_records_select('data_comments', "recordid IN ($allrecordssql)", array($data->courseid));
+ $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
$DB->delete_records_select('data_content', "recordid IN ($allrecordssql)", array($data->courseid));
$DB->delete_records_select('data_records', "dataid IN ($alldatassql)", array($data->courseid));
if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted
or !has_capability('moodle/course:view', $course_context , $record->userid)) {
$DB->delete_records('data_ratings', array('recordid'=>$record->id));
- $DB->delete_records('data_comments', array('recordid'=>$record->id));
+ $DB->delete_records('comments', array('itemid'=>$record->id, 'commentarea'=>'database_entry'));
$DB->delete_records('data_content', array('recordid'=>$record->id));
$DB->delete_records('data_records', array('id'=>$record->id));
// HACK: this is ugly - the recordid should be before the fieldid!
// remove all comments
if (!empty($data->reset_data_comments)) {
- $DB->delete_records_select('data_comments', "recordid IN ($allrecordssql)", array($data->courseid));
+ $DB->delete_records_select('comments', "itemid IN ($allrecordssql) AND commentarea='database_entry'", array($data->courseid));
$status[] = array('component'=>$componentstr, 'item'=>get_string('deleteallcomments'), 'error'=>false);
}
$status = $status and data_content_restore_mods ($oldid, $newid, $old_data_id, $new_data_id, $rec_info, $restore);
$status = $status and data_ratings_restore_mods ($oldid, $newid, $info, $rec_info);
- $status = $status and data_comments_restore_mods ($oldid, $newid, $info, $rec_info);
+ $status = $status and data_comments_restore_mods ($oldid, $newid, $old_data_id, $new_data_id, $info, $rec_info);
} else {
$status = false;
return $status;
}
-function data_comments_restore_mods ($oldid, $newid, $info, $rec_info) {
+function data_comments_restore_mods ($oldid, $newid, $old_data_id, $new_data_id, $info, $rec_info) {
global $CFG, $DB;
$status = true;
+ $newmodcontext = restore_get_new_context($restore, 'course_modules', CONTEXT_MODULE, $old_gid);
+
$comments= $rec_info['#']['COMMENTS']['0']['#']['COMMENT'];
if (empty($comments)) { // no comments to restore
$com_info = $comments[$i];
- $comment -> recordid = $newid;
- $comment -> userid = backup_todb($com_info['#']['USERID']['0']['#']);
- $comment -> content = backup_todb($com_info['#']['CONTENT']['0']['#']);
- $comment -> created = backup_todb($com_info['#']['CREATED']['0']['#']);
- $comment -> modified = backup_todb($com_info['#']['MODIFIED']['0']['#']);
- $DB->insert_record("data_comments", $comment);
+ $comment->itemid = $newid;
+ $comment->contextid = $newmodcontext->id;
+ $comment->userid = backup_todb($com_info['#']['USERID']['0']['#']);
+ $comment->content = backup_todb($com_info['#']['CONTENT']['0']['#']);
+ $comment->commentarea = backup_todb($com_info['#']['COMMENTAREA']['0']['#']);
+ $comment->timecreated = backup_todb($com_info['#']['TIMECREATED']['0']['#']);
+ $user = backup_getid($restore->backup_unique_code,"user",$comment->userid);
+ if ($user) {
+ $comment->userid = $user->new_id;
+ }
+ $DB->insert_record("comments", $comment);
}
return $status;
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
-$module->version = 2009042000;
+$module->version = 2009111700;
$module->requires = 2009041700; // Requires this Moodle version
$module->cron = 60;
require_course_login($course, true, $cm);
+ require_once($CFG->libdir . '/commentlib.php');
+ comment::js();
+
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
require_capability('mod/data:viewentry', $context);