MDL-28094 add function that detects if subdirs used and fix subdirs option in form editor

This commit is contained in:
Petr Škoda 2013-08-25 15:09:39 +02:00
parent b69ec2889e
commit 4db9d48253
2 changed files with 29 additions and 1 deletions

View File

@ -80,6 +80,31 @@ function file_encode_url($urlbase, $path, $forcedownload=false, $https=false) {
return $return;
}
/**
* Detects if area contains subdirs,
* this is intended for file areas that are attached to content
* migrated from 1.x where subdirs were allowed everywhere.
*
* @param context $context
* @param string $component
* @param string $filearea
* @param string $itemid
* @return bool
*/
function file_area_contains_subdirs(context $context, $component, $filearea, $itemid) {
global $DB;
if (!isset($itemid)) {
// Not initialised yet.
return false;
}
// Detect if any directories are already present, this is necessary for content upgraded from 1.x.
$select = "contextid = :contextid AND component = :component AND filearea = :filearea AND itemid = :itemid AND filepath <> '/' AND filename = '.'";
$params = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid);
return $DB->record_exists_select('files', $select, $params);
}
/**
* Prepares 'editor' formslib element from data in database
*

View File

@ -91,6 +91,9 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
$this->_options['trusted'] = trusttext_trusted($this->_options['context']);
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
// Note: for some reason the code using this setting does not like bools.
$this->_options['subdirs'] = (int)($this->_options['subdirs'] == 1);
editors_head_setup();
}
@ -205,7 +208,7 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element {
* @param bool $allow true if sub directory can be created.
*/
function setSubdirs($allow) {
$this->_options['subdirs'] = $allow;
$this->_options['subdirs'] = (int)($allow == 1);
}
/**