';
return $str;
}
function display_search_field($value = '') {
return '' .
'';
}
public function parse_search_field($defaults = null) {
$param = 'f_'.$this->field->id;
if (empty($defaults[$param])) {
$defaults = array($param => '');
}
return optional_param($param, $defaults[$param], PARAM_NOTAGS);
}
function generate_sql($tablealias, $value) {
global $DB;
static $i=0;
$i++;
$name = "df_textarea_$i";
return array(" ({$tablealias}.fieldid = {$this->field->id} AND ".$DB->sql_like("{$tablealias}.content", ":$name", false).") ", array($name=>"%$value%"));
}
function print_after_form() {
}
function update_content($recordid, $value, $name='') {
global $DB;
$content = new stdClass();
$content->fieldid = $this->field->id;
$content->recordid = $recordid;
$names = explode('_', $name);
if (!empty($names[2])) {
if ($names[2] == 'itemid') {
// the value will be retrieved by file_get_submitted_draft_itemid, do not need to save in DB
return true;
} else {
$content->{$names[2]} = clean_param($value, PARAM_NOTAGS); // content[1-4]
}
} else {
$content->content = clean_param($value, PARAM_CLEAN);
}
if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) {
$content->id = $oldcontent->id;
} else {
$content->id = $DB->insert_record('data_content', $content);
if (!$content->id) {
return false;
}
}
if (!empty($content->content)) {
$draftitemid = file_get_submitted_draft_itemid('field_'. $this->field->id. '_itemid');
$options = $this->get_options();
$content->content = file_save_draft_area_files($draftitemid, $this->context->id, 'mod_data', 'content', $content->id, $options, $content->content);
}
$rv = $DB->update_record('data_content', $content);
return $rv;
}
/**
* Display the content of the field in browse mode
*
* @param int $recordid
* @param object $template
* @return bool|string
*/
function display_browse_field($recordid, $template) {
$content = $this->get_data_content($recordid);
if (!$content || !isset($content->content)) {
return '';
}
$options = new stdClass();
if ($this->field->param1 == '1') { // We are autolinking this field, so disable linking within us.
$options->filter = false;
}
$options->para = false;
$str = file_rewrite_pluginfile_urls(
$content->content,
'pluginfile.php',
$this->context->id,
'mod_data',
'content',
$content->id,
$this->get_options()
);
$str = format_text($str, $content->content1, $options);
return '
' . $str . '
';
}
/**
* Whether this module support files
*
* @param string $relativepath
* @return bool
*/
function file_ok($relativepath) {
return true;
}
/**
* Only look at the first item (second is format)
*
* @param string $value
* @param string $name
* @return bool
*/
function notemptyfield($value, $name) {
$names = explode('_', $name);
// Clean first.
if (count($names) == 2) {
// Don't assume that this is coming from a text editor with tags.
return strval($value) !== '';
}
return false;
}
/**
* Returns the presentable string value for a field content.
*
* The returned string should be plain text.
*
* @param stdClass $content
* @return string
*/
public static function get_content_value($content) {
return content_to_text($content->content, $content->content1);
}
/**
* Return the plugin configs for external functions.
*
* @return array the list of config parameters
* @since Moodle 3.3
*/
public function get_config_for_external() {
// Return all the config parameters.
$configs = [];
for ($i = 1; $i <= 10; $i++) {
$configs["param$i"] = $this->field->{"param$i"};
}
return $configs;
}
}