]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-7742 added nested drop down box to add activities/resources to course, 3rd party...
authorskodak <skodak>
Tue, 2 Jan 2007 09:33:07 +0000 (09:33 +0000)
committerskodak <skodak>
Tue, 2 Jan 2007 09:33:07 +0000 (09:33 +0000)
MDL-6987 preparation for migration of mod/assignment/mod.html

course/lib.php
lib/weblib.php
mod/assignment/lib.php
mod/label/lib.php
mod/resource/lib.php

index 0692b776dfdbe614fb05c5a49f915269f9d88d6a..29f8055f97d9e731cfbd261f0d10a80eab8f503f 100644 (file)
@@ -22,6 +22,9 @@ define('FRONTPAGECOURSELIMIT',    200);         // maximum number of courses dis
 define('EXCELROWS', 65535);
 define('FIRSTUSEDEXCELROW', 3);
 
+define('MOD_CLASS_ACTIVITY', 0);
+define('MOD_CLASS_RESOURCE', 1);
+
 
 function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, $selecteddate="lastlogin",
                                     $mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") {
@@ -1135,9 +1138,6 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
             asort($modnamesused);
         }
     }
-
-    unset($modnames['resource']);
-    unset($modnames['label']);
 }
 
 
@@ -1342,33 +1342,49 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
     }
 }
 
-
+/**
+ * Prints the menus to add activities and resources.
+ */
 function print_section_add_menus($course, $section, $modnames, $vertical=false, $return=false) {
-// Prints the menus to add activities and resources
+    global $CFG;
 
-    global $CFG, $USER;
-    static $straddactivity, $stractivities, $straddresource, $resources;
+    static $resources = false;
+    static $activities = false;
 
-    if (!isset($straddactivity)) {
-        $straddactivity = get_string('addactivity');
-        $straddresource = get_string('addresource');
+    if ($resources === false) { 
+        $resources = array();
+        $activities = array();
 
-        /// Standard resource types
-        require_once("$CFG->dirroot/mod/resource/lib.php");
-        $resourceraw = resource_get_resource_types();
+        foreach($modnames as $modname=>$modnamestr) {
+            if (!course_allowed_module($course, $modname)) {
+                continue;
+            }
 
-        foreach ($resourceraw as $type => $name) {
-            $resources["resource&amp;type=$type"] = $name;
-        }
-        if (course_allowed_module($course,'label')) {
-            $resources['label'] = get_string('resourcetypelabel', 'resource');
+            require_once("$CFG->dirroot/mod/$modname/lib.php");
+            $gettypesfunc =  $modname.'_get_types';
+            if (function_exists($gettypesfunc)) {
+                $types = $gettypesfunc();
+                foreach($types as $type) {
+                    if ($type->modclass == MOD_CLASS_RESOURCE) {
+                        $resources[$type->type] = $type->typestr;
+                    } else {
+                        $activities[$type->type] = $type->typestr;
+                    }
+                }
+            } else {
+                // all mods without type are considered activity
+                $activities[$modname] = $modnamestr;
+            }
         }
     }
 
+    $straddactivity = get_string('addactivity');
+    $straddresource = get_string('addresource');
+
     $output  = '<div style="text-align: right">';
-    if (course_allowed_module($course,'resource')) {
-        $resourceallowed = true;
-        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=$USER->sesskey&amp;add=",
+
+    if (!empty($resources)) {
+        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=".sesskey()."&amp;add=",
                               $resources, "ressection$section", "", $straddresource, 'resource/types', $straddresource, true);
     }
 
@@ -1376,21 +1392,12 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false,
         $output .= '<div>';
     }
 
-    // we need to loop through the forms and check to see if we can add them.
-    foreach ($modnames as $key=>$value) {
-        if (!course_allowed_module($course,$key))
-            unset($modnames[$key]);
+    if (!empty($activities)) {
+        $output .= ' ';
+        $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=".sesskey()."&amp;add=",
+                    $activities, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
     }
 
-    // this is stupid but labels get put into resource, so if resource is hidden and label is not, we're in trouble.
-    if (course_allowed_module($course,'label') && empty($resourceallowed)) {
-        $modnames['label'] = get_string('modulename', 'label');
-    }
-
-    $output .= ' ';
-    $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&amp;section=$section&amp;sesskey=$USER->sesskey&amp;add=",
-                $modnames, "section$section", "", $straddactivity, 'mods', $straddactivity, true);
-
     if ($vertical) {
         $output .= '</div>';
     }
index c8c9bca1895a7eb682256328c489754404f1f4d8..772f20b1f8d7c34c77a1c5363f78b5bb84737d87 100644 (file)
@@ -966,9 +966,20 @@ function popup_form($common, $options, $formname, $selected='', $nothing='choose
     }
 
     $inoptgroup = false;
+
     foreach ($options as $value => $label) {
 
-        if (substr($label,0,2) == '--') { /// we are starting a new optgroup
+        if ($label == '--') { /// we are ending previous optgroup
+            /// Check to see if we already have a valid open optgroup
+            /// XHTML demands that there be at least 1 option within an optgroup
+            if ($inoptgroup and (count($optgr) > 1) ) {
+                $output .= implode('', $optgr);
+                $output .= '   </optgroup>';
+            }
+            $optgr = array();
+            $inoptgroup = false;
+            continue;
+        } else if (substr($label,0,2) == '--') { /// we are starting a new optgroup
 
             /// Check to see if we already have a valid open optgroup
             /// XHTML demands that there be at least 1 option within an optgroup
index 1648a218985557f574c1e88d22945d6588875ec2..c6366bc511973228d192652c46c78a90dc02e3f1 100644 (file)
@@ -2476,4 +2476,46 @@ function assignment_get_post_actions() {
     return array('upload');
 }
 
+function assignment_get_types() {
+    $types = array();
+
+    $type = new object();
+    $type->modclass = MOD_CLASS_ACTIVITY;
+    $type->type = "assignment_group_start";
+    $type->typestr = '--'.get_string('modulenameplural', 'assignment');
+    $types[] = $type;
+
+    $standardassignments = array('upload','online','uploadsingle','offline');
+    foreach ($standardassignments as $assignmenttype) {
+        $type = new object();
+        $type->modclass = MOD_CLASS_ACTIVITY;
+        $type->type = "assignment&amp;type=$assignmenttype";
+        $type->typestr = get_string("type$assignmenttype", 'assignment');
+        $types[] = $type;
+    }
+
+    /// Drop-in extra assignment types
+    $assignmenttypes = get_list_of_plugins('mod/assignment/type');
+    foreach ($assignmenttypes as $assignmenttype) {
+        if (!empty($CFG->{'assignment_hide_'.$assignmenttype})) {  // Not wanted
+            continue;
+        }
+        if (!in_array($assignmenttype, $standardassignments)) {
+            $type = new object();
+            $type->modclass = MOD_CLASS_ACTIVITY;
+            $type->type = "assignment&amp;type=$assignmenttype";
+            $type->typestr = get_string("type$assignmenttype", 'assignment');
+            $types[] = $type;
+        }
+    }
+
+    $type = new object();
+    $type->modclass = MOD_CLASS_ACTIVITY;
+    $type->type = "assignment_group_end";
+    $type->typestr = '--';
+    $types[] = $type;
+
+    return $types;
+}
+
 ?>
index b34a5d1bed96a841c2d921306594b3e1ffb2bd5b..b55a66055e051075a0defc08150d4263ba94d4a0 100644 (file)
@@ -88,4 +88,15 @@ function label_get_post_actions() {
     return array();
 }
 
+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;
+}
 ?>
index 0c1e4f9b055f9329214d43fc3b893c6fcf30b14f..604c1abb34826ba23640c59ce7f5a9f3eeb4e022 100644 (file)
@@ -629,16 +629,16 @@ function resource_is_url($path) {
     return false;
 }
 
-function resource_get_resource_types() {
-/// Returns a menu of current resource types, in standard order
-    global $resource_standard_order, $CFG;
+function resource_get_types() {
+    $types = array();
 
-    $resources = array();
-
-    /// Standard resource types
     $standardresources = array('text','html','file','directory');
     foreach ($standardresources as $resourcetype) {
-        $resources[$resourcetype] = get_string("resourcetype$resourcetype", 'resource');
+        $type = new object();
+        $type->modclass = MOD_CLASS_RESOURCE;
+        $type->type = "resource&amp;type=$resourcetype";
+        $type->typestr = get_string("resourcetype$resourcetype", 'resource');
+        $types[] = $type;
     }
 
     /// Drop-in extra resource types
@@ -647,11 +647,16 @@ function resource_get_resource_types() {
         if (!empty($CFG->{'resource_hide_'.$resourcetype})) {  // Not wanted
             continue;
         }
-        if (!in_array($resourcetype, $resources)) {
-            $resources[$resourcetype] = get_string("resourcetype$resourcetype", 'resource');
+        if (!in_array($resourcetype, $standardresources)) {
+            $type = new object();
+            $type->modclass = MOD_CLASS_RESOURCE;
+            $type->type = "resource&amp;type=$resourcetype";
+            $type->typestr = get_string("resourcetype$resourcetype", 'resource');
+            $types[] = $type;
         }
     }
-    return $resources;
+
+    return $types;
 }
 
 function resource_get_view_actions() {