From: nfreear Date: Wed, 17 Jan 2007 13:56:09 +0000 (+0000) Subject: Partial fix for MDL-8048, groups cleanup including hiding unimplemented buttons in... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=b1f627d9eba22fa2e7418a22953ded4aeef2c4b9;p=moodle.git Partial fix for MDL-8048, groups cleanup including hiding unimplemented buttons in GUI, fixing error strings. --- diff --git a/group/db/dbbasicgrouplib.php b/group/db/dbbasicgrouplib.php index f60566c0ca..34c00067fe 100644 --- a/group/db/dbbasicgrouplib.php +++ b/group/db/dbbasicgrouplib.php @@ -43,20 +43,13 @@ function groups_db_get_user($userid) { * or an error returned */ function groups_db_get_groups($courseid) { - if (!$courseid) { + if (! $courseid) { $groupid = false; } else { $groups = get_records('groups_courses_groups', 'courseid', $courseid, '', $fields='id, groupid'); // Put the results into an array - $groupids = array(); - if (!$groups) { - $groupids = false; - } else { - foreach ($groups as $group) { - array_push($groupids, $group->groupid); - } - } + $groupids = groups_groups_to_groupids($groups, $courseid); } return $groupids; @@ -101,26 +94,16 @@ function groups_db_get_groups_for_user($userid, $courseid) { $groupids = false; } else { global $CFG; - $table_prefix = $CFG->prefix; $sql = "SELECT g.id, userid - FROM {$table_prefix}groups_members AS gm - INNER JOIN {$table_prefix}groups AS g + FROM {$CFG->prefix}groups_members AS gm + INNER JOIN {$CFG->prefix}groups AS g ON gm.groupid = g.id - INNER JOIN {$table_prefix}groups_courses_groups AS cg + INNER JOIN {$CFG->prefix}groups_courses_groups AS cg ON g.id = cg.groupid WHERE cg.courseid = $courseid AND gm.userid=$userid"; $groups = get_records_sql($sql); - - if (!$groups) { - $groupids = false; - } else { - // Put the results into an array - $groupids = array(); - foreach ($groups as $group) { - array_push($groupids, $group->id); - } - } + $groupids = groups_groups_to_groupids($groups, $courseid); } return $groupids; @@ -140,9 +123,8 @@ function groups_db_get_group_settings($groupid, $courseid=false) { $groupsettings = false; } else { global $CFG; - $tableprefix = $CFG->prefix; $sql = "SELECT id, name, description, lang, theme, picture, hidepicture - FROM {$tableprefix}groups + FROM {$CFG->prefix}groups WHERE id = $groupid"; $groupsettings = get_record_sql($sql); if ($courseid && $groupsettings) { @@ -162,9 +144,10 @@ function groups_db_get_group_settings($groupid, $courseid=false) { * if an error occurred. */ function groups_db_users_in_common_group($userid1, $userid2) { - $havecommongroup = false; - $sql = "SELECT gm1.groupid, 1 FROM {$tableprefix}groups_members AS gm1 " . - "INNER JOIN {$tableprefix}groups_members AS gm2 " . + global $CFG; + $havecommongroup = false; + $sql = "SELECT gm1.groupid, 1 FROM {$CFG->prefix}groups_members AS gm1 " . + "INNER JOIN {$CFG->prefix}groups_members AS gm2 " . "ON gm1.groupid =gm2.groupid" . "WHERE gm1.userid = $userid1 AND gm2.userid = $userid2"; $commongroups = get_record_sql($sql); diff --git a/group/db/dbgroupinglib.php b/group/db/dbgroupinglib.php index 8cffcde6b3..98795d5bf7 100644 --- a/group/db/dbgroupinglib.php +++ b/group/db/dbgroupinglib.php @@ -109,9 +109,8 @@ function groups_db_get_grouping_settings($groupingid) { $groupingsettings = false; } else { global $CFG; - $tableprefix = $CFG->prefix; $sql = "SELECT * - FROM {$tableprefix}groups_groupings + FROM {$CFG->prefix}groups_groupings WHERE id = $groupingid"; $groupingsettings = get_record_sql($sql); } @@ -214,10 +213,9 @@ function groups_db_grouping_exists($groupingid) { $belongstogroup = false; } else { global $CFG; - $tableprefix = $CFG->prefix; $sql = "SELECT gm.id - FROM {$tableprefix}groups_groupings_groups AS gg - INNER JOIN {$tableprefix}groups_members AS gm + FROM {$CFG->prefix}groups_groupings_groups AS gg + INNER JOIN {$CFG->prefix}groups_members AS gm ON gg.groupid = gm.groupid WHERE gm.userid = $userid AND gg.groupingid = $groupingid"; $belongstogroup = record_exists_sql($sql); diff --git a/group/group.php b/group/group.php index 7c51a0063e..430228cff8 100644 --- a/group/group.php +++ b/group/group.php @@ -32,7 +32,7 @@ $delete = optional_param('delete', false, PARAM_BOOL); $course = groups_get_course_info($courseid); if (! $course) { $success = false; - print_error('The course ID is invalid'); + print_error('invalidcourse'); //'The course ID is invalid' } if ($success) { @@ -83,7 +83,7 @@ if ($success) { redirect(groups_home_url($courseid, $groupid, $groupingid, false)); } else { - print_error('Error creating/updating group.'); + print_error('erroreditgrouping', 'group', groups_home_url($courseid)); } } } diff --git a/group/grouping.php b/group/grouping.php index dbdfd7ac91..ede13cdb18 100644 --- a/group/grouping.php +++ b/group/grouping.php @@ -25,7 +25,10 @@ $groupingsettings->description= optional_param('description', PARAM_ALPHANUM); $course = groups_get_course_info($courseid); if (! $course) { $success = false; - print_error('The course ID is invalid'); + print_error('invalidcourse'); //'The course ID is invalid' +} +if (GROUP_NOT_IN_GROUPING == $groupingid) { + print_error('errornotingroupingedit', 'group', groups_home_url($courseid), get_string('notingrouping', 'group')); } if ($success) { @@ -59,7 +62,7 @@ if ($success) { redirect(groups_home_url($courseid, null, $groupingid, false)); } else { - print_error('Error creating/updating grouping.'); + print_error('erroreditgroup', 'group', groups_home_url($courseid)); } } } @@ -115,6 +118,20 @@ if ($success) {

+ + +
    +
  1. +
  2. +
  3. +
  4. +
  5. +
  6. +
+ +*/ ?> +

diff --git a/group/index.php b/group/index.php index 986b61aa2b..8244cf194d 100644 --- a/group/index.php +++ b/group/index.php @@ -19,32 +19,6 @@ $groupingid = optional_param('grouping', -1, PARAM_INT); $groupid = optional_param('group', false, PARAM_INT); $userid = optional_param('user', false, PARAM_INT); -function groups_param_action($prefix = 'b_') { - $action = false; -//($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/ - - if ($_POST) { - $form_vars = $_POST; - } - elseif ($_GET) { - $form_vars = $_GET; - } - if ($form_vars) { - foreach ($form_vars as $key => $value) { - //echo "$key => $value
\n"; - if (preg_match("/$prefix(.+)/", $key, $matches)) { - $action = $matches[1]; - break; - } - } - } - if ($action && !preg_match('/^\w+$/', $action)) { - $action = false; - error('Action had wrong type.'); - } - ///if (debugging()) echo 'Debug: '.$action; - return $action; -} $action = groups_param_action(); // Get the course information so we can print the header and @@ -52,7 +26,7 @@ $action = groups_param_action(); $course = groups_get_course_info($courseid); if (! $course) { $success = false; - print_error('The course ID is invalid'); + print_error('invalidcourse'); //'The course ID is invalid' } if ($success) { @@ -125,8 +99,8 @@ if ($success) { "-> $strgroups", '', '', true, '', user_login_string($course, $USER)); $usehtmleditor = false; - -//groups_sort_language_strings(); + //TODO: eventually we'll implement all buttons, meantime hide the ones we haven't finised. + $shownotdone = false; ?>

@@ -170,13 +144,17 @@ if ($success) { ?> -

-

-

-

-

-

-

+

+

+ +

+

+ +

+ +

+ +

@@ -210,13 +188,16 @@ if ($success) { ?> -

-

-

-

-

-

- +

+

+

+ +

+ +

+ +

+

@@ -239,9 +220,10 @@ if ($success) { ?> -

-

- + +

+ +

diff --git a/group/lib/basicgrouplib.php b/group/lib/basicgrouplib.php index 18bf935a31..e25fe289ae 100644 --- a/group/lib/basicgrouplib.php +++ b/group/lib/basicgrouplib.php @@ -73,7 +73,7 @@ function groups_get_all_groups_for_user($userid) { if (! $groups) { return false; } - // Put the results into an array + // Put the results into an array. TODO: check. $groupids = array(); foreach ($groups as $group) { array_push($groupids, $group->id); diff --git a/group/lib/groupinglib.php b/group/lib/groupinglib.php index 59eac11202..e089222ebb 100644 --- a/group/lib/groupinglib.php +++ b/group/lib/groupinglib.php @@ -1,4 +1,4 @@ -id); - } - } - return $userids; + if (! $users) { + return false; + } + $userids = array(); + foreach($users as $user) { + array_push($userids, $user->id); + } + return $userids; } /** - * Takes an array of groups (i.e of objects) and converts it in the - * corresponding array of groupids. - * @param $groups array The array of group - * @return array The array of group ids, or false if an error occurred + * Takes an array of groups (i.e of objects) and converts it to the + * corresponding array of group IDs. + * @param $groups array The array of group-like objects, only the $group->id member is required. + * @return array The array of group IDs, or false if an error occurred */ function groups_groups_to_groupids($groups) { - $groupids = array(); + if (! $groups) { + return false; + } + $groupids = array(); foreach ($groups as $group) { array_push($groupids, $group->id); } @@ -274,4 +276,37 @@ function groups_home_url($courseid, $groupid=false, $groupingid=false, $html=tru return $url; } +/** + * Returns the first button action with the given prefix, taken from + * POST or GET, otherwise returns false. + * See /lib/moodlelib.php function optional_param. + * @param $prefix 'act_' as in 'action'. + * @return string The action without the prefix, or false if no action found. + */ +function groups_param_action($prefix = 'act_') { + $action = false; +//($_SERVER['QUERY_STRING'] && preg_match("/$prefix(.+?)=(.+)/", $_SERVER['QUERY_STRING'], $matches)) { //b_(.*?)[&;]{0,1}/ + + if ($_POST) { + $form_vars = $_POST; + } + elseif ($_GET) { + $form_vars = $_GET; + } + if ($form_vars) { + foreach ($form_vars as $key => $value) { + if (preg_match("/$prefix(.+)/", $key, $matches)) { + $action = $matches[1]; + break; + } + } + } + if ($action && !preg_match('/^\w+$/', $action)) { + $action = false; + error('Action had wrong type.'); + } + ///if (debugging()) echo 'Debug: '.$action; + return $action; +} + ?> \ No newline at end of file diff --git a/lang/en_utf8/group.php b/lang/en_utf8/group.php index 563f64b6f8..e78310e023 100644 --- a/lang/en_utf8/group.php +++ b/lang/en_utf8/group.php @@ -13,6 +13,11 @@ $string['groupmemberdesc'] = 'Standard role for a member of a group.'; $string['notingrouping'] = '[Not in a grouping]'; $string['errornotingrouping'] = 'Sorry, you can\'t create a group in $a'; +$string['errornotingroupingedit'] = 'Sorry, you can\'t edit grouping $a'; +$string['errorinvalidgrouping'] = 'Error, invalid grouping $a'; +$string['errorinvalidgroup'] = 'Error, invalid group $a'; +$string['erroreditgrouping'] = 'Error creating/updating grouping $a'; +$string['erroreditgroup'] = 'Error creating/updating grouping $a'; $string['groupings'] = 'Groupings'; $string['grouping'] = 'Grouping';