MDL-19676 Removed blog assignment code

This commit is contained in:
nicolasconnault 2009-09-11 01:45:16 +00:00
parent b5c8422581
commit 5f4d4d801c
6 changed files with 41 additions and 516 deletions

View file

@ -120,11 +120,6 @@ if ($action === 'delete'){
require_once('edit_form.php');
if (!empty($existing)) {
$assignmentdata = $DB->get_record_sql('SELECT a.timedue, a.preventlate, a.emailteachers, a.var2, asub.grade
FROM {assignment} a, {assignment_submissions} as asub WHERE
a.id = asub.assignment AND userid = '.$USER->id.' AND a.assignmenttype = \'blog\'
AND asub.data1 = \''.$existing->id.'\'');
if ($blogassociations = $DB->get_records('blog_association', array('blogid' => $existing->id))) {
foreach ($blogassociations as $assocrec) {
@ -143,7 +138,7 @@ if (!empty($existing)) {
}
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
$blogeditform = new blog_edit_form(null, compact('existing', 'sitecontext', 'assignmentdata', 'textfieldoptions', 'id'));
$blogeditform = new blog_edit_form(null, compact('existing', 'sitecontext', 'textfieldoptions', 'id'));
$existing = file_prepare_standard_editor($existing, 'summary', $textfieldoptions, $PAGE->get_context());

View file

@ -29,35 +29,14 @@ class blog_edit_form extends moodleform {
$entryid = $this->_customdata['id'];
$summaryoptions = $this->_customdata['textfieldoptions'];
if (!empty($this->_customdata['assignmentdata'])) {
$assignmentdata = $this->_customdata['assignmentdata'];
}
$existing = $this->_customdata['existing'];
$sitecontext = $this->_customdata['sitecontext'];
//determine if content elements should be deactivated for a past due blog assignment
$noedit = false;
if (!empty($assignmentdata)) {
if ((time() > $assignmentdata->timedue && $assignmentdata->preventlate) || $assignmentdata->grade != -1) {
$noedit = true;
}
}
$mform->addElement('header', 'general', get_string('general', 'form'));
if ($noedit) { //show disabled form elements, but provide hidden elements so that the data is transferred
$mform->addElement('text', 'fakesubject', get_string('entrytitle', 'blog'), array('size'=>60, 'disabled'=>'disabled'));
$mform->addElement('textarea', 'fakesummary', get_string('entrybody', 'blog'), array('rows'=>25, 'cols'=>40, 'disabled'=>'disabled'));
$mform->setHelpButton('fakesummary', array('writing', 'richtext'), false, 'editorhelpbutton');
$mform->addElement('hidden', 'subject');
$mform->addElement('hidden', 'summary');
} else { //insert normal form elements
$mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
$mform->addElement('editor', 'summary_editor', get_string('entrybody', 'blog'), null, $summaryoptions);
}
$mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
$mform->addElement('editor', 'summary_editor', get_string('entrybody', 'blog'), null, $summaryoptions);
$mform->setType('subject', PARAM_TEXT);
$mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
@ -68,21 +47,14 @@ class blog_edit_form extends moodleform {
$mform->addElement('format', 'format', get_string('format'));
$mform->addElement('filepicker', 'attachment', get_string('attachment', 'forum'), null, array('filetypes' => '*'));
$mform->addElement('file', 'attachment', get_string('attachment', 'forum'));
//disable publishstate options that are not allowed
$publishstates = array();
$i = 0;
foreach (blog_entry::get_applicable_publish_states() as $state => $desc) {
if (!empty($assignmentdata)) {
if ($i <= $assignmentdata->var2) { //var2 is the maximum publish state allowed
$publishstates[$state] = $desc;
}
} else {
$publishstates[$state] = $desc; //no maximum was set
}
$publishstates[$state] = $desc; //no maximum was set
$i++;
}
@ -106,31 +78,31 @@ class blog_edit_form extends moodleform {
$courses = get_my_courses($USER->id, 'visible DESC, fullname ASC');
}
$course_names[0] = 'none';
$coursenames[0] = 'none';
if (!empty($courses)) {
foreach ($courses as $course) {
$course_names[$course->context->id] = $course->fullname;
$coursenames[$course->context->id] = $course->fullname;
$modinfo = get_fast_modinfo($course, $USER->id);
$course_context_path = $DB->get_field('context', 'path', array('id' => $course->context->id));
$coursecontextpath = $DB->get_field('context', 'path', array('id' => $course->context->id));
foreach ($modinfo->instances as $modname => $instances) {
foreach ($instances as $modid => $mod) {
$mod_context_id = $DB->get_field_select('context', 'id',
$modcontextid = $DB->get_field_select('context', 'id',
'instanceid = '.$mod->id.' AND ' .
'contextlevel = ' . CONTEXT_MODULE . ' AND ' .
'path LIKE \''.$course_context_path.'/%\'');
'path LIKE \''.$coursecontextpath.'/%\'');
$mod_string = $mod->name . ' (' . get_plugin_name($modname) . ')';
$this->modnames[$course->context->id][$mod_context_id] = $mod_string;
$allmodnames[$mod_context_id] = $course->shortname . " - " . $mod_string;
$modstring = $mod->name . ' (' . get_plugin_name($modname) . ')';
$this->modnames[$course->context->id][$modcontextid] = $modstring;
$allmodnames[$modcontextid] = $course->shortname . " - " . $modstring;
}
}
}
}
$mform->addElement('select', 'courseassoc', get_string('course'), $course_names, 'onchange="addCourseAssociations()"');
$mform->addElement('select', 'courseassoc', get_string('course'), $coursenames, 'onchange="addCourseAssociations()"');
$selectassoc = &$mform->addElement('select', 'modassoc', get_string('managemodules'), $allmodnames);
$selectassoc->setMultiple(true);
$PAGE->requires->data_for_js('blog_edit_form_modnames', $this->modnames);
@ -158,22 +130,6 @@ class blog_edit_form extends moodleform {
$mform->setType('courseid', PARAM_INT);
$mform->setDefault('courseid', 0);
if (!empty($assignmentdata)) { //dont allow associations for blog assignments
$courseassoc = $mform->getElement('courseassoc');
$modassoc = $mform->getElement('modassoc');
$courseassoc->updateAttributes(array('disabled' => 'disabled'));
$modassoc->updateAttributes(array('disabled' => 'disabled'));
}
if ($noedit) { //disable some other fields when editing is not allowed
$subject = $mform->getElement('subject');
$summary = $mform->getElement('summary');
$attachment = $mform->getElement('attachment');
$format = $mform->getElement('format');
$attachment->updateAttributes(array('disabled' => 'disabled'));
$format->updateAttributes(array('disabled' => 'disabled'));
}
$this->set_data($existing);
}
@ -182,60 +138,10 @@ class blog_edit_form extends moodleform {
$errors = array();
//check to see if it's part of a submitted blog assignment
if ($blogassignment = $DB->get_record_sql('SELECT a.timedue, a.preventlate, a.emailteachers, a.var2, asub.grade
FROM {assignment} a, {assignment_submissions} as asub WHERE
a.id = asub.assignment AND userid = '.$USER->id.' AND a.assignmenttype = \'blog\'
AND asub.data1 = \''.$data['entryid'].'\'')) {
$original = $DB->get_record('post', array('id' => $data['entryid']));
//don't allow updates of the summary, subject, or attachment
$changed = ($original->summary != $data['summary'] ||
$original->subject != $data['subject'] ||
!empty($files));
//determine numeric value for publish state (for comparison purposes)
$postaccess = -1;
$i=0;
foreach (blog_applicable_publish_states() as $state => $desc) {
if ($state == $data['publishstate']) {
$postaccess = $i;
}
$publishstates[$i++] = $state;
}
//send an error if improper changes are being made
if (($changed and time() > $blogassignment->timedue and $blogassignment->preventlate = 1) or
($changed and $blogassignment->grade != -1) or
(time() < $blogassignment->timedue and ($postaccess > $blogassignment->var2 || $postaccess == -1))) {
//too late to edit this entry
if ($original->subject != $data['subject']) {
$errors['subject'] = get_string('canteditblogassignment', 'blog');
}
if ($original->summary != $data['summary']) {
$errors['summary'] = get_string('canteditblogassignment', 'blog');
}
if (!empty($files)) {
$errors['attachment'] = get_string('canteditblogassignment', 'blog');
}
}
//insure the publishto value is within proper constraints
if (time() < $blogassignment->timedue and ($postaccess > $blogassignment->var2 || $postaccess == -1)) {
$errors['publishto'] = get_string('canteditblogassignment', 'blog');
}
} else {
if (empty($data['courseassoc']) && ($data['publishstate'] == 'course' || $data['publishstate'] == 'group') && !empty($CFG->useblogassociations)) {
return array('publishstate' => get_string('mustassociatecourse', 'blog'));
}
if (empty($data['courseassoc']) && ($data['publishstate'] == 'course' || $data['publishstate'] == 'group') && !empty($CFG->useblogassociations)) {
return array('publishstate' => get_string('mustassociatecourse', 'blog'));
}
//validate course association
if (!empty($data['courseassoc'])) {
$coursecontext = $DB->get_record('context', array('id' => $data['courseassoc'], 'contextlevel' => CONTEXT_COURSE));
@ -261,7 +167,7 @@ class blog_edit_form extends moodleform {
if ($modcontext) { //insure associated mod has a valid context id
//get context of the mod's course
$path = split('/', $modcontext->path);
$coursecontext = $DB->get_record('context', array('id' => $path[3]));
$coursecontext = $DB->get_record('context', array('id' => $path[(count($path) - 2)]));
//insure only one course is associated
if (!empty($data['courseassoc'])) {

View file

@ -169,7 +169,7 @@ class blog_entry {
}
//retrieve associations in case they're needed early
$blog_associations = $DB->get_records('blog_association', array('blogid' => $this->id));
$blogassociations = $DB->get_records('blog_association', array('blogid' => $this->id));
//determine text for publish state
switch ($template['publishstate']) {
case 'draft':
@ -211,25 +211,32 @@ class blog_entry {
}
//add associations
if (!empty($CFG->useblogassociations) && $blog_associations) {
if (!empty($CFG->useblogassociations) && $blogassociations) {
$contentcell->text .= $OUTPUT->container_start('tags');
$assoc_str = '';
$assocstr = '';
$hascourseassocs = false;
foreach ($blog_associations as $assoc_rec) { //first find and show the associated course
$context_rec = $DB->get_record('context', array('id' => $assoc_rec->contextid));
foreach ($blogassociations as $assocrec) { //first find and show the associated course
$context_rec = $DB->get_record('context', array('id' => $assocrec->contextid));
if ($context_rec->contextlevel == CONTEXT_COURSE) {
$associcon = new moodle_action_icon();
$associcon->link->url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $context_rec->instanceid));
$associcon->image->src = $OUTPUT->old_icon_url('i/course');
$associcon->linktext = $DB->get_field('course', 'shortname', array('id' => $context_rec->instanceid));
$assoc_str .= $OUTPUT->action_icon($associcon);
$assocstr .= $OUTPUT->action_icon($associcon);
$hascourseassocs = true;
}
}
foreach ($blog_associations as $assoc_rec) { //now show each mod association
$context_rec = $DB->get_record('context', array('id' => $assoc_rec->contextid));
foreach ($blogassociations as $assocrec) { //now show each mod association
$context_rec = $DB->get_record('context', array('id' => $assocrec->contextid));
if ($context_rec->contextlevel == CONTEXT_MODULE) {
if ($hascourseassocs) {
$assocstr .= ', ';
$hascourseassocs = false;
}
$modinfo = $DB->get_record('course_modules', array('id' => $context_rec->instanceid));
$modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
@ -237,13 +244,13 @@ class blog_entry {
$associcon->link->url = new moodle_url($CFG->wwwroot.'/mod/'.$modname.'/view.php', array('id' => $modinfo->id));
$associcon->image->src = $OUTPUT->mod_icon_url('icon', $modname);
$associcon->linktext = $DB->get_field($modname, 'name', array('id' => $modinfo->instance));
$assoc_str .= $OUTPUT->action_icon($associcon);
$assocstr .= $OUTPUT->action_icon($associcon);
$assocstr .= ', ';
$assoc_str .= ', ';
$assoc_str .= $OUTPUT->action_icon($associcon);
}
}
$contentcell->text .= get_string('associations', 'blog') . ': '. $assoc_str;
$assocstr = substr($assocstr, 0, -2);
$contentcell->text .= get_string('associations', 'blog') . ': '. $assocstr;
$contentcell->text .= $OUTPUT->container_end();
}
@ -258,13 +265,7 @@ class blog_entry {
if (blog_user_can_edit_entry($this)) {
$contentcell->text .= $OUTPUT->link(html_link::make(new moodle_url($CFG->wwwroot.'/blog/edit.php', array('action' => 'edit', 'entryid' => $this->id)), $stredit)) . ' | ';
if (!$DB->record_exists_sql('SELECT a.timedue, a.preventlate, a.emailteachers, a.var2, asub.grade
FROM {assignment} a, {assignment_submissions} as asub WHERE
a.id = asub.assignment AND userid = '.$USER->id.' AND a.assignmenttype = \'blog\'
AND asub.data1 = \''.$this->id.'\'')) {
$contentcell->text .= $OUTPUT->link(html_link::make(new moodle_url($CFG->wwwroot.'/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete)) . ' | ';
}
$contentcell->text .= $OUTPUT->link(html_link::make(new moodle_url($CFG->wwwroot.'/blog/edit.php', array('action' => 'delete', 'entryid' => $this->id)), $strdelete)) . ' | ';
}
$contentcell->text .= $OUTPUT->link(html_link::make(new moodle_url($CFG->wwwroot.'/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog')));
@ -348,21 +349,8 @@ class blog_entry {
$this->$var = $val;
}
//check to see if it's part of a submitted blog assignment
if ($blogassignment = $DB->get_record_sql("SELECT a.timedue, a.preventlate, a.emailteachers, a.var2, asi.grade, asi.id
FROM {assignment} a, {assignment_submissions} as asi WHERE
a.id = asi.assignment AND userid = ? AND a.assignmenttype = 'blog'
AND asi.data1 = ?", array($USER->id, $this->id))) {
//email teachers if necessary
if ($blogassignment->emailteachers) {
email_teachers($DB->get_record('assignment_submissions', array('id'=>$blogassignment['id'])));
}
} else {
//only update the attachment and associations if it is not a submitted assignment
if (!empty($CFG->useblogassociations)) {
$this->add_associations();
}
if (!empty($CFG->useblogassociations)) {
$this->add_associations();
}
$this->lastmodified = time();
@ -393,14 +381,6 @@ class blog_entry {
$returnurl = '';
//check to see if it's part of a submitted blog assignment
if ($blogassignment = $DB->get_record_sql("SELECT a.timedue, a.preventlate, a.emailteachers, asub.grade
FROM {assignment} a, {assignment_submissions} as asub WHERE
a.id = asub.assignment AND userid = ? AND a.assignmenttype = 'blog'
AND asub.data1 = ?", array($USER->id, $this->id))) {
print_error('cantdeleteblogassignment', 'blog', $returnurl);
}
$this->delete_attachments();
$DB->delete_records('post', array('id' => $this->id));

View file

@ -91,7 +91,7 @@ class bloglib_test extends UnitTestCaseUsingDatabase {
global $CFG, $PAGE, $OUTPUT;
$this->create_test_tables('post', 'tag', 'course', 'user', 'role', 'role_assignments', 'group', 'blog_associations',
'course_modules', 'role_capabilities', 'assignment', 'tag_correlation', 'tag_instance');
'course_modules', 'role_capabilities', 'tag_correlation', 'tag_instance');
$contexts = $this->load_test_data('context',
array('contextlevel', 'instanceid', 'path', 'depth'), array(