Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-25660 workshop registers events in the calendar

  • Loading branch information...
commit 6c6042404a0cb2ece02b236b2f5378b0811fb2f0 1 parent b1d3043
@mudrd8mz mudrd8mz authored
Showing with 103 additions and 0 deletions.
  1. +4 −0 mod/workshop/lang/en/workshop.php
  2. +99 −0 mod/workshop/lib.php
View
4 mod/workshop/lang/en/workshop.php
@@ -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
99 mod/workshop/lib.php
@@ -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;
}
@@ -1387,3 +1395,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();
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.