MDL-37455 mod_folder can display content inline. Coding style corrections
authorMarina Glancy <marina@moodle.com>
Fri, 15 Feb 2013 09:12:31 +0000 (20:12 +1100)
committerMarina Glancy <marina@moodle.com>
Sat, 23 Feb 2013 01:03:58 +0000 (12:03 +1100)
mod/folder/edit.php
mod/folder/lang/en/folder.php
mod/folder/lib.php

index 33f219f..687181f 100644 (file)
@@ -52,7 +52,7 @@ $options = array('subdirs'=>1, 'maxbytes'=>$CFG->maxbytes, 'maxfiles'=>-1, 'acce
 file_prepare_standard_filemanager($data, 'files', $options, $context, 'mod_folder', 'content', 0);
 
 $mform = new mod_folder_edit_form(null, array('data'=>$data, 'options'=>$options));
-if (!empty($folder->display) && $folder->display == FOLDER_DISPLAY_INLINE) {
+if ($folder->display == FOLDER_DISPLAY_INLINE) {
     $redirecturl = course_get_url($cm->course, $cm->sectionnum);
 } else {
     $redirecturl = new moodle_url('/mod/folder/view.php', array('id' => $cm->id));
index c499be3..1e9f751 100644 (file)
@@ -45,11 +45,9 @@ $string['page-mod-folder-view'] = 'Folder module main page';
 $string['pluginadministration'] = 'Folder administration';
 $string['pluginname'] = 'Folder';
 $string['display'] = 'Display folder contents';
-$string['display_help'] = 'If you choose to display the folder contents on a course page, there '.
-    'will be no link to a separate page and the title will not be displayed. The '.
-    'description will be displayed only if "Display description on course page" '.
-    'is checked.<br />'.
-    'Also note that participants view actions can not be logged in this case.';
+$string['display_help'] = 'If you choose to display the folder contents on a course page, there  will be no link to a separate page and the title will not be displayed. 
+The description will be displayed only if "Display description on course page" is checked.<br />
+Also note that participants view actions can not be logged in this case.';
 $string['displaypage'] = 'On a separate page';
 $string['displayinline'] = 'Inline on a course page';
 $string['noautocompletioninline'] = 'Automatic completion on viewing of activity can not be selected together with "Display inline" option';
index c09ce2e..7e602cb 100644 (file)
@@ -433,14 +433,14 @@ function folder_get_coursemodule_info($cm) {
     $cminfo->name = $folder->name;
     if ($folder->display == FOLDER_DISPLAY_INLINE) {
         // prepare folder object to store in customdata
-        $fdata = new stdClass;
+        $fdata = new stdClass();
         if ($cm->showdescription && strlen(trim($folder->intro))) {
             $fdata->intro = $folder->intro;
             if ($folder->introformat != FORMAT_MOODLE) {
                 $fdata->introformat = $folder->introformat;
             }
         }
-        $cminfo->customdata = json_encode($fdata);
+        $cminfo->customdata = $fdata;
     } else {
         if ($cm->showdescription) {
             // Convert intro to html. Do not filter cached version, filters run at display time.
@@ -459,7 +459,8 @@ function folder_get_coursemodule_info($cm) {
  * @param cm_info $cm
  */
 function folder_cm_info_dynamic(cm_info $cm) {
-    if (strlen($cm->get_custom_data())) {
+    if ($cm->get_custom_data()) {
+        // the field 'customdata' is not empty IF AND ONLY IF we display contens inline
         $cm->set_no_view_link();
     }
 }
@@ -472,10 +473,12 @@ function folder_cm_info_dynamic(cm_info $cm) {
  */
 function folder_cm_info_view(cm_info $cm) {
     global $PAGE;
-    if ($cm->uservisible && strlen($cm->get_custom_data()) &&
+    if ($cm->uservisible && $cm->get_custom_data() &&
             has_capability('mod/folder:view', $cm->context)) {
-        // restore folder object from customdata
-        $folder = json_decode($cm->get_custom_data());
+        // Restore folder object from customdata.
+        // Note the field 'customdata' is not empty IF AND ONLY IF we display contens inline.
+        // Otherwise the content is default.
+        $folder = $cm->get_custom_data();
         $folder->id = (int)$cm->instance;
         $folder->course = (int)$cm->course;
         $folder->display = FOLDER_DISPLAY_INLINE;