@@ -56,8 +56,9 @@ public function get_document_recordset($modifiedfrom = 0, \context $context = nu
56
56
return null ;
57
57
}
58
58
59
- $ sql = "SELECT mc.id, mc.course AS courseid, mc.typeid, mcf.name AS fieldname, mcd.id dataid,
60
- mcd.value AS value, mcd.valueformat AS valueformat,
59
+ // Search area is from customfield_data, but if the record is missing from activity, use default value.
60
+ $ sql = "SELECT mc.id, mc.course AS courseid, mc.typeid, mcf.name AS fieldname, mcf.type,
61
+ mcd.id dataid, mcd.value AS value, mcd.valueformat AS valueformat,
61
62
mcd.timecreated AS timecreated, mcd.timemodified AS timemodified
62
63
FROM {cms} mc
63
64
JOIN {customfield_data} mcd ON mc.id = mcd.instanceid
@@ -100,16 +101,15 @@ public function get_document($record, $options = []) {
100
101
return false ;
101
102
}
102
103
104
+ // Get default value for cms custom field.
103
105
if (is_null ($ this ->defaultvalues )) {
104
106
$ defaultvalues = [];
105
- // Get default value for cms custom field.
106
107
$ sql = "SELECT mct.id typeid, mcf.configdata, mcf.name fieldname
107
108
FROM {cms_types} mct
108
109
JOIN {customfield_category} mcc ON mcc.itemid = mct.id
109
110
JOIN {customfield_field} mcf ON mcf.categoryid = mcc.id
110
111
WHERE mcc.component = 'mod_cms' AND mcc.area = 'cmsfield' AND mcf.type IN ('textarea', 'text') " ;
111
112
$ cmstypes = $ DB ->get_records_sql ($ sql );
112
- $ defaultvalues = [];
113
113
foreach ($ cmstypes as $ cmstype ) {
114
114
$ data = new \stdClass ();
115
115
$ configdata = json_decode ($ cmstype ->configdata );
@@ -123,9 +123,17 @@ public function get_document($record, $options = []) {
123
123
124
124
// Check if it's default value or not.
125
125
if (empty ($ record ->dataid )) {
126
- $ title = $ this ->defaultvalues [$ record ->typeid ]->fieldname ?? 'Default title ' ;
127
- $ value = $ this ->defaultvalues [$ record ->typeid ]->value ?? 'Default value ' ;
128
- $ valueformat = $ this ->defaultvalues [$ record ->typeid ]->valueformat ?? 'Default valueformat ' ;
126
+ $ title = $ this ->defaultvalues [$ record ->typeid ]->fieldname ?? '' ;
127
+ $ value = $ this ->defaultvalues [$ record ->typeid ]->value ?? '' ;
128
+ if (isset ($ this ->defaultvalues [$ record ->typeid ]->valueformat )) {
129
+ $ valueformat = $ this ->defaultvalues [$ record ->typeid ]->valueformat ;
130
+ } else {
131
+ if ($ record ->type == 'textarea ' ) {
132
+ $ valueformat = FORMAT_HTML ;
133
+ } else {
134
+ $ valueformat = FORMAT_PLAIN ;
135
+ }
136
+ }
129
137
} else {
130
138
$ title = $ record ->fieldname ;
131
139
$ value = $ record ->value ;
@@ -216,10 +224,7 @@ protected function get_data($id) {
216
224
FROM {customfield_data} mcd
217
225
JOIN {cms} mc ON mc.id = mcd.instanceid
218
226
WHERE mcd.id = :id " ;
219
- $ this ->cmsdata [$ id ] = $ DB ->get_record_sql ($ sql , ['id ' => $ id ]);
220
- if (!$ this ->cmsdata [$ id ]) {
221
- throw new \dml_missing_record_exception ('cms_data ' );
222
- }
227
+ $ this ->cmsdata [$ id ] = $ DB ->get_record_sql ($ sql , ['id ' => $ id ], MUST_EXIST );
223
228
}
224
229
return $ this ->cmsdata [$ id ];
225
230
}
0 commit comments