Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…rd8mz/moodle into MOODLE_21_STABLE
  • Loading branch information...
commit d89ebccf65f17e6b039f500ce8d1d79ee64447de 2 parents 8a2b5c4 + f58b7c2
Dan Poltawski danpoltawski authored
37 mod/workshop/db/upgrade.php
@@ -319,5 +319,42 @@ function xmldb_workshop_upgrade($oldversion) {
319 319 upgrade_mod_savepoint(true, 2011061001, 'workshop');
320 320 }
321 321
  322 + /**
  323 + * Remove all workshop calendar events
  324 + */
  325 + if ($oldversion < 2011061002) {
  326 + require_once($CFG->dirroot . '/calendar/lib.php');
  327 + $events = $DB->get_records('event', array('modulename' => 'workshop'));
  328 + foreach ($events as $event) {
  329 + $event = calendar_event::load($event);
  330 + $event->delete();
  331 + }
  332 + upgrade_mod_savepoint(true, 2011061002, 'workshop');
  333 + }
  334 +
  335 + /**
  336 + * Recreate all workshop calendar events
  337 + */
  338 + if ($oldversion < 2011061003) {
  339 + require_once(dirname(dirname(__FILE__)) . '/lib.php');
  340 +
  341 + $sql = "SELECT w.id, w.course, w.name, w.intro, w.introformat, w.submissionstart,
  342 + w.submissionend, w.assessmentstart, w.assessmentend,
  343 + cm.id AS cmid
  344 + FROM {workshop} w
  345 + JOIN {modules} m ON m.name = 'workshop'
  346 + JOIN {course_modules} cm ON (cm.module = m.id AND cm.course = w.course AND cm.instance = w.id)";
  347 +
  348 + $rs = $DB->get_recordset_sql($sql);
  349 +
  350 + foreach ($rs as $workshop) {
  351 + $cmid = $workshop->cmid;
  352 + unset($workshop->cmid);
  353 + workshop_calendar_update($workshop, $cmid);
  354 + }
  355 + $rs->close();
  356 + upgrade_mod_savepoint(true, 2011061003, 'workshop');
  357 + }
  358 +
322 359 return true;
323 360 }
4 mod/workshop/lang/en/workshop.php
@@ -49,6 +49,7 @@
49 49 $string['assessmentbyyourself'] = 'Your assessment';
50 50 $string['assessmentdeleted'] = 'Assessment deallocated';
51 51 $string['assessmentend'] = 'Deadline for assessment';
  52 +$string['assessmentendevent'] = '{$a} (assessment deadline)';
52 53 $string['assessmentenddatetime'] = 'Assessment deadline: {$a->daydatetime} ({$a->distanceday})';
53 54 $string['assessmentform'] = 'Assessment form';
54 55 $string['assessmentofsubmission'] = '<a href="{$a->assessmenturl}">Assessment</a> of <a href="{$a->submissionurl}">{$a->submissiontitle}</a>';
@@ -57,6 +58,7 @@
57 58 $string['assessmentreferenceneeded'] = 'You have to assess this example submission to provide a reference assessment. Click \'Continue\' button to assess the submission.';
58 59 $string['assessmentsettings'] = 'Assessment settings';
59 60 $string['assessmentstart'] = 'Open for assessment from';
  61 +$string['assessmentstartevent'] = '{$a} (opens for assessment)';
60 62 $string['assessmentstartdatetime'] = 'Open for assessment from {$a->daydatetime} ({$a->distanceday})';
61 63 $string['assessmentweight'] = 'Assessment weight';
62 64 $string['assignedassessments'] = 'Assigned submissions to assess';
@@ -206,12 +208,14 @@
206 208 $string['submissionattachment'] = 'Attachment';
207 209 $string['submissioncontent'] = 'Submission content';
208 210 $string['submissionend'] = 'Submissions deadline';
  211 +$string['submissionendevent'] = '{$a} (submissions deadline)';
209 212 $string['submissionenddatetime'] = 'Submissions deadline: {$a->daydatetime} ({$a->distanceday})';
210 213 $string['submissiongrade'] = 'Grade for submission';
211 214 $string['submissiongrade_help'] = 'This setting specifies the maximum grade that may be obtained for submitted work.';
212 215 $string['submissiongradeof'] = 'Grade for submission (of {$a})';
213 216 $string['submissionsettings'] = 'Submission settings';
214 217 $string['submissionstart'] = 'Open for submissions from';
  218 +$string['submissionstartevent'] = '{$a} (opens for submissions)';
215 219 $string['submissionstartdatetime'] = 'Open for submissions from {$a->daydatetime} ({$a->distanceday})';
216 220 $string['submissiontitle'] = 'Title';
217 221 $string['subplugintype_workshopallocation'] = 'Submissions allocation method';
106 mod/workshop/lib.php
@@ -29,6 +29,8 @@
29 29
30 30 defined('MOODLE_INTERNAL') || die();
31 31
  32 +require_once($CFG->dirroot . '/calendar/lib.php');
  33 +
32 34 ////////////////////////////////////////////////////////////////////////////////
33 35 // Moodle core API //
34 36 ////////////////////////////////////////////////////////////////////////////////
@@ -106,6 +108,9 @@ function workshop_add_instance(stdclass $workshop) {
106 108 workshop_grade_item_update($workshop);
107 109 workshop_grade_item_category_update($workshop);
108 110
  111 + // create calendar events
  112 + workshop_calendar_update($workshop, $workshop->coursemodule);
  113 +
109 114 return $workshop->id;
110 115 }
111 116
@@ -155,6 +160,9 @@ function workshop_update_instance(stdclass $workshop) {
155 160 workshop_grade_item_update($workshop);
156 161 workshop_grade_item_category_update($workshop);
157 162
  163 + // update calendar events
  164 + workshop_calendar_update($workshop, $workshop->coursemodule);
  165 +
158 166 return true;
159 167 }
160 168
@@ -210,6 +218,13 @@ function workshop_delete_instance($id) {
210 218 call_user_func($classname.'::delete_instance', $workshop->id);
211 219 }
212 220
  221 + // delete the calendar events
  222 + $events = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
  223 + foreach ($events as $event) {
  224 + $event = calendar_event::load($event);
  225 + $event->delete();
  226 + }
  227 +
213 228 // finally remove the workshop record itself
214 229 $DB->delete_records('workshop', array('id' => $workshop->id));
215 230
@@ -1386,3 +1401,94 @@ function workshop_page_type_list($pagetype, $parentcontext, $currentcontext) {
1386 1401 $module_pagetype = array('mod-workshop-*'=>get_string('page-mod-workshop-x', 'workshop'));
1387 1402 return $module_pagetype;
1388 1403 }
  1404 +
  1405 +////////////////////////////////////////////////////////////////////////////////
  1406 +// Calendar API //
  1407 +////////////////////////////////////////////////////////////////////////////////
  1408 +
  1409 +/**
  1410 + * Updates the calendar events associated to the given workshop
  1411 + *
  1412 + * @param stdClass $workshop the workshop instance record
  1413 + * @param int $cmid course module id
  1414 + */
  1415 +function workshop_calendar_update(stdClass $workshop, $cmid) {
  1416 + global $DB;
  1417 +
  1418 + // get the currently registered events so that we can re-use their ids
  1419 + $currentevents = $DB->get_records('event', array('modulename' => 'workshop', 'instance' => $workshop->id));
  1420 +
  1421 + // the common properties for all events
  1422 + $base = new stdClass();
  1423 + $base->description = format_module_intro('workshop', $workshop, $cmid, false);
  1424 + $base->courseid = $workshop->course;
  1425 + $base->groupid = 0;
  1426 + $base->userid = 0;
  1427 + $base->modulename = 'workshop';
  1428 + $base->eventtype = 'pluginname';
  1429 + $base->instance = $workshop->id;
  1430 + $base->visible = instance_is_visible('workshop', $workshop);
  1431 + $base->timeduration = 0;
  1432 +
  1433 + if ($workshop->submissionstart) {
  1434 + $event = clone($base);
  1435 + $event->name = get_string('submissionstartevent', 'mod_workshop', $workshop->name);
  1436 + $event->timestart = $workshop->submissionstart;
  1437 + if ($reusedevent = array_shift($currentevents)) {
  1438 + $event->id = $reusedevent->id;
  1439 + } else {
  1440 + // should not be set but just in case
  1441 + unset($event->id);
  1442 + }
  1443 + // calendar_event::create will reuse a db record if the id field is set
  1444 + calendar_event::create($event);
  1445 + }
  1446 +
  1447 + if ($workshop->submissionend) {
  1448 + $event = clone($base);
  1449 + $event->name = get_string('submissionendevent', 'mod_workshop', $workshop->name);
  1450 + $event->timestart = $workshop->submissionend;
  1451 + if ($reusedevent = array_shift($currentevents)) {
  1452 + $event->id = $reusedevent->id;
  1453 + } else {
  1454 + // should not be set but just in case
  1455 + unset($event->id);
  1456 + }
  1457 + // calendar_event::create will reuse a db record if the id field is set
  1458 + calendar_event::create($event);
  1459 + }
  1460 +
  1461 + if ($workshop->assessmentstart) {
  1462 + $event = clone($base);
  1463 + $event->name = get_string('assessmentstartevent', 'mod_workshop', $workshop->name);
  1464 + $event->timestart = $workshop->assessmentstart;
  1465 + if ($reusedevent = array_shift($currentevents)) {
  1466 + $event->id = $reusedevent->id;
  1467 + } else {
  1468 + // should not be set but just in case
  1469 + unset($event->id);
  1470 + }
  1471 + // calendar_event::create will reuse a db record if the id field is set
  1472 + calendar_event::create($event);
  1473 + }
  1474 +
  1475 + if ($workshop->assessmentend) {
  1476 + $event = clone($base);
  1477 + $event->name = get_string('assessmentendevent', 'mod_workshop', $workshop->name);
  1478 + $event->timestart = $workshop->assessmentend;
  1479 + if ($reusedevent = array_shift($currentevents)) {
  1480 + $event->id = $reusedevent->id;
  1481 + } else {
  1482 + // should not be set but just in case
  1483 + unset($event->id);
  1484 + }
  1485 + // calendar_event::create will reuse a db record if the id field is set
  1486 + calendar_event::create($event);
  1487 + }
  1488 +
  1489 + // delete any leftover events
  1490 + foreach ($currentevents as $oldevent) {
  1491 + $oldevent = calendar_event::load($oldevent);
  1492 + $oldevent->delete();
  1493 + }
  1494 +}
2  mod/workshop/version.php
@@ -29,6 +29,6 @@
29 29
30 30 defined('MOODLE_INTERNAL') || die();
31 31
32   -$module->version = 2011061001;
  32 +$module->version = 2011061003;
33 33 $module->requires = 2011020900; // Requires this Moodle version
34 34 //$module->cron = 60;

0 comments on commit d89ebcc

Please sign in to comment.
Something went wrong with that request. Please try again.