Skip to content

Commit

Permalink
MDL-7742 added nested drop down box to add activities/resources to co…
Browse files Browse the repository at this point in the history
…urse, 3rd party mods can specify type

MDL-6987 preparation for migration of mod/assignment/mod.html
  • Loading branch information
skodak committed Jan 2, 2007
1 parent 17a67c9 commit 89bfeee
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 45 deletions.
75 changes: 41 additions & 34 deletions course/lib.php
Expand Up @@ -22,6 +22,9 @@
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") {
Expand Down Expand Up @@ -1135,9 +1138,6 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
asort($modnamesused);
}
}

unset($modnames['resource']);
unset($modnames['label']);
}


Expand Down Expand Up @@ -1342,55 +1342,62 @@ 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&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);
}

if ($vertical) {
$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>';
}
Expand Down
13 changes: 12 additions & 1 deletion lib/weblib.php
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions mod/assignment/lib.php
Expand Up @@ -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;
}

?>
11 changes: 11 additions & 0 deletions mod/label/lib.php
Expand Up @@ -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;
}
?>
25 changes: 15 additions & 10 deletions mod/resource/lib.php
Expand Up @@ -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
Expand All @@ -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() {
Expand Down

0 comments on commit 89bfeee

Please sign in to comment.