Skip to content

Commit

Permalink
calendar MDL-23932 Defaults now set when initialising a calendar_even…
Browse files Browse the repository at this point in the history
…t object
  • Loading branch information
Sam Hemelryk committed Aug 25, 2010
1 parent d37e440 commit c203a27
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ class calendar_event {
* an event
*/
public function __construct($data=null) {
global $CFG;
global $CFG, $USER;

// First convert to object if it is not already (should either be object or assoc array)
if (!is_object($data)) {
Expand All @@ -1675,6 +1675,16 @@ public function __construct($data=null) {
$data->id = null;
}

// Default to a user event
if (empty($data->eventtype)) {
$data->eventtype = 'user';
}

// Default to the current user
if (empty($data->userid)) {
$data->userid = $USER->id;
}

if (!empty($data->timeduration) && is_array($data->timeduration)) {
$data->timeduration = make_timestamp($data->timeduration['year'], $data->timeduration['month'], $data->timeduration['day'], $data->timeduration['hour'], $data->timeduration['minute']) - $data->timestart;
}
Expand All @@ -1685,6 +1695,10 @@ public function __construct($data=null) {
$data->description = '';
$data->format = editors_get_preferred_format();
}
// Ensure form is defaulted correctly
if (empty($data->format)) {
$data->format = editors_get_preferred_format();
}

$this->properties = $data;
}
Expand Down Expand Up @@ -1718,6 +1732,9 @@ public function __get($key) {
if (method_exists($this, 'get_'.$key)) {
return $this->{'get_'.$key}();
}
if (!isset($this->properties->{$key})) {
throw new coding_exception('Undefined property requested');
}
return $this->properties->{$key};
}

Expand Down

0 comments on commit c203a27

Please sign in to comment.