From a48bf07993dcc4e74351b71c055387459f92e4a0 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Fri, 30 Apr 2010 10:53:39 +0000 Subject: [PATCH] Fixing Chat event type + handling illegal eventtype displaying Without this fix, chat created events with eventtype set to boolean. Such value was then used by calendar block to get a string, which now produces coding_exception. --- calendar/lib.php | 7 ++++++- lib/moodlelib.php | 8 ++++++++ mod/chat/lib.php | 4 ++-- mod/choice/mod_form.php | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index d9bdc9f7d11..1c38b896319 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -501,7 +501,12 @@ function calendar_add_event_metadata($event) { } $modulename = get_string('modulename', $event->modulename); - $eventtype = get_string($event->eventtype, $event->modulename); + if (get_string_manager()->string_exists($event->eventtype, $event->modulename)) { + // will be used as alt text if the event icon + $eventtype = get_string($event->eventtype, $event->modulename); + } else { + $eventtype = ''; + } $icon = $OUTPUT->pix_url('icon', $event->modulename) . ''; $event->icon = ''.$eventtype.''; diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 6bc9d0feb6d..cc3b2b745a0 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5968,6 +5968,10 @@ class core_string_manager implements string_manager { * @return boot true if exists */ public function string_exists($identifier, $component) { + $identifier = clean_param($identifier, PARAM_STRINGID); + if (empty($identifier)) { + return false; + } $lang = current_language(); $string = $this->load_component_strings($component, $lang); return isset($string[$identifier]); @@ -6293,6 +6297,10 @@ class install_string_manager implements string_manager { * @return boot true if exists */ public function string_exists($identifier, $component) { + $identifier = clean_param($identifier, PARAM_STRINGID); + if (empty($identifier)) { + return false; + } // simple old style hack ;) $str = get_string($identifier, $component); return (strpos($str, '[[') === false); diff --git a/mod/chat/lib.php b/mod/chat/lib.php index 084ab605e62..49fb9650293 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -120,7 +120,7 @@ function chat_add_instance($chat) { $event->userid = 0; $event->modulename = 'chat'; $event->instance = $returnid; - $event->eventtype = $chat->schedule; + $event->eventtype = 'chattime'; $event->timestart = $chat->chattime; $event->timeduration = 0; @@ -499,7 +499,7 @@ function chat_refresh_events($courseid = 0) { $event->userid = 0; $event->modulename = 'chat'; $event->instance = $chat->id; - $event->eventtype = $chat->schedule; + $event->eventtype = 'chattime'; $event->timeduration = 0; $event->visible = $DB->get_field('course_modules', 'visible', array('module'=>$moduleid, 'instance'=>$chat->id)); diff --git a/mod/choice/mod_form.php b/mod/choice/mod_form.php index 19b45119bc9..0195f727bdd 100644 --- a/mod/choice/mod_form.php +++ b/mod/choice/mod_form.php @@ -33,7 +33,7 @@ class mod_choice_mod_form extends moodleform_mod { $menuoptions[1] = get_string('enable'); $mform->addElement('header', 'timerestricthdr', get_string('limit', 'choice')); $mform->addElement('select', 'limitanswers', get_string('limitanswers', 'choice'), $menuoptions); - $mform->setHelpButton('limitanswers', array('limit', get_string('limit', 'choice'), 'choice')); + $mform->addHelpButton('limitanswers', 'choice'); if ($this->_instance){ $repeatno = $DB->count_records('choice_options', array('choiceid'=>$this->_instance));