Skip to content

Commit

Permalink
MDL-25660 workshop registers events in the calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
mudrd8mz committed Apr 13, 2012
1 parent 8e35d0a commit 5f05ebc
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mod/workshop/lang/en/workshop.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
Expand All @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
99 changes: 99 additions & 0 deletions mod/workshop/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->dirroot . '/calendar/lib.php');

////////////////////////////////////////////////////////////////////////////////
// Moodle core API //
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -106,6 +108,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;
}

Expand Down Expand Up @@ -155,6 +160,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;
}

Expand Down Expand Up @@ -1386,3 +1394,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();
}
}

0 comments on commit 5f05ebc

Please sign in to comment.