MDL-20204 more steps away from old popup_form
authorPetr Skoda <skodak@moodle.org>
Wed, 10 Feb 2010 11:25:17 +0000 (11:25 +0000)
committerPetr Skoda <skodak@moodle.org>
Wed, 10 Feb 2010 11:25:17 +0000 (11:25 +0000)
course/lib.php
mod/label/lib.php

index 6746132..1413db3 100644 (file)
@@ -1577,6 +1577,8 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
     static $resources = false;
     static $activities = false;
 
+    $urlbase = "/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey().'&add=';
+
     if ($resources === false) {
         $resources = array();
         $activities = array();
@@ -1593,27 +1595,46 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
             include_once($libfile);
             $gettypesfunc =  $modname.'_get_types';
             if (function_exists($gettypesfunc)) {
-                $types = $gettypesfunc();
-
-                foreach($types as $type) {
-                    $type->type = str_replace('&amp;', '&', $type->type);
-                    if (!isset($type->modclass) or !isset($type->typestr)) {
-                        debugging('Incorrect activity type in '.$modname);
-                        continue;
+                // NOTE: this is legacy stuff, module subtypes are very strongly discouraged!!
+                if ($types = $gettypesfunc()) {
+                    $menu = array();
+                    $atype = null;
+                    $groupname = null;
+                    foreach($types as $type) {
+                    if ($type->typestr === '--') {
+                            continue;
+                        }
+                        if (strpos($type->typestr, '--') === 0) {
+                            $groupname = str_replace('--', '', $type->typestr);
+                            continue;
+                        }
+                        $type->type = str_replace('&amp;', '&', $type->type);
+                        if ($type->modclass == MOD_CLASS_RESOURCE) {
+                            $atype = MOD_CLASS_RESOURCE;
+                        }
+                        $menu[$urlbase.$type->type] = $type->typestr;
                     }
-                    if ($type->modclass == MOD_CLASS_RESOURCE) {
-                        $resources[$type->type] = $type->typestr;
+                    if (!is_null($groupname)) {
+                        if ($atype == MOD_CLASS_RESOURCE) {
+                            $resources[] = array($groupname=>$menu);
+                        } else {
+                            $activities[] = array($groupname=>$menu);
+                        }
                     } else {
-                        $activities[$type->type] = $type->typestr;
+                        if ($atype == MOD_CLASS_RESOURCE) {
+                            $resources = array_merge($resources, $menu);
+                        } else {
+                            $activities = array_merge($activities, $menu);
+                        }
                     }
                 }
             } else {
                 $archetype = plugin_supports('mod', $modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER);
                 if ($archetype == MOD_ARCHETYPE_RESOURCE) {
-                    $resources[$modname] = $modnamestr;
+                    $resources[$urlbase.$modname] = $modnamestr;
                 } else {
                     // all other archetypes are considered activity
-                    $activities[$modname] = $modnamestr;
+                    $activities[$urlbase.$modname] = $modnamestr;
                 }
             }
         }
@@ -1628,20 +1649,16 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
         $output .= '<div class="horizontal">';
     }
 
-    $popupurl = "$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey();
-
     if (!empty($resources)) {
-        $select = html_select::make_popup_form($popupurl, 'add', $resources, "ressection$section", null);
-        $select->nothinglabel = $straddresource;
+        $select = new url_select($resources, '', array(''=>$straddresource), "ressection$section");
         $select->set_help_icon('resource/types', $straddresource);
-        $output .= $OUTPUT->select($select);
+        $output .= $OUTPUT->render($select);
     }
 
     if (!empty($activities)) {
-        $select = html_select::make_popup_form($popupurl, 'add', $activities, "section$section", null);
-        $select->nothinglabel = $straddactivity;
+        $select = new url_select($activities, '', array(''=>$straddactivity), "section$section");
         $select->set_help_icon('mods', $straddactivity);
-        $output .= $OUTPUT->select($select);
+        $output .= $OUTPUT->render($select);
     }
 
     if (!$vertical) {
index 5b529c6..a049b7c 100644 (file)
@@ -163,21 +163,6 @@ function label_get_post_actions() {
     return array();
 }
 
-/**
- * @return object
- */
-function label_get_types() {
-    $types = array();
-
-    $type = new object();
-    $type->modclass = MOD_CLASS_RESOURCE;
-    $type->type = "label";
-    $type->typestr = get_string('resourcetypelabel', 'resource');
-    $types[] = $type;
-
-    return $types;
-}
-
 /**
  * This function is used by the reset_course_userdata function in moodlelib.
  *
@@ -219,6 +204,7 @@ function label_supports($feature) {
         case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
         case FEATURE_GRADE_HAS_GRADE:         return false;
         case FEATURE_GRADE_OUTCOMES:          return false;
+        case FEATURE_MOD_ARCHETYPE:           return MOD_ARCHETYPE_RESOURCE;
 
         default: return null;
     }