mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 08:26:37 +02:00
MDL-19676 Removed blog assignment code
This commit is contained in:
parent
b5c8422581
commit
5f4d4d801c
6 changed files with 41 additions and 516 deletions
|
@ -947,19 +947,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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) {
|
function backup_blog($bf, $blogid, $level) {
|
||||||
global $DB;
|
global $DB;
|
||||||
$blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid));
|
$blog = $DB->get_record('post', array('module'=>'blog', 'id'=>$blogid));
|
||||||
|
@ -3372,23 +3359,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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
|
//Prints course end
|
||||||
if ($status) {
|
if ($status) {
|
||||||
if (!$status = backup_course_end($backup_file,$preferences)) {
|
if (!$status = backup_course_end($backup_file,$preferences)) {
|
||||||
|
|
|
@ -120,11 +120,6 @@ if ($action === 'delete'){
|
||||||
require_once('edit_form.php');
|
require_once('edit_form.php');
|
||||||
|
|
||||||
if (!empty($existing)) {
|
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))) {
|
if ($blogassociations = $DB->get_records('blog_association', array('blogid' => $existing->id))) {
|
||||||
|
|
||||||
foreach ($blogassociations as $assocrec) {
|
foreach ($blogassociations as $assocrec) {
|
||||||
|
@ -143,7 +138,7 @@ if (!empty($existing)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
|
$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());
|
$existing = file_prepare_standard_editor($existing, 'summary', $textfieldoptions, $PAGE->get_context());
|
||||||
|
|
||||||
|
|
|
@ -29,35 +29,14 @@ class blog_edit_form extends moodleform {
|
||||||
$entryid = $this->_customdata['id'];
|
$entryid = $this->_customdata['id'];
|
||||||
$summaryoptions = $this->_customdata['textfieldoptions'];
|
$summaryoptions = $this->_customdata['textfieldoptions'];
|
||||||
|
|
||||||
if (!empty($this->_customdata['assignmentdata'])) {
|
|
||||||
$assignmentdata = $this->_customdata['assignmentdata'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$existing = $this->_customdata['existing'];
|
$existing = $this->_customdata['existing'];
|
||||||
$sitecontext = $this->_customdata['sitecontext'];
|
$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'));
|
$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"');
|
$mform->addElement('text', 'subject', get_string('entrytitle', 'blog'), 'size="60"');
|
||||||
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
|
$textfieldoptions = array('trusttext'=>true, 'subdirs'=>true);
|
||||||
$mform->addElement('editor', 'summary_editor', get_string('entrybody', 'blog'), null, $summaryoptions);
|
$mform->addElement('editor', 'summary_editor', get_string('entrybody', 'blog'), null, $summaryoptions);
|
||||||
}
|
|
||||||
|
|
||||||
$mform->setType('subject', PARAM_TEXT);
|
$mform->setType('subject', PARAM_TEXT);
|
||||||
$mform->addRule('subject', get_string('emptytitle', 'blog'), 'required', null, 'client');
|
$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('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
|
//disable publishstate options that are not allowed
|
||||||
$publishstates = array();
|
$publishstates = array();
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
foreach (blog_entry::get_applicable_publish_states() as $state => $desc) {
|
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++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,31 +78,31 @@ class blog_edit_form extends moodleform {
|
||||||
$courses = get_my_courses($USER->id, 'visible DESC, fullname ASC');
|
$courses = get_my_courses($USER->id, 'visible DESC, fullname ASC');
|
||||||
}
|
}
|
||||||
|
|
||||||
$course_names[0] = 'none';
|
$coursenames[0] = 'none';
|
||||||
|
|
||||||
if (!empty($courses)) {
|
if (!empty($courses)) {
|
||||||
|
|
||||||
foreach ($courses as $course) {
|
foreach ($courses as $course) {
|
||||||
$course_names[$course->context->id] = $course->fullname;
|
$coursenames[$course->context->id] = $course->fullname;
|
||||||
$modinfo = get_fast_modinfo($course, $USER->id);
|
$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 ($modinfo->instances as $modname => $instances) {
|
||||||
|
|
||||||
foreach ($instances as $modid => $mod) {
|
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 ' .
|
'instanceid = '.$mod->id.' AND ' .
|
||||||
'contextlevel = ' . CONTEXT_MODULE . ' AND ' .
|
'contextlevel = ' . CONTEXT_MODULE . ' AND ' .
|
||||||
'path LIKE \''.$course_context_path.'/%\'');
|
'path LIKE \''.$coursecontextpath.'/%\'');
|
||||||
|
|
||||||
$mod_string = $mod->name . ' (' . get_plugin_name($modname) . ')';
|
$modstring = $mod->name . ' (' . get_plugin_name($modname) . ')';
|
||||||
$this->modnames[$course->context->id][$mod_context_id] = $mod_string;
|
$this->modnames[$course->context->id][$modcontextid] = $modstring;
|
||||||
$allmodnames[$mod_context_id] = $course->shortname . " - " . $mod_string;
|
$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 = &$mform->addElement('select', 'modassoc', get_string('managemodules'), $allmodnames);
|
||||||
$selectassoc->setMultiple(true);
|
$selectassoc->setMultiple(true);
|
||||||
$PAGE->requires->data_for_js('blog_edit_form_modnames', $this->modnames);
|
$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->setType('courseid', PARAM_INT);
|
||||||
$mform->setDefault('courseid', 0);
|
$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);
|
$this->set_data($existing);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,59 +138,9 @@ class blog_edit_form extends moodleform {
|
||||||
|
|
||||||
$errors = array();
|
$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)) {
|
if (empty($data['courseassoc']) && ($data['publishstate'] == 'course' || $data['publishstate'] == 'group') && !empty($CFG->useblogassociations)) {
|
||||||
return array('publishstate' => get_string('mustassociatecourse', 'blog'));
|
return array('publishstate' => get_string('mustassociatecourse', 'blog'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//validate course association
|
//validate course association
|
||||||
if (!empty($data['courseassoc'])) {
|
if (!empty($data['courseassoc'])) {
|
||||||
|
@ -261,7 +167,7 @@ class blog_edit_form extends moodleform {
|
||||||
if ($modcontext) { //insure associated mod has a valid context id
|
if ($modcontext) { //insure associated mod has a valid context id
|
||||||
//get context of the mod's course
|
//get context of the mod's course
|
||||||
$path = split('/', $modcontext->path);
|
$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
|
//insure only one course is associated
|
||||||
if (!empty($data['courseassoc'])) {
|
if (!empty($data['courseassoc'])) {
|
||||||
|
|
|
@ -169,7 +169,7 @@ class blog_entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
//retrieve associations in case they're needed early
|
//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
|
//determine text for publish state
|
||||||
switch ($template['publishstate']) {
|
switch ($template['publishstate']) {
|
||||||
case 'draft':
|
case 'draft':
|
||||||
|
@ -211,25 +211,32 @@ class blog_entry {
|
||||||
}
|
}
|
||||||
|
|
||||||
//add associations
|
//add associations
|
||||||
if (!empty($CFG->useblogassociations) && $blog_associations) {
|
if (!empty($CFG->useblogassociations) && $blogassociations) {
|
||||||
$contentcell->text .= $OUTPUT->container_start('tags');
|
$contentcell->text .= $OUTPUT->container_start('tags');
|
||||||
$assoc_str = '';
|
$assocstr = '';
|
||||||
|
$hascourseassocs = false;
|
||||||
|
|
||||||
foreach ($blog_associations as $assoc_rec) { //first find and show the associated course
|
foreach ($blogassociations as $assocrec) { //first find and show the associated course
|
||||||
$context_rec = $DB->get_record('context', array('id' => $assoc_rec->contextid));
|
$context_rec = $DB->get_record('context', array('id' => $assocrec->contextid));
|
||||||
if ($context_rec->contextlevel == CONTEXT_COURSE) {
|
if ($context_rec->contextlevel == CONTEXT_COURSE) {
|
||||||
$associcon = new moodle_action_icon();
|
$associcon = new moodle_action_icon();
|
||||||
$associcon->link->url = new moodle_url($CFG->wwwroot.'/course/view.php', array('id' => $context_rec->instanceid));
|
$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->image->src = $OUTPUT->old_icon_url('i/course');
|
||||||
$associcon->linktext = $DB->get_field('course', 'shortname', array('id' => $context_rec->instanceid));
|
$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
|
foreach ($blogassociations as $assocrec) { //now show each mod association
|
||||||
$context_rec = $DB->get_record('context', array('id' => $assoc_rec->contextid));
|
$context_rec = $DB->get_record('context', array('id' => $assocrec->contextid));
|
||||||
|
|
||||||
if ($context_rec->contextlevel == CONTEXT_MODULE) {
|
if ($context_rec->contextlevel == CONTEXT_MODULE) {
|
||||||
|
if ($hascourseassocs) {
|
||||||
|
$assocstr .= ', ';
|
||||||
|
$hascourseassocs = false;
|
||||||
|
}
|
||||||
|
|
||||||
$modinfo = $DB->get_record('course_modules', array('id' => $context_rec->instanceid));
|
$modinfo = $DB->get_record('course_modules', array('id' => $context_rec->instanceid));
|
||||||
$modname = $DB->get_field('modules', 'name', array('id' => $modinfo->module));
|
$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->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->image->src = $OUTPUT->mod_icon_url('icon', $modname);
|
||||||
$associcon->linktext = $DB->get_field($modname, 'name', array('id' => $modinfo->instance));
|
$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();
|
$contentcell->text .= $OUTPUT->container_end();
|
||||||
}
|
}
|
||||||
|
@ -258,14 +265,8 @@ class blog_entry {
|
||||||
|
|
||||||
if (blog_user_can_edit_entry($this)) {
|
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)) . ' | ';
|
$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')));
|
$contentcell->text .= $OUTPUT->link(html_link::make(new moodle_url($CFG->wwwroot.'/blog/index.php', array('entryid' => $this->id)), get_string('permalink', 'blog')));
|
||||||
|
|
||||||
|
@ -348,22 +349,9 @@ class blog_entry {
|
||||||
$this->$var = $val;
|
$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)) {
|
if (!empty($CFG->useblogassociations)) {
|
||||||
$this->add_associations();
|
$this->add_associations();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$this->lastmodified = time();
|
$this->lastmodified = time();
|
||||||
|
|
||||||
|
@ -393,14 +381,6 @@ class blog_entry {
|
||||||
|
|
||||||
$returnurl = '';
|
$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();
|
$this->delete_attachments();
|
||||||
|
|
||||||
$DB->delete_records('post', array('id' => $this->id));
|
$DB->delete_records('post', array('id' => $this->id));
|
||||||
|
|
|
@ -91,7 +91,7 @@ class bloglib_test extends UnitTestCaseUsingDatabase {
|
||||||
global $CFG, $PAGE, $OUTPUT;
|
global $CFG, $PAGE, $OUTPUT;
|
||||||
|
|
||||||
$this->create_test_tables('post', 'tag', 'course', 'user', 'role', 'role_assignments', 'group', 'blog_associations',
|
$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',
|
$contexts = $this->load_test_data('context',
|
||||||
array('contextlevel', 'instanceid', 'path', 'depth'), array(
|
array('contextlevel', 'instanceid', 'path', 'depth'), array(
|
||||||
|
|
|
@ -1,326 +0,0 @@
|
||||||
<?php
|
|
||||||
require_once($CFG->dirroot .'/blog/lib.php');
|
|
||||||
require_once($CFG->libdir.'/formslib.php');
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extend the base assignment class for offline assignments
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class assignment_blog extends assignment_base {
|
|
||||||
|
|
||||||
function assignment_blog($cmid='staticonly', $assignment=NULL, $cm=NULL, $course=NULL) {
|
|
||||||
parent::assignment_base($cmid, $assignment, $cm, $course);
|
|
||||||
$this->type = 'blog';
|
|
||||||
}
|
|
||||||
|
|
||||||
function display_lateness($timesubmitted) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_student_answer($userid, $return=false){
|
|
||||||
global $CFG, $DB;
|
|
||||||
if (!$submission = $this->get_submission($userid)) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
$post = $DB->get_record('post', array('id' => $submission->data1));
|
|
||||||
$ret = '<b>'.$post->subject.': </b><br>'.shorten_text(format_text($post->summary));
|
|
||||||
$ret .= '<a href="'.$CFG->wwwroot.'/blog/index.php?postid='.$post->id.'" target="_blank">Full Entry</a><br>';
|
|
||||||
|
|
||||||
return $ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function setup_elements(&$mform) {
|
|
||||||
$ynoptions = array( 0 => get_string('no'), 1 => get_string('yes'));
|
|
||||||
//$mform->addElement('select', 'var1', get_string('multiassoc', 'assignment'), $ynoptions);
|
|
||||||
//$mform->setHelpButton('var1', array('multiassoc', get_string('multiassoc', 'assignment'), 'assignment'));
|
|
||||||
//$mform->setDefault('var1', 0);
|
|
||||||
|
|
||||||
$publishstates = array();
|
|
||||||
$i = 0;
|
|
||||||
foreach(blog_applicable_publish_states() as $state) $publishstates[$i++] = $state;
|
|
||||||
$mform->addElement('select', 'var2', get_string('maxpublishstate', 'assignment'), $publishstates);
|
|
||||||
$mform->setDefault('var2', 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function prepare_new_submission($userid) {
|
|
||||||
$submission = new Object;
|
|
||||||
$submission->assignment = $this->assignment->id;
|
|
||||||
$submission->userid = $userid;
|
|
||||||
$submission->timecreated = time(); // needed for offline assignments
|
|
||||||
$submission->timemodified = $submission->timecreated;
|
|
||||||
$submission->numfiles = 0;
|
|
||||||
$submission->data1 = '';
|
|
||||||
$submission->data2 = '';
|
|
||||||
$submission->grade = -1;
|
|
||||||
$submission->submissioncomment = '';
|
|
||||||
$submission->format = 0;
|
|
||||||
$submission->teacher = 0;
|
|
||||||
$submission->timemarked = 0;
|
|
||||||
$submission->mailed = 0;
|
|
||||||
return $submission;
|
|
||||||
}
|
|
||||||
|
|
||||||
// needed for the timemodified override
|
|
||||||
function process_feedback() {
|
|
||||||
global $CFG, $USER, $DB;
|
|
||||||
require_once($CFG->libdir.'/gradelib.php');
|
|
||||||
|
|
||||||
if (!$feedback = data_submitted()) { // No incoming data?
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
///For save and next, we need to know the userid to save, and the userid to go
|
|
||||||
///We use a new hidden field in the form, and set it to -1. If it's set, we use this
|
|
||||||
///as the userid to store
|
|
||||||
if ((int)$feedback->saveuserid !== -1){
|
|
||||||
$feedback->userid = $feedback->saveuserid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($feedback->cancel)) { // User hit cancel button
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$grading_info = grade_get_grades($this->course->id, 'mod', 'assignment', $this->assignment->id, $feedback->userid);
|
|
||||||
|
|
||||||
// store outcomes if needed
|
|
||||||
$this->process_outcomes($feedback->userid);
|
|
||||||
|
|
||||||
$submission = $this->get_submission($feedback->userid, true); // Get or make one
|
|
||||||
|
|
||||||
if (!$grading_info->items[0]->grades[$feedback->userid]->locked and
|
|
||||||
!$grading_info->items[0]->grades[$feedback->userid]->overridden) {
|
|
||||||
|
|
||||||
$submission->grade = $feedback->grade;
|
|
||||||
$submission->submissioncomment = $feedback->submissioncomment;
|
|
||||||
$submission->format = $feedback->format;
|
|
||||||
$submission->teacher = $USER->id;
|
|
||||||
$mailinfo = get_user_preferences('assignment_mailinfo', 0);
|
|
||||||
if (!$mailinfo) {
|
|
||||||
$submission->mailed = 1; // treat as already mailed
|
|
||||||
} else {
|
|
||||||
$submission->mailed = 0; // Make sure mail goes out (again, even)
|
|
||||||
}
|
|
||||||
$submission->timemarked = time();
|
|
||||||
|
|
||||||
unset($submission->data1); // Don't need to update this.
|
|
||||||
unset($submission->data2); // Don't need to update this.
|
|
||||||
|
|
||||||
if (empty($submission->timemodified)) { // eg for offline assignments
|
|
||||||
$submission->timemodified = time();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $DB->update_record('assignment_submissions', $submission)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// triger grade event
|
|
||||||
$this->update_grade($submission);
|
|
||||||
|
|
||||||
add_to_log($this->course->id, 'assignment', 'update grades',
|
|
||||||
'submissions.php?id='.$this->assignment->id.'&user='.$feedback->userid, $feedback->userid, $this->cm->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $submission;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function view() {
|
|
||||||
|
|
||||||
global $USER, $DB, $CFG, $COURSE;
|
|
||||||
|
|
||||||
$edit = optional_param('edit', 0, PARAM_BOOL);
|
|
||||||
$saved = optional_param('saved', 0, PARAM_BOOL);
|
|
||||||
|
|
||||||
$context = get_context_instance(CONTEXT_MODULE, $this->cm->id);
|
|
||||||
require_capability('mod/assignment:view', $context);
|
|
||||||
|
|
||||||
$submission = $this->get_submission();
|
|
||||||
|
|
||||||
//Guest can not submit nor edit an assignment (bug: 4604)
|
|
||||||
if (!has_capability('mod/assignment:submit', $context)) {
|
|
||||||
$editable = null;
|
|
||||||
} else {
|
|
||||||
$editable = $this->isopen();
|
|
||||||
}
|
|
||||||
$editmode = ($editable and $edit);
|
|
||||||
|
|
||||||
if ($editmode) {
|
|
||||||
//guest can not edit or submit assignment
|
|
||||||
if (!has_capability('mod/assignment:submit', $context)) {
|
|
||||||
print_error('guestnosubmit', 'assignment');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add_to_log($this->course->id, "assignment", "view", "view.php?id={$this->cm->id}", $this->assignment->id, $this->cm->id);
|
|
||||||
|
|
||||||
/// prepare form and process submitted data
|
|
||||||
$mform = new mod_assignment_blog_edit_form();
|
|
||||||
if($this->assignment->var1) { //allow multiple associations
|
|
||||||
$mform->set_multiple_assoc();
|
|
||||||
}
|
|
||||||
|
|
||||||
$defaults = new object();
|
|
||||||
if($submission = $this->get_submission()) {
|
|
||||||
$defaults->selectblog = $submission->data1;
|
|
||||||
}
|
|
||||||
$defaults->id = $this->cm->id;
|
|
||||||
|
|
||||||
$mform->set_data($defaults);
|
|
||||||
|
|
||||||
if ($mform->is_cancelled()) {
|
|
||||||
redirect('view.php?id='.$this->cm->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data = $mform->get_data()) { // No incoming data?
|
|
||||||
if ($editable && $this->update_submission($data)) {
|
|
||||||
//TODO fix log actions - needs db upgrade
|
|
||||||
$submission = $this->get_submission();
|
|
||||||
add_to_log($this->course->id, 'assignment', 'upload',
|
|
||||||
'view.php?a='.$this->assignment->id, $this->assignment->id, $this->cm->id);
|
|
||||||
$this->email_teachers($submission);
|
|
||||||
//redirect to get updated submission date and word count
|
|
||||||
redirect('view.php?id='.$this->cm->id.'&saved=1');
|
|
||||||
} else {
|
|
||||||
// TODO: add better error message
|
|
||||||
notify(get_string("error")); //submitting not allowed!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// print header, etc. and display form if needed
|
|
||||||
if ($editmode) {
|
|
||||||
$this->view_header(get_string('editmysubmission', 'assignment'));
|
|
||||||
} else {
|
|
||||||
$this->view_header();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->view_intro();
|
|
||||||
|
|
||||||
$this->view_dates();
|
|
||||||
|
|
||||||
if ($saved) {
|
|
||||||
notify(get_string('submissionsaved', 'assignment'), 'notifysuccess');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (has_capability('mod/assignment:submit', $context)) {
|
|
||||||
print_simple_box_start('center', '70%', '', 0, 'generalbox', 'online');
|
|
||||||
if ($editmode) {
|
|
||||||
if($DB->record_exists('post', array('module'=>'blog', 'userid'=>$USER->id))) {
|
|
||||||
$mform->display();
|
|
||||||
} else {
|
|
||||||
echo '<div class="noticebox">'.get_string('noblogs', 'assignment').'</div>';
|
|
||||||
echo '<br><a href="'. $CFG->wwwroot. '/blog/edit.php?action=add&courseid='
|
|
||||||
.$COURSE->id.'">'.get_string('addnewentry', 'blog') ."</a>";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ($submission) {
|
|
||||||
blog_print_entry($DB->get_record('post', array('id' => $submission->data1)));
|
|
||||||
} else if (!has_capability('mod/assignment:submit', $context)) { //fix for #4604
|
|
||||||
echo '<div style="text-align:center">'. get_string('guestnosubmit', 'assignment').'</div>';
|
|
||||||
} else if ($this->isopen()) { //fix for #4206
|
|
||||||
echo '<div style="text-align:center">'.get_string('emptysubmission', 'assignment').'</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
print_simple_box_end();
|
|
||||||
if (!$editmode && $editable) {
|
|
||||||
echo "<div style='text-align:center'>";
|
|
||||||
print_single_button('view.php', array('id'=>$this->cm->id,'edit'=>'1'),
|
|
||||||
get_string('editmysubmission', 'assignment'));
|
|
||||||
echo "</div>";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->view_feedback();
|
|
||||||
|
|
||||||
$this->view_footer();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function update_submission($data) {
|
|
||||||
global $CFG, $USER, $DB, $COURSE;
|
|
||||||
|
|
||||||
$submission = $this->get_submission($USER->id, true);
|
|
||||||
|
|
||||||
$update = new object();
|
|
||||||
$update->id = $submission->id;
|
|
||||||
$update->data1 = $data->selectblog;
|
|
||||||
$update->timemodified = time();
|
|
||||||
|
|
||||||
//enforce access restriction
|
|
||||||
$postaccess = -1;
|
|
||||||
$i=0;
|
|
||||||
$post = $DB->get_record('post', array('id' => $data->selectblog));
|
|
||||||
if(!$post) {
|
|
||||||
print_error('blognotfound', 'blog');
|
|
||||||
}
|
|
||||||
$publishstates = array();
|
|
||||||
foreach(blog_applicable_publish_states() as $state => $desc) {
|
|
||||||
if($state == $post->publishstate) {
|
|
||||||
$postaccess = $i;
|
|
||||||
}
|
|
||||||
$publishstates[$i++] = $state;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($this->assignment->var2 < $postaccess) {
|
|
||||||
$post->publishstate = $publishstates[$this->assignment->var2];
|
|
||||||
$DB->update_record('post', $post);
|
|
||||||
}
|
|
||||||
|
|
||||||
//force the user to have strict associations with this post
|
|
||||||
blog_remove_associations_for_post($post->id); //remove all existing associations
|
|
||||||
//add assignment association
|
|
||||||
$assignmentmodid = $DB->get_field('modules', 'id', array('name' => 'assignment'));
|
|
||||||
$modcontext = get_context_instance(CONTEXT_MODULE, $DB->get_field('course_modules', 'id',
|
|
||||||
array('module' => $assignmentmodid, 'instance' => $this->assignment->id)));
|
|
||||||
blog_add_association($post->id, $modcontext->id);
|
|
||||||
//add course association
|
|
||||||
$coursecontext = get_context_instance(CONTEXT_COURSE, $DB->get_field('course_modules', 'course',
|
|
||||||
array('module' => $assignmentmodid, 'instance' => $this->assignment->id)));
|
|
||||||
blog_add_association($post->id, $coursecontext->id);
|
|
||||||
|
|
||||||
if (!$DB->update_record('assignment_submissions', $update)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$submission = $this->get_submission($USER->id);
|
|
||||||
$this->update_grade($submission);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class mod_assignment_blog_edit_form extends moodleform {
|
|
||||||
function definition() {
|
|
||||||
global $USER, $DB;
|
|
||||||
$mform =& $this->_form;
|
|
||||||
|
|
||||||
// visible elements
|
|
||||||
//$mform->addRule('text', get_string('required'), 'required', null, 'client');
|
|
||||||
|
|
||||||
$blogentries = array();
|
|
||||||
foreach($DB->get_records('post', array('userid' => $USER->id)) as $rec) {
|
|
||||||
$blogentries[$rec->id] = userdate($rec->created) . ' - ' . $rec->summary;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mform->addElement('select', 'selectblog', get_string('selectblog', 'assignment'), $blogentries);
|
|
||||||
|
|
||||||
// hidden params
|
|
||||||
$mform->addElement('hidden', 'id', 0);
|
|
||||||
$mform->setType('id', PARAM_INT);
|
|
||||||
|
|
||||||
// buttons
|
|
||||||
$this->add_action_buttons();
|
|
||||||
}
|
|
||||||
|
|
||||||
function set_multiple_assoc() {
|
|
||||||
$mform =& $this->_form;
|
|
||||||
$selectblog = $mform->getElement('selectblog');
|
|
||||||
$selectblog->setMultiple(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
Loading…
Add table
Add a link
Reference in a new issue