Need a get_group_by_id() function

Bug #1667799 reported by Robert Lyon on 2017-02-24
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Wishlist
Cecilia Vela Gurovic

Bug Description

Unlike view/collection etc 'group' functions are not in a class.

And so there is no easy function to find group information by id.

Instead we do a db query each time we want to find some group information and by the looks of the code we are not consistent each time, eg:

  $group = get_record('group', 'id', $id, 'deleted', 0);

vs.

  $group = get_record('group', 'id', $id);

At current count there is over 40 places where we fetch group by id via direct db call.

It would be useful to have all those places fetch the info via function. That way we can have consistency across the system and also allow for the replying with additional information such as roles and whether one can edit or not, eg:

 get_group_by_id($id, $includedeleted = true, $getroles = false, $canedit = false) {
    if ($includedeletd) {
        $group = get_record('group', 'id', $groupid, 'deleted', 0);
    }
    else {
        $group = get_record('group', 'id', $groupid);
    }
    if (empty($group)) {
       return false;
    }
    if ($getroles) {
        $group->roles = group_user_access($group->id);
    }
    if ($canedit) {
        $group->canedit = $role && group_role_can_edit_views($group, $group->roles);
    }
    return $group;
 }

Robert Lyon (robertl-9) wrote :

Actually Ideally 'Group' would be it's own class with it's own variables / methods - like views - but that would be much more work to do.

Changed in mahara:
importance: Undecided → Wishlist
milestone: none → 17.04.0
status: New → Confirmed
Changed in mahara:
assignee: nobody → Cecilia Vela Gurovic (ceciliavg)
Changed in mahara:
status: Confirmed → In Progress

Cases to test:

Go to a group and check you can see the journals for that group,
should not show old deleted journals or journals from other groups

Check if a user can post in the journals it has permissions to post

When creating a journal group, it shows correct info from group

Creating a new post/editing a post in a group journal shows the correct information

A group member can see journal entries in a group journal

When searching for groups, membership of the group is not displayed
if it is configured to hide the membership in the group settings

Copying a group gets the correct information

Check that you can see a forums in any group
Check that you can see topic pages in group forums

Successfully delete a group

User can leave the group, join a group, invite another user to a group

screen /download.php generates correct numbers in report

After editing a group view, check the "Return to group pages" button returns to the correct group

Clean urls is working correctly for groups
https://wiki.mahara.org/wiki/System_Administrator's_Guide/Clean_URL_Configuration

A group member with role 'tutor', can release with no problems a view that was submitted to the group

Reviewed: https://reviews.mahara.org/7492
Committed: https://git.mahara.org/mahara/mahara/commit/0edbc6fd2b89ff355d0f9ee01fafdadcd4348d37
Submitter: Robert Lyon (<email address hidden>)
Branch: master

commit 0edbc6fd2b89ff355d0f9ee01fafdadcd4348d37
Author: Cecilia Vela Gurovic <email address hidden>
Date: Mon Feb 27 17:31:31 2017 +1300

Bug 1667799: Added function to find group information by id

Replaced most calls to DB to request group
basic information, for get_group_by_id() method
in group library

behatnotneeded

Change-Id: Ie03520a6c7a364ead63ccedaff07118a5928348e

Robert Lyon (robertl-9) on 2017-03-05
Changed in mahara:
status: In Progress → Fix Committed
Robert Lyon (robertl-9) on 2017-04-27
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers