Project

General

Profile

Bug #5666

Error getting groups from course

Added by Jose Manuel Abuin Mosquera almost 7 years ago. Updated almost 7 years ago.

Status:
Bug resolved
Priority:
Normal
Category:
Agenda
Target version:
Start date:
19/10/2012
Due date:
% Done:

100%

Estimated time:
Spent time:
Complexity:
Normal
SCRUM pts - complexity:
?

Description

Chamilo version: 1.9.2

When you want to add a new appointment in the agenda and you select the "To" field, you can see a lot of groups (in this case 130 groups) even if you don't have any group in your course.

I found the problem at file main/inc/lib/course.lib.php in function get_group_list_of_course

$session_id != 0 ? $session_condition = ' WHERE g.session_id IN.')' : $session_condition = ' WHERE g.session_id = 0';

should be:

$session_id != 0 ? $session_condition = ' AND g.session_id IN.')' : $session_condition = ' AND g.session_id = 0';

AND

$sql = "SELECT g.id, g.name, COUNT userNb
FROM ".Database::get_course_table(TABLE_GROUP)." AS g
LEFT JOIN ".Database::get_course_table(TABLE_GROUP_USER)." gu
ON (g.id = gu.group_id AND g.c_id = $course_id AND gu.c_id = $course_id)
$session_condition
GROUP BY g.id
ORDER BY g.name";

should be:

$sql = "SELECT g.id, g.name, COUNT userNb
FROM ".Database::get_course_table(TABLE_GROUP)." AS g
LEFT JOIN ".Database::get_course_table(TABLE_GROUP_USER)." gu
ON g.id = gu.group_id WHERE g.c_id = $course_id AND gu.c_id = $course_id
$session_condition
GROUP BY g.id
ORDER BY g.name";

It needs testing

History

#1

Updated by Julio Montoya almost 7 years ago

  • Status changed from New to Needs more info

Hi Jose,
I think I already sent a fix for that for 1.9.4 here's the new function:


  public static function get_group_list_of_course($course_code, $session_id = 0) {
        $course_info = Database::get_course_info($course_code);
        $course_id = $course_info['real_id'];
        $group_list = array();
        $session_id != 0 ? $session_condition = ' WHERE g.session_id IN(1,'.intval($session_id).')' : $session_condition = ' WHERE g.session_id = 0';

        $sql = "SELECT g.id, g.name
                FROM ".Database::get_course_table(TABLE_GROUP)." AS g
                INNER JOIN ".Database::get_course_table(TABLE_GROUP_USER)." gu
                ON (g.id = gu.group_id AND g.c_id = $course_id AND gu.c_id = $course_id)
                $session_condition                
                ORDER BY g.name";
        $result = Database::query($sql);

        while ($group_data = Database::fetch_array($result)) {
            $group_data['userNb'] = GroupManager::number_of_students($group_data['id'], $course_id);
            $group_list[$group_data['id']] = $group_data;
        }
        return $group_list;
    }

make sure you have this function GroupManager::number_of_students() too

#2

Updated by Jose Manuel Abuin Mosquera almost 7 years ago

Indeed Julio, now it's working fine with your fix :)

I am sorry, I didn't check if somebody already reported this problem :(

Thank you so much

#3

Updated by Julio Montoya almost 7 years ago

  • Status changed from Needs more info to Bug resolved
  • % Done changed from 0 to 100

No problem, thanks for reporting!

Also available in: Atom PDF