Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add/delete calendar events when adding/updating/deleting hotpots

  • Loading branch information...
commit 172ab5365043f1defb5f2006ccb70ca24057c120 1 parent 6e69ab8
gbateson authored

Showing 1 changed file with 67 additions and 11 deletions. Show diff stats Hide diff stats

  1. +67 11 mod/hotpot/lib.php
78 mod/hotpot/lib.php
@@ -189,22 +189,78 @@
189 189 // $hp->sesskey : unique string required for Moodle's session management
190 190
191 191 function hotpot_add_instance(&$hp) {
192   - if (hotpot_set_form_values($hp)) {
193   - $result = insert_record("hotpot", $hp);
194   - } else {
195   - $result= false;
196   - }
197   - return $result;
  192 + if (hotpot_set_form_values($hp)) {
  193 + if ($result = insert_record('hotpot', $hp)) {
  194 + hotpot_update_events($hp);
  195 + }
  196 + } else {
  197 + $result= false;
  198 + }
  199 + return $result;
198 200 }
199 201
200 202 function hotpot_update_instance(&$hp) {
201   - if (hotpot_set_form_values($hp)) {
202   - $hp->id = $hp->instance;
203   - $result = update_record("hotpot", $hp);
  203 + if (hotpot_set_form_values($hp)) {
  204 + $hp->id = $hp->instance;
  205 + if ($result = update_record('hotpot', $hp)) {
  206 + hotpot_update_events($hp);
  207 + }
  208 + } else {
  209 + $result= false;
  210 + }
  211 + return $result;
  212 +}
  213 +function hotpot_update_events($hotpot) {
  214 +
  215 + // remove any previous calendar events for this hotpot
  216 + delete_records('event', 'modulename', 'hotpot', 'instance', $hotpot->id);
  217 +
  218 + $event = new stdClass();
  219 + $event->description = $hotpot->summary;
  220 + $event->courseid = $hotpot->course;
  221 + $event->groupid = 0;
  222 + $event->userid = 0;
  223 + $event->modulename = 'hotpot';
  224 + $event->instance = $hotpot->id;
  225 + $event->timestart = $hotpot->timeopen;
  226 + if ($cm = get_coursemodule_from_id('hotpot', $hotpot->id)) {
  227 + $event->visible = hotpot_is_visible($cm);
204 228 } else {
205   - $result= false;
  229 + $event->visible = 1;
  230 + }
  231 +
  232 + if ($hotpot->timeclose && $hotpot->timeopen) {
  233 + // we have both a start and an end date
  234 + $event->eventtype = 'open';
  235 + $event->timeduration = ($hotpot->timeclose - $hotpot->timeopen);
  236 +
  237 + if ($event->timeduration > HOTPOT_MAX_EVENT_LENGTH) { /// Long durations create two events
  238 +
  239 + $event->name = $hotpot->name.' ('.get_string('hotpotopens', 'hotpot').')';
  240 + $event->timeduration = 0;
  241 + add_event($event);
  242 +
  243 + $event->timestart = $hotpot->timeclose;
  244 + $event->eventtype = 'close';
  245 + $event->name = $hotpot->name.' ('.get_string('hotpotcloses', 'hotpot').')';
  246 + unset($event->id);
  247 + add_event($event);
  248 + } else { // single event with duration
  249 + $event->name = $hotpot->name;
  250 + add_event($event);
  251 + }
  252 + } elseif ($hotpot->timeopen) { // only an open date
  253 + $event->name = $hotpot->name.' ('.get_string('hotpotopens', 'hotpot').')';
  254 + $event->eventtype = 'open';
  255 + $event->timeduration = 0;
  256 + add_event($event);
  257 + } elseif ($hotpot->timeclose) { // only a closing date
  258 + $event->name = $hotpot->name.' ('.get_string('hotpotcloses', 'hotpot').')';
  259 + $event->timestart = $hotpot->timeclose;
  260 + $event->eventtype = 'close';
  261 + $event->timeduration = 0;
  262 + add_event($event);
206 263 }
207   - return $result;
208 264 }
209 265
210 266 function hotpot_set_form_values(&$hp) {

0 comments on commit 172ab53

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