Commit bb0bd8cb authored by Dan Poltawski's avatar Dan Poltawski
Browse files

Merge branch 'MDL-25660-workshop-calendar' of git://github.com/mudrd8mz/moodle

Conflicts:
	mod/workshop/lang/en/workshop.php
	mod/workshop/version.php
    mod/workshop/db/upgrade.php
parents 2a1f43a1 33d0cb3c
...@@ -50,5 +50,42 @@ function xmldb_workshop_upgrade($oldversion) { ...@@ -50,5 +50,42 @@ function xmldb_workshop_upgrade($oldversion) {
upgrade_mod_savepoint(true, 2012033100, 'workshop'); upgrade_mod_savepoint(true, 2012033100, 'workshop');
} }
/**
* Remove all workshop calendar events
*/
if ($oldversion < 2012041700) {
require_once($CFG->dirroot . '/calendar/lib.php');
$events = $DB->get_records('event', array('modulename' => 'workshop'));
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
upgrade_mod_savepoint(true, 2012041700, 'workshop');
}
/**
* Recreate all workshop calendar events
*/
if ($oldversion < 2012041701) {
require_once(dirname(dirname(__FILE__)) . '/lib.php');
$sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,
w.submissionend, w.assessmentstart, w.assessmentend,
cm.id AS cmid
FROM {workshop} w
JOIN {modules} m ON m.name = 'workshop'
JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";
$rs = $DB->get_recordset_sql($sql);
foreach ($rs as $workshop) {
$cmid = $workshop->cmid;
unset($workshop->cmid);
workshop_calendar_update($workshop, $cmid);
}
$rs->close();
upgrade_mod_savepoint(true, 2012041701, 'workshop');
}
return true; return true;
} }
...@@ -51,6 +51,7 @@ $string['assessmentbyyourself'] = 'Your assessment'; ...@@ -51,6 +51,7 @@ $string['assessmentbyyourself'] = 'Your assessment';
$string['assessmentdeleted'] = 'Assessment deallocated'; $string['assessmentdeleted'] = 'Assessment deallocated';
$string['assessmentend'] = 'Deadline for assessment'; $string['assessmentend'] = 'Deadline for assessment';
$string['assessmentendbeforestart'] = 'Deadline for assessment can not be specified before the open for assessment date'; $string['assessmentendbeforestart'] = 'Deadline for assessment can not be specified before the open for assessment date';
$string['assessmentendevent'] = '{$a} (assessment deadline)';
$string['assessmentenddatetime'] = 'Assessment deadline: {$a->daydatetime} ({$a->distanceday})'; $string['assessmentenddatetime'] = 'Assessment deadline: {$a->daydatetime} ({$a->distanceday})';
$string['assessmentform'] = 'Assessment form'; $string['assessmentform'] = 'Assessment form';
$string['assessmentofsubmission'] = '<a href="{$a->assessmenturl}">Assessment</a> of <a href="{$a->submissionurl}">{$a->submissiontitle}</a>'; $string['assessmentofsubmission'] = '<a href="{$a->assessmenturl}">Assessment</a> of <a href="{$a->submissionurl}">{$a->submissiontitle}</a>';
...@@ -59,6 +60,7 @@ $string['assessmentreferenceconflict'] = 'It is not possible to assess an exampl ...@@ -59,6 +60,7 @@ $string['assessmentreferenceconflict'] = 'It is not possible to assess an exampl
$string['assessmentreferenceneeded'] = 'You have to assess this example submission to provide a reference assessment. Click \'Continue\' button to assess the submission.'; $string['assessmentreferenceneeded'] = 'You have to assess this example submission to provide a reference assessment. Click \'Continue\' button to assess the submission.';
$string['assessmentsettings'] = 'Assessment settings'; $string['assessmentsettings'] = 'Assessment settings';
$string['assessmentstart'] = 'Open for assessment from'; $string['assessmentstart'] = 'Open for assessment from';
$string['assessmentstartevent'] = '{$a} (opens for assessment)';
$string['assessmentstartdatetime'] = 'Open for assessment from {$a->daydatetime} ({$a->distanceday})'; $string['assessmentstartdatetime'] = 'Open for assessment from {$a->daydatetime} ({$a->distanceday})';
$string['assessmentweight'] = 'Assessment weight'; $string['assessmentweight'] = 'Assessment weight';
$string['assignedassessments'] = 'Assigned submissions to assess'; $string['assignedassessments'] = 'Assigned submissions to assess';
...@@ -210,6 +212,7 @@ $string['submissionattachment'] = 'Attachment'; ...@@ -210,6 +212,7 @@ $string['submissionattachment'] = 'Attachment';
$string['submissioncontent'] = 'Submission content'; $string['submissioncontent'] = 'Submission content';
$string['submissionend'] = 'Submissions deadline'; $string['submissionend'] = 'Submissions deadline';
$string['submissionendbeforestart'] = 'Submissions deadline can not be specified before the open for submissions date'; $string['submissionendbeforestart'] = 'Submissions deadline can not be specified before the open for submissions date';
$string['submissionendevent'] = '{$a} (submissions deadline)';
$string['submissionenddatetime'] = 'Submissions deadline: {$a->daydatetime} ({$a->distanceday})'; $string['submissionenddatetime'] = 'Submissions deadline: {$a->daydatetime} ({$a->distanceday})';
$string['submissionendswitch'] = 'Switch to the next phase after the submissions deadline'; $string['submissionendswitch'] = 'Switch to the next phase after the submissions deadline';
$string['submissionendswitch_help'] = 'If the submissions deadline is specified and this box is checked, the workshop will automatically switch to the assessment phase after the submissions deadline. $string['submissionendswitch_help'] = 'If the submissions deadline is specified and this box is checked, the workshop will automatically switch to the assessment phase after the submissions deadline.
...@@ -220,6 +223,7 @@ $string['submissiongrade_help'] = 'This setting specifies the maximum grade that ...@@ -220,6 +223,7 @@ $string['submissiongrade_help'] = 'This setting specifies the maximum grade that
$string['submissiongradeof'] = 'Grade for submission (of {$a})'; $string['submissiongradeof'] = 'Grade for submission (of {$a})';
$string['submissionsettings'] = 'Submission settings'; $string['submissionsettings'] = 'Submission settings';
$string['submissionstart'] = 'Open for submissions from'; $string['submissionstart'] = 'Open for submissions from';
$string['submissionstartevent'] = '{$a} (opens for submissions)';
$string['submissionstartdatetime'] = 'Open for submissions from {$a->daydatetime} ({$a->distanceday})'; $string['submissionstartdatetime'] = 'Open for submissions from {$a->daydatetime} ({$a->distanceday})';
$string['submissiontitle'] = 'Title'; $string['submissiontitle'] = 'Title';
$string['subplugintype_workshopallocation'] = 'Submissions allocation method'; $string['subplugintype_workshopallocation'] = 'Submissions allocation method';
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/calendar/lib.php');
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Moodle core API // // Moodle core API //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
...@@ -108,6 +110,9 @@ function workshop_add_instance(stdclass $workshop) { ...@@ -108,6 +110,9 @@ function workshop_add_instance(stdclass $workshop) {
workshop_grade_item_update($workshop); workshop_grade_item_update($workshop);
workshop_grade_item_category_update($workshop); workshop_grade_item_category_update($workshop);
// create calendar events
workshop_calendar_update($workshop, $workshop->coursemodule);
return $workshop->id; return $workshop->id;
} }
...@@ -158,6 +163,9 @@ function workshop_update_instance(stdclass $workshop) { ...@@ -158,6 +163,9 @@ function workshop_update_instance(stdclass $workshop) {
workshop_grade_item_update($workshop); workshop_grade_item_update($workshop);
workshop_grade_item_category_update($workshop); workshop_grade_item_category_update($workshop);
// update calendar events
workshop_calendar_update($workshop, $workshop->coursemodule);
return true; return true;
} }
...@@ -213,6 +221,13 @@ function workshop_delete_instance($id) { ...@@ -213,6 +221,13 @@ function workshop_delete_instance($id) {
call_user_func($classname.'::delete_instance', $workshop->id); call_user_func($classname.'::delete_instance', $workshop->id);
} }
// delete the calendar events
$events = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
foreach ($events as $event) {
$event = calendar_event::load($event);
$event->delete();
}
// finally remove the workshop record itself // finally remove the workshop record itself
$DB->delete_records('workshop', array('id' => $workshop->id)); $DB->delete_records('workshop', array('id' => $workshop->id));
...@@ -1426,3 +1441,94 @@ function workshop_page_type_list($pagetype, $parentcontext, $currentcontext) { ...@@ -1426,3 +1441,94 @@ function workshop_page_type_list($pagetype, $parentcontext, $currentcontext) {
$module_pagetype = array('mod-workshop-*'=>get_string('page-mod-workshop-x', 'workshop')); $module_pagetype = array('mod-workshop-*'=>get_string('page-mod-workshop-x', 'workshop'));
return $module_pagetype; return $module_pagetype;
} }
////////////////////////////////////////////////////////////////////////////////
// Calendar API //
////////////////////////////////////////////////////////////////////////////////
/**
* Updates the calendar events associated to the given workshop
*
* @param stdClass $workshop the workshop instance record
* @param int $cmid course module id
*/
function workshop_calendar_update(stdClass $workshop, $cmid) {
global $DB;
// get the currently registered events so that we can re-use their ids
$currentevents = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
// the common properties for all events
$base = new stdClass();
$base->description = format_module_intro('workshop', $workshop, $cmid, false);
$base->courseid = $workshop->course;
$base->groupid = 0;
$base->userid = 0;
$base->modulename = 'workshop';
$base->eventtype = 'pluginname';
$base->instance = $workshop->id;
$base->visible = instance_is_visible('workshop', $workshop);
$base->timeduration = 0;
if ($workshop->submissionstart) {
$event = clone($base);
$event->name = get_string('submissionstartevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->submissionstart;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// calendar_event::create will reuse a db record if the id field is set
calendar_event::create($event);
}
if ($workshop->submissionend) {
$event = clone($base);
$event->name = get_string('submissionendevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->submissionend;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// calendar_event::create will reuse a db record if the id field is set
calendar_event::create($event);
}
if ($workshop->assessmentstart) {
$event = clone($base);
$event->name = get_string('assessmentstartevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->assessmentstart;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// calendar_event::create will reuse a db record if the id field is set
calendar_event::create($event);
}
if ($workshop->assessmentend) {
$event = clone($base);
$event->name = get_string('assessmentendevent', 'mod_workshop', $workshop->name);
$event->timestart = $workshop->assessmentend;
if ($reusedevent = array_shift($currentevents)) {
$event->id = $reusedevent->id;
} else {
// should not be set but just in case
unset($event->id);
}
// calendar_event::create will reuse a db record if the id field is set
calendar_event::create($event);
}
// delete any leftover events
foreach ($currentevents as $oldevent) {
$oldevent = calendar_event::load($oldevent);
$oldevent->delete();
}
}
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$module->version = 2012033100; // the current module version (YYYYMMDDXX) $module->version = 2012041701; // the current module version (YYYYMMDDXX)
$module->requires = 2012032300; // requires this Moodle version $module->requires = 2012032300; // requires this Moodle version
$module->component = 'mod_workshop'; // full name of the plugin (used for diagnostics) $module->component = 'mod_workshop'; // full name of the plugin (used for diagnostics)
$module->cron = 60; // give as a chance every minute $module->cron = 60; // give as a chance every minute
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment