calendar MDL-23932 Defaults now set when initialising a calendar_event object

This commit is contained in:
Sam Hemelryk 2010-08-25 06:08:16 +00:00
parent d37e440a7b
commit c203a277e4

View File

@ -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)) {
@ -1675,6 +1675,16 @@ class calendar_event {
$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;
}
@ -1685,6 +1695,10 @@ class calendar_event {
$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;
}
@ -1718,6 +1732,9 @@ class calendar_event {
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};
}