From 89bfeee0d659b43c404864da94282bdff6fa690a Mon Sep 17 00:00:00 2001 From: skodak Date: Tue, 2 Jan 2007 09:33:07 +0000 Subject: [PATCH] MDL-7742 added nested drop down box to add activities/resources to course, 3rd party mods can specify type MDL-6987 preparation for migration of mod/assignment/mod.html --- course/lib.php | 75 +++++++++++++++++++++++------------------- lib/weblib.php | 13 +++++++- mod/assignment/lib.php | 42 +++++++++++++++++++++++ mod/label/lib.php | 11 +++++++ mod/resource/lib.php | 25 ++++++++------ 5 files changed, 121 insertions(+), 45 deletions(-) diff --git a/course/lib.php b/course/lib.php index 0692b776df..29f8055f97 100644 --- a/course/lib.php +++ b/course/lib.php @@ -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&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 = '
'; - if (course_allowed_module($course,'resource')) { - $resourceallowed = true; - $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=$USER->sesskey&add=", + + if (!empty($resources)) { + $output .= popup_form("$CFG->wwwroot/course/mod.php?id=$course->id&section=$section&sesskey=".sesskey()."&add=", $resources, "ressection$section", "", $straddresource, 'resource/types', $straddresource, true); } @@ -1376,21 +1392,12 @@ function print_section_add_menus($course, $section, $modnames, $vertical=false, $output .= '
'; } - // 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&section=$section&sesskey=".sesskey()."&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&section=$section&sesskey=$USER->sesskey&add=", - $modnames, "section$section", "", $straddactivity, 'mods', $straddactivity, true); - if ($vertical) { $output .= '
'; } diff --git a/lib/weblib.php b/lib/weblib.php index c8c9bca189..772f20b1f8 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -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 .= ' '; + } + $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 diff --git a/mod/assignment/lib.php b/mod/assignment/lib.php index 1648a21898..c6366bc511 100644 --- a/mod/assignment/lib.php +++ b/mod/assignment/lib.php @@ -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&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&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; +} + ?> diff --git a/mod/label/lib.php b/mod/label/lib.php index b34a5d1bed..b55a66055e 100644 --- a/mod/label/lib.php +++ b/mod/label/lib.php @@ -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; +} ?> diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 0c1e4f9b05..604c1abb34 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -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&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&type=$resourcetype"; + $type->typestr = get_string("resourcetype$resourcetype", 'resource'); + $types[] = $type; } } - return $resources; + + return $types; } function resource_get_view_actions() { -- 2.39.5