From: skodak Date: Thu, 16 Aug 2007 21:14:03 +0000 (+0000) Subject: MDL-10383 - some more refactoring/cleanup, enablegroupings experimental admin setting... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=778918fd71fd498ebee061cde8831b18117c5d2c;p=moodle.git MDL-10383 - some more refactoring/cleanup, enablegroupings experimental admin setting, tabs in groups UI --- diff --git a/admin/settings/misc.php b/admin/settings/misc.php index 7065f0bad7..9e030be024 100644 --- a/admin/settings/misc.php +++ b/admin/settings/misc.php @@ -7,6 +7,8 @@ $temp = new admin_settingpage('experimental', get_string('experimental', 'admin' $temp->add(new admin_setting_configcheckbox('enableglobalsearch', get_string('enableglobalsearch', 'admin'), get_string('configenableglobalsearch', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('smartpix', get_string('smartpix', 'admin'), get_string('configsmartpix', 'admin'), 0)); $temp->add(new admin_setting_configcheckbox('enablehtmlpurifier', get_string('enablehtmlpurifier', 'admin'), get_string('configenablehtmlpurifier', 'admin'), 0)); +$temp->add(new admin_setting_configcheckbox('enablegroupings', get_string('enablegroupings', 'admin'), get_string('configenablegroupings', 'admin'), 0)); + $ADMIN->add('misc', $temp); // XMLDB editor diff --git a/admin/uploaduser.php b/admin/uploaduser.php index 8a2c91af3e..4f357a84d2 100755 --- a/admin/uploaduser.php +++ b/admin/uploaduser.php @@ -5,6 +5,7 @@ require_once('../config.php'); require_once($CFG->libdir.'/adminlib.php'); +require_once($CFG->dirroot.'/group/lib.php'); require_once('uploaduser_form.php'); admin_externalpage_setup('uploadusers'); diff --git a/enrol/imsenterprise/enrol.php b/enrol/imsenterprise/enrol.php index 96c7fac5a4..8c70e5cbe3 100644 --- a/enrol/imsenterprise/enrol.php +++ b/enrol/imsenterprise/enrol.php @@ -5,6 +5,7 @@ * @package enrol_imsenterprise */ require_once("$CFG->libdir/blocklib.php"); +require_once($CFG->dirroot.'/group/lib.php'); // The following flags are set in the configuration // $CFG->enrol_imsfilelocation: where is the file we are looking for? diff --git a/enrol/manual/enrol.php b/enrol/manual/enrol.php index 347e7e610e..bc6a2a7168 100644 --- a/enrol/manual/enrol.php +++ b/enrol/manual/enrol.php @@ -22,6 +22,7 @@ // // /////////////////////////////////////////////////////////////////////////// +require_once($CFG->dirroot.'/group/lib.php'); /** * enrolment_plugin_manual is the default enrolment plugin diff --git a/group/group.php b/group/group.php index 4a8a93a2fd..b39757879e 100644 --- a/group/group.php +++ b/group/group.php @@ -85,9 +85,10 @@ if ($editform->is_cancelled()) { error('Error updating group'); } } else { - if (!groups_create_group($data, $editform->_upload_manager)) { + if (!$id = groups_create_group($data, $editform->_upload_manager)) { error('Error updating group'); } + $returnurl = $CFG->wwwroot.'/group/index.php?id='.$course->id.'&group='.$id; } redirect($returnurl); @@ -101,14 +102,15 @@ if ($id) { } else { $strheading = get_string('creategroup', 'group'); } -print_header("$course->shortname: ". $strheading, - $course->fullname, - "wwwroot/course/view.php?id=$courseid\">$course->shortname ". - "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". - "-> wwwroot/group/index.php?id=$courseid\">$strgroups". - "-> $strheading", '', '', true, '', user_login_string($course, $USER)); - -print_heading($strheading); + + +$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'), + array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'), + array('name'=>$strheading, 'link'=>'', 'type'=>'misc')); +$navigation = build_navigation($navlinks); + +/// Print header +print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course)); echo '
'; if ($id) { diff --git a/group/grouping.php b/group/grouping.php index eb55a24455..dc5ad1b482 100644 --- a/group/grouping.php +++ b/group/grouping.php @@ -99,7 +99,6 @@ if ($editform->is_cancelled()) { } -$strgroups = get_string('groups'); $strgroupings = get_string('groupings', 'group'); $strparticipants = get_string('participants'); @@ -109,12 +108,15 @@ if ($id) { $strheading = get_string('creategrouping', 'group'); } -print_header("$course->shortname: ". $strheading, - $course->fullname, - "wwwroot/course/view.php?id=$courseid\">$course->shortname ". - "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". - "-> $strgroupings". - "-> $strheading", '', '', true, '', user_login_string($course, $USER)); +$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'), + array('name'=>$strgroupings, 'link'=>$CFG->wwwroot.'/group/groupings.php?id='.$courseid, 'type'=>'misc'), + array('name'=>$strheading, 'link'=>'', 'type'=>'misc')); +$navigation = build_navigation($navlinks); + +/// Print header +print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course)); + + print_heading($strheading); $editform->display(); print_footer($course); diff --git a/group/groupings.php b/group/groupings.php index 7844e7c923..0abbc8ef52 100644 --- a/group/groupings.php +++ b/group/groupings.php @@ -24,16 +24,19 @@ $strgroups = get_string('groups'); $strgroupings = get_string('groupings', 'group'); $struses = get_string('activities'); $strparticipants = get_string('participants'); -$strmanagegrping = get_String('addgroupstogrouping', 'group'); +$strmanagegrping = get_String('showgroupsingrouping', 'group'); $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'), - array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'), array('name'=>$strgroupings, 'link'=>'', 'type'=>'misc')); $navigation = build_navigation($navlinks); /// Print header print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course)); +// Add tabs +$currenttab = 'groupings'; +require('tabs.php'); + print_heading($strgroupings); $data = array(); @@ -58,7 +61,7 @@ if ($groupings = get_records('groupings', 'courseid', $course->id)) { $buttons .= "id&delete=1\">pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /> "; $buttons .= "id\">pixpath/i/group.gif\" class=\"iconsmall\" alt=\"$strmanagegrping\" /> "; + " src=\"$CFG->pixpath/i/group.gif\" class=\"icon\" alt=\"$strmanagegrping\" /> "; $line[3] = $buttons; $data[] = $line; diff --git a/group/index.php b/group/index.php index a12281f1e5..bee224799f 100644 --- a/group/index.php +++ b/group/index.php @@ -33,188 +33,195 @@ if (!$course = get_record('course', 'id',$courseid)) { print_error('invalidcourse'); //'The course ID is invalid' } - // Make sure that the user has permissions to manage groups. - require_login($course); +// Make sure that the user has permissions to manage groups. +require_login($course); - $context = get_context_instance(CONTEXT_COURSE, $courseid); - if (! has_capability('moodle/course:managegroups', $context)) { - redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups - } +$context = get_context_instance(CONTEXT_COURSE, $courseid); +if (! has_capability('moodle/course:managegroups', $context)) { + redirect(); //"group.php?id=$course->id"); // Not allowed to see all groups +} - switch ($action) { - case false: //OK, display form. - break; - - case 'ajax_getmembersingroup': - $members = array(); - if ($members = groups_get_members($groupid)) { - $member_names = array(); - foreach($members as $member) { - $user = new object(); - $user->id = $member->id; - $user->name = fullname($member, true); - $member_names[] = $user; - } - $json = new Services_JSON(); - echo $json->encode($member_names); +switch ($action) { + case false: //OK, display form. + break; + + case 'ajax_getmembersingroup': + $members = array(); + if ($members = groups_get_members($groupid)) { + $member_names = array(); + foreach($members as $member) { + $user = new object(); + $user->id = $member->id; + $user->name = fullname($member, true); + $member_names[] = $user; } - die; // Client side JavaScript takes it from here. + $json = new Services_JSON(); + echo $json->encode($member_names); + } + die; // Client side JavaScript takes it from here. - case 'deletegroup': - redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid); - break; + case 'deletegroup': + redirect('group.php?delete=1&courseid='.$courseid.'&id='.$groupid); + break; - case 'showcreateorphangroupform': - redirect('group.php?courseid='.$courseid); - break; + case 'showcreateorphangroupform': + redirect('group.php?courseid='.$courseid); + break; - case 'showgroupsettingsform': - redirect('group.php?courseid='.$courseid.'&id='.$groupid); - break; + case 'showgroupsettingsform': + redirect('group.php?courseid='.$courseid.'&id='.$groupid); + break; - case 'updategroups': //Currently reloading. - break; + case 'updategroups': //Currently reloading. + break; - case 'removemembers': - break; + case 'removemembers': + break; - case 'showaddmembersform': - redirect('members.php?group='.$groupid); - break; + case 'showaddmembersform': + redirect('members.php?group='.$groupid); + break; - case 'updatemembers': //Currently reloading. - break; + case 'updatemembers': //Currently reloading. + break; - default: //ERROR. - if (debugging()) { - error('Error, unknown button/action. Probably a user-interface bug!', $returnurl); - break; - } + default: //ERROR. + if (debugging()) { + error('Error, unknown button/action. Probably a user-interface bug!', $returnurl); + break; } +} - // Print the page and form - $strgroups = get_string('groups'); - $strparticipants = get_string('participants'); - - print_header("$course->shortname: $strgroups", - $course->fullname, - "wwwroot/course/view.php?id=$courseid\">$course->shortname ". - "-> wwwroot/user/index.php?id=$courseid\">$strparticipants ". - "-> $strgroups", '', '', true, '', user_login_string($course, $USER)); +// Print the page and form +$strgroups = get_string('groups'); +$strparticipants = get_string('participants'); - $disabled = 'disabled="disabled"'; +$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'), + array('name'=>$strgroups, 'link'=>'', 'type'=>'misc')); +$navigation = build_navigation($navlinks); - $showeditgroupsettingsform_disabled = $disabled; - $deletegroup_disabled = $disabled; - $showcreategroupform_disabled = $disabled; - - if (!empty($groupid)) { - $showaddmembersform_disabled = ''; - $showeditgroupsettingsform_disabled = ''; - $deletegroup_disabled = ''; - } else { - $deletegroup_disabled = $disabled; - $showeditgroupsettingsform_disabled = $disabled; - $showaddmembersform_disabled = $disabled; - } - - print_heading(format_string($course->shortname) .' '.$strgroups, 'center', 3); - echo '
'."\n"; - echo '
'."\n"; - echo ''."\n"; - - echo ''."\n"; - echo ''."\n"; +/// Print header +print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course)); +if (!empty($CFG->enablegroupings)) { + // Add tabs + $currenttab = 'groups'; + require('tabs.php'); +} - echo "'."\n"; +echo ''."\n"; +echo '
\n"; - // NO GROUPINGS YET! - echo '

'."\n"; +$disabled = 'disabled="disabled"'; - echo ''."\n"; - if ($groups) { - // Print out the HTML - foreach ($groups as $group) { - $select = ''; - if ($groupid == $group->id) { - $select = ' selected="selected"'; - $sel_groupid = $group->id; - } - $usercount = (int)count_records('groups_members', 'groupid', $group->id); - $groupname = format_string($group->name).' ('.$usercount.')'; +echo ''."\n"; +echo ''."\n"; - echo "\n"; - } - } else { - // Print an empty option to avoid the XHTML error of having an empty select element - echo ''; - } - echo ''."\n"; - echo '

'."\n"; - echo '

'."\n"; - echo '

'."\n"; +echo "'."\n"; - echo ''."\n"; +echo ''."\n"; - echo ''."\n"; - echo '
\n"; +// NO GROUPINGS YET! +echo '

'."\n"; - echo '

'."\n"; +echo '
'."\n"; - echo '

'."\n"; - //NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick. - echo ''."\n"; +echo '

'."\n"; +echo '

'."\n"; +echo '

'."\n"; + +echo '

'."\n"; + +echo '
'."\n"; +echo '

'."\n"; +//NOTE: the SELECT was, multiple="multiple" name="user[]" - not used and breaks onclick. +echo ''."\n"; +} else { + // Print an empty option to avoid the XHTML error of having an empty select element + echo ''; +} + +echo ''."\n"; - echo '

'."\n"; - echo '
'."\n"; +echo '

'."\n"; +echo '
'."\n"; - // - echo '
'."\n"; - echo '
'."\n"; +// +echo '
'."\n"; +echo ''."\n"; - echo ''."\n"; +echo ''."\n"; - print_footer($course); +print_footer($course); /** * Returns the first button action with the given prefix, taken from diff --git a/group/lib.php b/group/lib.php index eb0234472d..c0d571aa8e 100644 --- a/group/lib.php +++ b/group/lib.php @@ -13,6 +13,67 @@ * require_once $CFG->dirroot.'/group/lib.php' must be used */ +/** + * Adds a specified user to a group + * @param int $userid The user id + * @param int $groupid The group id + * @return boolean True if user added successfully or the user is already a + * member of the group, false otherwise. + */ +function groups_add_member($groupid, $userid) { + if (!groups_group_exists($groupid)) { + return false; + } + + if (groups_is_member($groupid, $userid)) { + return true; + } + + $member = new object(); + $member->groupid = $groupid; + $member->userid = $userid; + $member->timeadded = time(); + + if (!insert_record('groups_members', $member)) { + return false; + } + + //update group info + set_field('groups', 'timemodified', $member->timeadded, 'id', $groupid); + + // MDL-9983 + $eventdata = new object(); + $eventdata->groupid = $groupid; + $eventdata->userid = $userid; + events_trigger('group_user_added', $eventdata); + + return true; +} + +/** + * Deletes the link between the specified user and group. + * @param int $groupid The group to delete the user from + * @param int $userid The user to delete + * @return boolean True if deletion was successful, false otherwise + */ +function groups_remove_member($groupid, $userid) { + if (!groups_group_exists($groupid)) { + return false; + } + + if (!groups_is_member($groupid, $userid)) { + return true; + } + + if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid)) { + return false; + } + //update group info + set_field('groups', 'timemodified', time(), 'id', $groupid); + + return true; +} + /** * Add a new group * @param object $data group properties (with magic quotes); diff --git a/group/tabs.php b/group/tabs.php new file mode 100644 index 0000000000..59531849c0 --- /dev/null +++ b/group/tabs.php @@ -0,0 +1,15 @@ +wwwroot.'/group/index.php?id='.$courseid, + get_string('groups')); + + $row[] = new tabobject('groupings', + $CFG->wwwroot.'/group/groupings.php?id='.$courseid, + get_string('groupings', 'group')); + + $tabs[] = $row; + echo '
'; + print_tabs($tabs, $currenttab); + echo '
'; +?> diff --git a/lang/en_utf8/admin.php b/lang/en_utf8/admin.php index db85bb2338..47b71cc41b 100644 --- a/lang/en_utf8/admin.php +++ b/lang/en_utf8/admin.php @@ -87,6 +87,7 @@ $string['configeditordictionary'] = 'This value will be used if aspell doesn\'t $string['configenableajax'] = 'This setting allows you to control the use of AJAX (advanced client/server interfaces using Javascript) across the whole site. With this setting enabled users can still make a choice in their profile, otherwise AJAX is disabled for everybody.'; $string['configenablecourserequests'] = 'This will allow any user to request a course be created.'; $string['configenableglobalsearch'] = 'This setting enables global text searching in resources and activities, it is not compatible with PHP 4.'; +$string['configenablegroupings'] = 'This setting enables groupings of groups. (Not yet fully implemented)'; $string['configenablehtmlpurifier'] = 'Use HTML Purifier instead of KSES for cleaning of untrusted text. HTML Purifier is actively developed and is believed to be more secure, but it is more resource intensive. Expect minor visual differences in the resulting html code. Please note that embed and object tags can not be enabled, MathML tags and old lang tags are not supported. '; $string['configenablerssfeeds'] = 'This switch will enable RSS feeds from across the site. To actually see any change you will need to enable RSS feeds in the individual modules too - go to the Modules settings under Admin Configuration.'; $string['configenablerssfeedsdisabled'] = 'It is not available because RSS feeds are disabled in all the Site. To enable them, go to the Variables settings under Admin Configuration.'; @@ -277,6 +278,7 @@ $string['editstrings'] = 'Edit words or phrases'; $string['enableajax'] = 'Enable AJAX'; $string['enablecourserequests'] = 'Enable course requests'; $string['enableglobalsearch'] = 'Enable global search'; +$string['enablegroupings'] = 'Enable groupings'; $string['enablehtmlpurifier'] = 'Enable HTML Purifier'; $string['enablerecordcache'] = 'Enable Record Cache'; $string['enablerssfeeds'] = 'Enable RSS feeds'; diff --git a/lang/en_utf8/group.php b/lang/en_utf8/group.php index 6396f4eae5..1d41b387b8 100644 --- a/lang/en_utf8/group.php +++ b/lang/en_utf8/group.php @@ -1,6 +1,6 @@ dirroot.'/group/lib.php'); + return groups_add_member($groupid, $userid); } diff --git a/lib/grouplib.php b/lib/grouplib.php index dc6fdc6f9e..8c7de05963 100644 --- a/lib/grouplib.php +++ b/lib/grouplib.php @@ -1,68 +1,6 @@ groupid = $groupid; - $member->userid = $userid; - $member->timeadded = time(); - - if (!insert_record('groups_members', $member)) { - return false; - } - - //update group info - set_field('groups', 'timemodified', $member->timeadded, 'id', $groupid); - - // MDL-9983 - $eventdata = new object(); - $eventdata -> groupid = $groupid; - $eventdata -> userid = $userid; - events_trigger('group_user_added', $eventdata); - - return true; -} - -/** - * Deletes the link between the specified user and group. - * @param int $groupid The group to delete the user from - * @param int $userid The user to delete - * @return boolean True if deletion was successful, false otherwise - */ -function groups_remove_member($groupid, $userid) { - if (!groups_group_exists($groupid)) { - return false; - } - - if (!groups_is_member($groupid, $userid)) { - return true; - } - - if (!delete_records('groups_members', 'groupid', $groupid, 'userid', $userid)) { - return false; - } - //update group info - set_field('groups', 'timemodified', time(), 'id', $groupid); - - return true; -} - - /** * Determines if a group with a given groupid exists. * @param int $groupid The groupid to check for