Merge branch 'MDL-61650-master' of git://github.com/damyon/moodle
[moodle.git] / mod / assign / submission / onlinetext / locallib.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
17 /**
18  * This file contains the definition for the library class for onlinetext submission plugin
19  *
20  * This class provides all the functionality for the new assign module.
21  *
22  * @package assignsubmission_onlinetext
23  * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
24  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25  */
27 defined('MOODLE_INTERNAL') || die();
28 // File area for online text submission assignment.
29 define('ASSIGNSUBMISSION_ONLINETEXT_FILEAREA', 'submissions_onlinetext');
31 /**
32  * library class for onlinetext submission plugin extending submission plugin base class
33  *
34  * @package assignsubmission_onlinetext
35  * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
36  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37  */
38 class assign_submission_onlinetext extends assign_submission_plugin {
40     /**
41      * Get the name of the online text submission plugin
42      * @return string
43      */
44     public function get_name() {
45         return get_string('onlinetext', 'assignsubmission_onlinetext');
46     }
49     /**
50      * Get onlinetext submission information from the database
51      *
52      * @param  int $submissionid
53      * @return mixed
54      */
55     private function get_onlinetext_submission($submissionid) {
56         global $DB;
58         return $DB->get_record('assignsubmission_onlinetext', array('submission'=>$submissionid));
59     }
61     /**
62      * Get the settings for onlinetext submission plugin
63      *
64      * @param MoodleQuickForm $mform The form to add elements to
65      * @return void
66      */
67     public function get_settings(MoodleQuickForm $mform) {
68         global $CFG, $COURSE;
70         $defaultwordlimit = $this->get_config('wordlimit') == 0 ? '' : $this->get_config('wordlimit');
71         $defaultwordlimitenabled = $this->get_config('wordlimitenabled');
73         $options = array('size' => '6', 'maxlength' => '6');
74         $name = get_string('wordlimit', 'assignsubmission_onlinetext');
76         // Create a text box that can be enabled/disabled for onlinetext word limit.
77         $wordlimitgrp = array();
78         $wordlimitgrp[] = $mform->createElement('text', 'assignsubmission_onlinetext_wordlimit', '', $options);
79         $wordlimitgrp[] = $mform->createElement('checkbox', 'assignsubmission_onlinetext_wordlimit_enabled',
80                 '', get_string('enable'));
81         $mform->addGroup($wordlimitgrp, 'assignsubmission_onlinetext_wordlimit_group', $name, ' ', false);
82         $mform->addHelpButton('assignsubmission_onlinetext_wordlimit_group',
83                               'wordlimit',
84                               'assignsubmission_onlinetext');
85         $mform->disabledIf('assignsubmission_onlinetext_wordlimit',
86                            'assignsubmission_onlinetext_wordlimit_enabled',
87                            'notchecked');
89         // Add numeric rule to text field.
90         $wordlimitgrprules = array();
91         $wordlimitgrprules['assignsubmission_onlinetext_wordlimit'][] = array(null, 'numeric', null, 'client');
92         $mform->addGroupRule('assignsubmission_onlinetext_wordlimit_group', $wordlimitgrprules);
94         // Rest of group setup.
95         $mform->setDefault('assignsubmission_onlinetext_wordlimit', $defaultwordlimit);
96         $mform->setDefault('assignsubmission_onlinetext_wordlimit_enabled', $defaultwordlimitenabled);
97         $mform->setType('assignsubmission_onlinetext_wordlimit', PARAM_INT);
98         $mform->disabledIf('assignsubmission_onlinetext_wordlimit_group',
99                            'assignsubmission_onlinetext_enabled',
100                            'notchecked');
101     }
103     /**
104      * Save the settings for onlinetext submission plugin
105      *
106      * @param stdClass $data
107      * @return bool
108      */
109     public function save_settings(stdClass $data) {
110         if (empty($data->assignsubmission_onlinetext_wordlimit) || empty($data->assignsubmission_onlinetext_wordlimit_enabled)) {
111             $wordlimit = 0;
112             $wordlimitenabled = 0;
113         } else {
114             $wordlimit = $data->assignsubmission_onlinetext_wordlimit;
115             $wordlimitenabled = 1;
116         }
118         $this->set_config('wordlimit', $wordlimit);
119         $this->set_config('wordlimitenabled', $wordlimitenabled);
121         return true;
122     }
124     /**
125      * Add form elements for settings
126      *
127      * @param mixed $submission can be null
128      * @param MoodleQuickForm $mform
129      * @param stdClass $data
130      * @return true if elements were added to the form
131      */
132     public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) {
133         $elements = array();
135         $editoroptions = $this->get_edit_options();
136         $submissionid = $submission ? $submission->id : 0;
138         if (!isset($data->onlinetext)) {
139             $data->onlinetext = '';
140         }
141         if (!isset($data->onlinetextformat)) {
142             $data->onlinetextformat = editors_get_preferred_format();
143         }
145         if ($submission) {
146             $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
147             if ($onlinetextsubmission) {
148                 $data->onlinetext = $onlinetextsubmission->onlinetext;
149                 $data->onlinetextformat = $onlinetextsubmission->onlineformat;
150             }
152         }
154         $data = file_prepare_standard_editor($data,
155                                              'onlinetext',
156                                              $editoroptions,
157                                              $this->assignment->get_context(),
158                                              'assignsubmission_onlinetext',
159                                              ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
160                                              $submissionid);
161         $mform->addElement('editor', 'onlinetext_editor', $this->get_name(), null, $editoroptions);
163         return true;
164     }
166     /**
167      * Editor format options
168      *
169      * @return array
170      */
171     private function get_edit_options() {
172         $editoroptions = array(
173             'noclean' => false,
174             'maxfiles' => EDITOR_UNLIMITED_FILES,
175             'maxbytes' => $this->assignment->get_course()->maxbytes,
176             'context' => $this->assignment->get_context(),
177             'return_types' => (FILE_INTERNAL | FILE_EXTERNAL | FILE_CONTROLLED_LINK),
178             'removeorphaneddrafts' => true // Whether or not to remove any draft files which aren't referenced in the text.
179         );
180         return $editoroptions;
181     }
183     /**
184      * Save data to the database and trigger plagiarism plugin,
185      * if enabled, to scan the uploaded content via events trigger
186      *
187      * @param stdClass $submission
188      * @param stdClass $data
189      * @return bool
190      */
191     public function save(stdClass $submission, stdClass $data) {
192         global $USER, $DB;
194         $editoroptions = $this->get_edit_options();
196         $data = file_postupdate_standard_editor($data,
197                                                 'onlinetext',
198                                                 $editoroptions,
199                                                 $this->assignment->get_context(),
200                                                 'assignsubmission_onlinetext',
201                                                 ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
202                                                 $submission->id);
204         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
206         $fs = get_file_storage();
208         $files = $fs->get_area_files($this->assignment->get_context()->id,
209                                      'assignsubmission_onlinetext',
210                                      ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
211                                      $submission->id,
212                                      'id',
213                                      false);
215         // Check word count before submitting anything.
216         $exceeded = $this->check_word_count(trim($data->onlinetext));
217         if ($exceeded) {
218             $this->set_error($exceeded);
219             return false;
220         }
222         $params = array(
223             'context' => context_module::instance($this->assignment->get_course_module()->id),
224             'courseid' => $this->assignment->get_course()->id,
225             'objectid' => $submission->id,
226             'other' => array(
227                 'pathnamehashes' => array_keys($files),
228                 'content' => trim($data->onlinetext),
229                 'format' => $data->onlinetext_editor['format']
230             )
231         );
232         if (!empty($submission->userid) && ($submission->userid != $USER->id)) {
233             $params['relateduserid'] = $submission->userid;
234         }
235         $event = \assignsubmission_onlinetext\event\assessable_uploaded::create($params);
236         $event->trigger();
238         $groupname = null;
239         $groupid = 0;
240         // Get the group name as other fields are not transcribed in the logs and this information is important.
241         if (empty($submission->userid) && !empty($submission->groupid)) {
242             $groupname = $DB->get_field('groups', 'name', array('id' => $submission->groupid), MUST_EXIST);
243             $groupid = $submission->groupid;
244         } else {
245             $params['relateduserid'] = $submission->userid;
246         }
248         $count = count_words($data->onlinetext);
250         // Unset the objectid and other field from params for use in submission events.
251         unset($params['objectid']);
252         unset($params['other']);
253         $params['other'] = array(
254             'submissionid' => $submission->id,
255             'submissionattempt' => $submission->attemptnumber,
256             'submissionstatus' => $submission->status,
257             'onlinetextwordcount' => $count,
258             'groupid' => $groupid,
259             'groupname' => $groupname
260         );
262         if ($onlinetextsubmission) {
264             $onlinetextsubmission->onlinetext = $data->onlinetext;
265             $onlinetextsubmission->onlineformat = $data->onlinetext_editor['format'];
266             $params['objectid'] = $onlinetextsubmission->id;
267             $updatestatus = $DB->update_record('assignsubmission_onlinetext', $onlinetextsubmission);
268             $event = \assignsubmission_onlinetext\event\submission_updated::create($params);
269             $event->set_assign($this->assignment);
270             $event->trigger();
271             return $updatestatus;
272         } else {
274             $onlinetextsubmission = new stdClass();
275             $onlinetextsubmission->onlinetext = $data->onlinetext;
276             $onlinetextsubmission->onlineformat = $data->onlinetext_editor['format'];
278             $onlinetextsubmission->submission = $submission->id;
279             $onlinetextsubmission->assignment = $this->assignment->get_instance()->id;
280             $onlinetextsubmission->id = $DB->insert_record('assignsubmission_onlinetext', $onlinetextsubmission);
281             $params['objectid'] = $onlinetextsubmission->id;
282             $event = \assignsubmission_onlinetext\event\submission_created::create($params);
283             $event->set_assign($this->assignment);
284             $event->trigger();
285             return $onlinetextsubmission->id > 0;
286         }
287     }
289     /**
290      * Return a list of the text fields that can be imported/exported by this plugin
291      *
292      * @return array An array of field names and descriptions. (name=>description, ...)
293      */
294     public function get_editor_fields() {
295         return array('onlinetext' => get_string('pluginname', 'assignsubmission_onlinetext'));
296     }
298     /**
299      * Get the saved text content from the editor
300      *
301      * @param string $name
302      * @param int $submissionid
303      * @return string
304      */
305     public function get_editor_text($name, $submissionid) {
306         if ($name == 'onlinetext') {
307             $onlinetextsubmission = $this->get_onlinetext_submission($submissionid);
308             if ($onlinetextsubmission) {
309                 return $onlinetextsubmission->onlinetext;
310             }
311         }
313         return '';
314     }
316     /**
317      * Get the content format for the editor
318      *
319      * @param string $name
320      * @param int $submissionid
321      * @return int
322      */
323     public function get_editor_format($name, $submissionid) {
324         if ($name == 'onlinetext') {
325             $onlinetextsubmission = $this->get_onlinetext_submission($submissionid);
326             if ($onlinetextsubmission) {
327                 return $onlinetextsubmission->onlineformat;
328             }
329         }
331         return 0;
332     }
335      /**
336       * Display onlinetext word count in the submission status table
337       *
338       * @param stdClass $submission
339       * @param bool $showviewlink - If the summary has been truncated set this to true
340       * @return string
341       */
342     public function view_summary(stdClass $submission, & $showviewlink) {
343         global $CFG;
345         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
346         // Always show the view link.
347         $showviewlink = true;
349         if ($onlinetextsubmission) {
350             // This contains the shortened version of the text plus an optional 'Export to portfolio' button.
351             $text = $this->assignment->render_editor_content(ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
352                                                              $onlinetextsubmission->submission,
353                                                              $this->get_type(),
354                                                              'onlinetext',
355                                                              'assignsubmission_onlinetext', true);
357             // The actual submission text.
358             $onlinetext = trim($onlinetextsubmission->onlinetext);
359             // The shortened version of the submission text.
360             $shorttext = shorten_text($onlinetext, 140);
362             $plagiarismlinks = '';
364             if (!empty($CFG->enableplagiarism)) {
365                 require_once($CFG->libdir . '/plagiarismlib.php');
367                 $plagiarismlinks .= plagiarism_get_links(array('userid' => $submission->userid,
368                     'content' => $onlinetext,
369                     'cmid' => $this->assignment->get_course_module()->id,
370                     'course' => $this->assignment->get_course()->id,
371                     'assignment' => $submission->assignment));
372             }
373             // We compare the actual text submission and the shortened version. If they are not equal, we show the word count.
374             if ($onlinetext != $shorttext) {
375                 $wordcount = get_string('numwords', 'assignsubmission_onlinetext', count_words($onlinetext));
377                 return $plagiarismlinks . $wordcount . $text;
378             } else {
379                 return $plagiarismlinks . $text;
380             }
381         }
382         return '';
383     }
385     /**
386      * Produce a list of files suitable for export that represent this submission.
387      *
388      * @param stdClass $submission - For this is the submission data
389      * @param stdClass $user - This is the user record for this submission
390      * @return array - return an array of files indexed by filename
391      */
392     public function get_files(stdClass $submission, stdClass $user) {
393         global $DB;
395         $files = array();
396         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
398         // Note that this check is the same logic as the result from the is_empty function but we do
399         // not call it directly because we already have the submission record.
400         if ($onlinetextsubmission && !empty($onlinetextsubmission->onlinetext)) {
401             $finaltext = $this->assignment->download_rewrite_pluginfile_urls($onlinetextsubmission->onlinetext, $user, $this);
402             $formattedtext = format_text($finaltext,
403                                          $onlinetextsubmission->onlineformat,
404                                          array('context'=>$this->assignment->get_context()));
405             $head = '<head><meta charset="UTF-8"></head>';
406             $submissioncontent = '<!DOCTYPE html><html>' . $head . '<body>'. $formattedtext . '</body></html>';
408             $filename = get_string('onlinetextfilename', 'assignsubmission_onlinetext');
409             $files[$filename] = array($submissioncontent);
411             $fs = get_file_storage();
413             $fsfiles = $fs->get_area_files($this->assignment->get_context()->id,
414                                            'assignsubmission_onlinetext',
415                                            ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
416                                            $submission->id,
417                                            'timemodified',
418                                            false);
420             foreach ($fsfiles as $file) {
421                 $files[$file->get_filename()] = $file;
422             }
423         }
425         return $files;
426     }
428     /**
429      * Display the saved text content from the editor in the view table
430      *
431      * @param stdClass $submission
432      * @return string
433      */
434     public function view(stdClass $submission) {
435         global $CFG;
436         $result = '';
438         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
440         if ($onlinetextsubmission) {
442             // Render for portfolio API.
443             $result .= $this->assignment->render_editor_content(ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
444                                                                 $onlinetextsubmission->submission,
445                                                                 $this->get_type(),
446                                                                 'onlinetext',
447                                                                 'assignsubmission_onlinetext');
449             $plagiarismlinks = '';
451             if (!empty($CFG->enableplagiarism)) {
452                 require_once($CFG->libdir . '/plagiarismlib.php');
454                 $plagiarismlinks .= plagiarism_get_links(array('userid' => $submission->userid,
455                     'content' => trim($onlinetextsubmission->onlinetext),
456                     'cmid' => $this->assignment->get_course_module()->id,
457                     'course' => $this->assignment->get_course()->id,
458                     'assignment' => $submission->assignment));
459             }
460         }
462         return $plagiarismlinks . $result;
463     }
465     /**
466      * Return true if this plugin can upgrade an old Moodle 2.2 assignment of this type and version.
467      *
468      * @param string $type old assignment subtype
469      * @param int $version old assignment version
470      * @return bool True if upgrade is possible
471      */
472     public function can_upgrade($type, $version) {
473         if ($type == 'online' && $version >= 2011112900) {
474             return true;
475         }
476         return false;
477     }
480     /**
481      * Upgrade the settings from the old assignment to the new plugin based one
482      *
483      * @param context $oldcontext - the database for the old assignment context
484      * @param stdClass $oldassignment - the database for the old assignment instance
485      * @param string $log record log events here
486      * @return bool Was it a success?
487      */
488     public function upgrade_settings(context $oldcontext, stdClass $oldassignment, & $log) {
489         // No settings to upgrade.
490         return true;
491     }
493     /**
494      * Upgrade the submission from the old assignment to the new one
495      *
496      * @param context $oldcontext - the database for the old assignment context
497      * @param stdClass $oldassignment The data record for the old assignment
498      * @param stdClass $oldsubmission The data record for the old submission
499      * @param stdClass $submission The data record for the new submission
500      * @param string $log Record upgrade messages in the log
501      * @return bool true or false - false will trigger a rollback
502      */
503     public function upgrade(context $oldcontext,
504                             stdClass $oldassignment,
505                             stdClass $oldsubmission,
506                             stdClass $submission,
507                             & $log) {
508         global $DB;
510         $onlinetextsubmission = new stdClass();
511         $onlinetextsubmission->onlinetext = $oldsubmission->data1;
512         $onlinetextsubmission->onlineformat = $oldsubmission->data2;
514         $onlinetextsubmission->submission = $submission->id;
515         $onlinetextsubmission->assignment = $this->assignment->get_instance()->id;
517         if ($onlinetextsubmission->onlinetext === null) {
518             $onlinetextsubmission->onlinetext = '';
519         }
521         if ($onlinetextsubmission->onlineformat === null) {
522             $onlinetextsubmission->onlineformat = editors_get_preferred_format();
523         }
525         if (!$DB->insert_record('assignsubmission_onlinetext', $onlinetextsubmission) > 0) {
526             $log .= get_string('couldnotconvertsubmission', 'mod_assign', $submission->userid);
527             return false;
528         }
530         // Now copy the area files.
531         $this->assignment->copy_area_files_for_upgrade($oldcontext->id,
532                                                         'mod_assignment',
533                                                         'submission',
534                                                         $oldsubmission->id,
535                                                         $this->assignment->get_context()->id,
536                                                         'assignsubmission_onlinetext',
537                                                         ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
538                                                         $submission->id);
539         return true;
540     }
542     /**
543      * Formatting for log info
544      *
545      * @param stdClass $submission The new submission
546      * @return string
547      */
548     public function format_for_log(stdClass $submission) {
549         // Format the info for each submission plugin (will be logged).
550         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
551         $onlinetextloginfo = '';
552         $onlinetextloginfo .= get_string('numwordsforlog',
553                                          'assignsubmission_onlinetext',
554                                          count_words($onlinetextsubmission->onlinetext));
556         return $onlinetextloginfo;
557     }
559     /**
560      * The assignment has been deleted - cleanup
561      *
562      * @return bool
563      */
564     public function delete_instance() {
565         global $DB;
566         $DB->delete_records('assignsubmission_onlinetext',
567                             array('assignment'=>$this->assignment->get_instance()->id));
569         return true;
570     }
572     /**
573      * No text is set for this plugin
574      *
575      * @param stdClass $submission
576      * @return bool
577      */
578     public function is_empty(stdClass $submission) {
579         $onlinetextsubmission = $this->get_onlinetext_submission($submission->id);
580         $wordcount = 0;
582         if (isset($onlinetextsubmission->onlinetext)) {
583             $wordcount = count_words(trim($onlinetextsubmission->onlinetext));
584         }
586         return $wordcount == 0;
587     }
589     /**
590      * Determine if a submission is empty
591      *
592      * This is distinct from is_empty in that it is intended to be used to
593      * determine if a submission made before saving is empty.
594      *
595      * @param stdClass $data The submission data
596      * @return bool
597      */
598     public function submission_is_empty(stdClass $data) {
599         if (!isset($data->onlinetext_editor)) {
600             return true;
601         }
602         $wordcount = 0;
604         if (isset($data->onlinetext_editor['text'])) {
605             $wordcount = count_words(trim((string)$data->onlinetext_editor['text']));
606         }
608         return $wordcount == 0;
609     }
611     /**
612      * Get file areas returns a list of areas this plugin stores files
613      * @return array - An array of fileareas (keys) and descriptions (values)
614      */
615     public function get_file_areas() {
616         return array(ASSIGNSUBMISSION_ONLINETEXT_FILEAREA=>$this->get_name());
617     }
619     /**
620      * Copy the student's submission from a previous submission. Used when a student opts to base their resubmission
621      * on the last submission.
622      * @param stdClass $sourcesubmission
623      * @param stdClass $destsubmission
624      */
625     public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmission) {
626         global $DB;
628         // Copy the files across (attached via the text editor).
629         $contextid = $this->assignment->get_context()->id;
630         $fs = get_file_storage();
631         $files = $fs->get_area_files($contextid, 'assignsubmission_onlinetext',
632                                      ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $sourcesubmission->id, 'id', false);
633         foreach ($files as $file) {
634             $fieldupdates = array('itemid' => $destsubmission->id);
635             $fs->create_file_from_storedfile($fieldupdates, $file);
636         }
638         // Copy the assignsubmission_onlinetext record.
639         $onlinetextsubmission = $this->get_onlinetext_submission($sourcesubmission->id);
640         if ($onlinetextsubmission) {
641             unset($onlinetextsubmission->id);
642             $onlinetextsubmission->submission = $destsubmission->id;
643             $DB->insert_record('assignsubmission_onlinetext', $onlinetextsubmission);
644         }
645         return true;
646     }
648     /**
649      * Return a description of external params suitable for uploading an onlinetext submission from a webservice.
650      *
651      * @return external_description|null
652      */
653     public function get_external_parameters() {
654         $editorparams = array('text' => new external_value(PARAM_RAW, 'The text for this submission.'),
655                               'format' => new external_value(PARAM_INT, 'The format for this submission'),
656                               'itemid' => new external_value(PARAM_INT, 'The draft area id for files attached to the submission'));
657         $editorstructure = new external_single_structure($editorparams, 'Editor structure', VALUE_OPTIONAL);
658         return array('onlinetext_editor' => $editorstructure);
659     }
661     /**
662      * Compare word count of onlinetext submission to word limit, and return result.
663      *
664      * @param string $submissiontext Onlinetext submission text from editor
665      * @return string Error message if limit is enabled and exceeded, otherwise null
666      */
667     public function check_word_count($submissiontext) {
668         global $OUTPUT;
670         $wordlimitenabled = $this->get_config('wordlimitenabled');
671         $wordlimit = $this->get_config('wordlimit');
673         if ($wordlimitenabled == 0) {
674             return null;
675         }
677         // Count words and compare to limit.
678         $wordcount = count_words($submissiontext);
679         if ($wordcount <= $wordlimit) {
680             return null;
681         } else {
682             $errormsg = get_string('wordlimitexceeded', 'assignsubmission_onlinetext',
683                     array('limit' => $wordlimit, 'count' => $wordcount));
684             return $OUTPUT->error_text($errormsg);
685         }
686     }
688     /**
689      * Return the plugin configs for external functions.
690      *
691      * @return array the list of settings
692      * @since Moodle 3.2
693      */
694     public function get_config_for_external() {
695         return (array) $this->get_config();
696     }