Permalink
Browse files

Merge branch 'MDL-25660-workshop-calendar_22' of git://github.com/mud…

…rd8mz/moodle into MOODLE_22_STABLE
  • Loading branch information...
2 parents 36ddd60 + ade4de3 commit 35eb31fa38c11af51f29317285ee09a19931c98a @danpoltawski danpoltawski committed Apr 17, 2012
Showing with 148 additions and 1 deletion.
  1. +37 −0 mod/workshop/db/upgrade.php
  2. +4 −0 mod/workshop/lang/en/workshop.php
  3. +106 −0 mod/workshop/lib.php
  4. +1 −1 mod/workshop/version.php
@@ -322,5 +322,42 @@ function xmldb_workshop_upgrade($oldversion) {
// Moodle v2.2.0 release upgrade line
// Put any upgrade step following this
+ /**
+ * Remove all workshop calendar events
+ */
+ if ($oldversion < 2011112901) {
+ 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, 2011112901, 'workshop');
+ }
+
+ /**
+ * Recreate all workshop calendar events
+ */
+ if ($oldversion < 2011112902) {
+ 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, 2011112902, 'workshop');
+ }
+
return true;
}
@@ -49,6 +49,7 @@
$string['assessmentbyyourself'] = 'Your assessment';
$string['assessmentdeleted'] = 'Assessment deallocated';
$string['assessmentend'] = 'Deadline for assessment';
+$string['assessmentendevent'] = '{$a} (assessment deadline)';
$string['assessmentenddatetime'] = 'Assessment deadline: {$a->daydatetime} ({$a->distanceday})';
$string['assessmentform'] = 'Assessment form';
$string['assessmentofsubmission'] = '<a href="{$a->assessmenturl}">Assessment</a> of <a href="{$a->submissionurl}">{$a->submissiontitle}</a>';
@@ -57,6 +58,7 @@
$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['assessmentstart'] = 'Open for assessment from';
+$string['assessmentstartevent'] = '{$a} (opens for assessment)';
$string['assessmentstartdatetime'] = 'Open for assessment from {$a->daydatetime} ({$a->distanceday})';
$string['assessmentweight'] = 'Assessment weight';
$string['assignedassessments'] = 'Assigned submissions to assess';
@@ -206,12 +208,14 @@
$string['submissionattachment'] = 'Attachment';
$string['submissioncontent'] = 'Submission content';
$string['submissionend'] = 'Submissions deadline';
+$string['submissionendevent'] = '{$a} (submissions deadline)';
$string['submissionenddatetime'] = 'Submissions deadline: {$a->daydatetime} ({$a->distanceday})';
$string['submissiongrade'] = 'Grade for submission';
$string['submissiongrade_help'] = 'This setting specifies the maximum grade that may be obtained for submitted work.';
$string['submissiongradeof'] = 'Grade for submission (of {$a})';
$string['submissionsettings'] = 'Submission settings';
$string['submissionstart'] = 'Open for submissions from';
+$string['submissionstartevent'] = '{$a} (opens for submissions)';
$string['submissionstartdatetime'] = 'Open for submissions from {$a->daydatetime} ({$a->distanceday})';
$string['submissiontitle'] = 'Title';
$string['subplugintype_workshopallocation'] = 'Submissions allocation method';
View
@@ -29,6 +29,8 @@
defined('MOODLE_INTERNAL') || die();
+require_once($CFG->dirroot . '/calendar/lib.php');
+
////////////////////////////////////////////////////////////////////////////////
// Moodle core API //
////////////////////////////////////////////////////////////////////////////////
@@ -107,6 +109,9 @@ function workshop_add_instance(stdclass $workshop) {
workshop_grade_item_update($workshop);
workshop_grade_item_category_update($workshop);
+ // create calendar events
+ workshop_calendar_update($workshop, $workshop->coursemodule);
+
return $workshop->id;
}
@@ -156,6 +161,9 @@ function workshop_update_instance(stdclass $workshop) {
workshop_grade_item_update($workshop);
workshop_grade_item_category_update($workshop);
+ // update calendar events
+ workshop_calendar_update($workshop, $workshop->coursemodule);
+
return true;
}
@@ -211,6 +219,13 @@ function workshop_delete_instance($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
$DB->delete_records('workshop', array('id' => $workshop->id));
@@ -1387,3 +1402,94 @@ function workshop_page_type_list($pagetype, $parentcontext, $currentcontext) {
$module_pagetype = array('mod-workshop-*'=>get_string('page-mod-workshop-x', 'workshop'));
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();
+ }
+}
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
-$module->version = 2011112900; // The current module version (Date: YYYYMMDDXX)
+$module->version = 2011112902; // The current module version (Date: YYYYMMDDXX)
$module->requires = 2011112900; // Requires this Moodle version
$module->component = 'mod_workshop'; // Full name of the plugin (used for diagnostics)
$module->cron = 0;

0 comments on commit 35eb31f

Please sign in to comment.