Permalink
Browse files

MDL-36551 - mod_data: Onsite presets now retain the advanced search t…

…emplate.

Presets that were saved to the site would lose the advanced search template when being used.
The previous check was put in place to see if the advanced search template existed or not (presets pre 1.9),
This checked external files properly but not onsite files.

Now checks are being done on both internal and external preset files.
  • Loading branch information...
abgreeve committed Nov 14, 2012
1 parent b969895 commit f0a7956c1b334b50138671439f426ffe016c4dde
Showing with 15 additions and 12 deletions.
  1. +15 −12 mod/data/lib.php
View
@@ -2172,17 +2172,25 @@ public function get_directory() {
* @param stored_file $fileobj the directory to look in. null if using a conventional directory
* @param string $dir the directory to look in. null if using the Moodle file storage
* @param string $filename the name of the file we want
- * @return string the contents of the file
+ * @return string the contents of the file or null if the file doesn't exist.
*/
public function data_preset_get_file_contents(&$filestorage, &$fileobj, $dir, $filename) {
if(empty($filestorage) || empty($fileobj)) {
if (substr($dir, -1)!='/') {
$dir .= '/';
}
- return file_get_contents($dir.$filename);
+ if (file_exists($dir.$filename)) {
+ return file_get_contents($dir.$filename);
+ } else {
+ return null;
+ }
} else {
- $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename);
- return $file->get_content();
+ if ($filestorage->file_exists(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename)) {
+ $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename);
+ return $file->get_content();
+ } else {
+ return null;
+ }
}
}
@@ -2202,7 +2210,8 @@ public function get_preset_settings() {
$files = $fs->get_area_files(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA);
//preset name to find will be the final element of the directory
- $presettofind = end(explode('/',$this->directory));
+ $explodeddirectory = explode('/', $this->directory);
+ $presettofind = end($explodeddirectory);
//now go through the available files available and see if we can find it
foreach ($files as $file) {
@@ -2283,15 +2292,9 @@ public function get_preset_settings() {
$result->settings->rsstitletemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"rsstitletemplate.html");
$result->settings->csstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"csstemplate.css");
$result->settings->jstemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"jstemplate.js");
+ $result->settings->asearchtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"asearchtemplate.html");
- //optional
- if (file_exists($this->directory."/asearchtemplate.html")) {
- $result->settings->asearchtemplate = $this->data_preset_get_file_contents($fs, $fileobj,$this->directory,"asearchtemplate.html");
- } else {
- $result->settings->asearchtemplate = NULL;
- }
$result->settings->instance = $this->module->id;
-
return $result;
}

0 comments on commit f0a7956

Please sign in to comment.