mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 16:32:18 +02:00
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
This commit is contained in:
parent
17a67c9690
commit
89bfeee0d6
@ -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 = '<div style="text-align: right">';
|
||||
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 .= '<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&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 .= '</div>';
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -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;
|
||||
}
|
||||
?>
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user