Skip to content

Commit

Permalink
MDL-19676 Removed blog assignment code
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasconnault committed Sep 11, 2009
1 parent b5c8422 commit 5f4d4d8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 516 deletions.
30 changes: 0 additions & 30 deletions backup/backuplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -947,19 +947,6 @@ function backup_blogs($bf, $preferences) {
}


function backup_course_blogs($bf, $preferences) {
global $DB;
fwrite ($bf, start_tag("BLOGS",2,true));

$sql = 'SELECT as.data1 FROM {assignment} a, {assignment_submissions} as WHERE
as.assignment = a.id AND a.assignmenttype = \'blog\' AND a.course = ?';
$records = $DB->get_records_sql($sql, array($preferences->backup_course));
foreach ($records as $rec) {
backup_blog($bf, $rec->data1, 3);
}
fwrite($bf, end_tag("BLOGS",2,true));
}

function backup_blog($bf, $blogid, $level) {
global $DB;
$blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid));
Expand Down Expand Up @@ -3372,23 +3359,6 @@ function backup_execute(&$preferences, &$errorstr) {
}
}

//Backup course blog assignment data, if any.
if (!defined('BACKUP_SILENTLY')) {
echo '<li>'.get_string("courseblogdata").'</li>';
}
if($status) {
if (!$status = backup_course_blogs($backup_file,$preferences)) {
if (!defined('BACKUP_SILENTLY')) {
notify("An error occurred while backing up the course blog assignment data");
}
else {
$errorstr = "An error occurred while backing up the course blog assignment data";
return false;
}
}
}


//Prints course end
if ($status) {
if (!$status = backup_course_end($backup_file,$preferences)) {
Expand Down
7 changes: 1 addition & 6 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@
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) {
Expand All @@ -143,7 +138,7 @@
}

$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());

Expand Down
128 changes: 17 additions & 111 deletions blog/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,14 @@ function definition() {
$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');
Expand All @@ -68,21 +47,14 @@ function definition() {

$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++;
}

Expand All @@ -106,31 +78,31 @@ function definition() {
$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);
Expand Down Expand Up @@ -158,22 +130,6 @@ function definition() {
$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);
}

Expand All @@ -182,60 +138,10 @@ function validation($data, $files) {

$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));
Expand All @@ -261,7 +167,7 @@ function validation($data, $files) {
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'])) {
Expand Down
Loading

0 comments on commit 5f4d4d8

Please sign in to comment.