protected function set_customdata($customdata) {
        // Always include the courseid (because is not stored in the notifications or messages table).
        if (!empty($this->courseid) && (is_object($customdata) || is_array($customdata))) {
            $customdata = (array) $customdata;
            $customdata['courseid'] = $this->courseid;
        }
        $this->customdata = json_encode($customdata);
    }