Skip to content

Commit

Permalink
Adding order_user_list_by_official_code see BT#8697
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Oct 1, 2014
1 parent 6f818a9 commit ea16dbd
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 12 deletions.
41 changes: 38 additions & 3 deletions main/admin/add_users_to_usergroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,13 @@ function change_select(val) {
$order = array('firstname');
}

global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$order = array('official_code', 'lastname');
}

$conditions = array();

if (!empty($first_letter_user)) {
Expand Down Expand Up @@ -242,10 +249,22 @@ function change_select(val) {
}

if (in_array($item['user_id'], $list_in)) {
$officialCode = !empty($item['official_code']) ? ' - '.$item['official_code'] : null;
$person_name = api_get_person_name(
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') '.$item['official_code'];
).' ('.$item['username'].') '.$officialCode;

if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$officialCode = !empty($item['official_code']) ? $item['official_code'].' - ' : '? - ';
$person_name = $officialCode.api_get_person_name(
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') ';
}

$elements_in[$item['user_id']] = $person_name;
}
}
Expand Down Expand Up @@ -273,11 +292,27 @@ function change_select(val) {
continue;
}
}
if ($item['status'] == 6 ) continue; //avoid anonymous users

// Avoid anonymous users
if ($item['status'] == 6) {
continue;
}
$officialCode = !empty($item['official_code']) ? ' - '.$item['official_code'] : null;
$person_name = api_get_person_name(
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') '.$item['official_code'];
).' ('.$item['username'].') '.$officialCode;

if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$officialCode = !empty($item['official_code']) ? $item['official_code'].' - ' : '? - ';
$person_name = $officialCode.api_get_person_name(
$item['firstname'],
$item['lastname']
).' ('.$item['username'].') ';
}

if (in_array($item['user_id'], $list_in)) {
//$elements_in[$item['user_id']] = $person_name;
} else {
Expand Down
51 changes: 45 additions & 6 deletions main/group/member_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@
$current_group = GroupManager::get_group_properties($group_id);

$nameTools = get_lang('EditGroup');
$interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);
$interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups'));
$interbreadcrumb[] = array('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);

$is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);

if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
api_not_allowed(true);
}

/* FUNCTIONS */

/**
* List all users registered to the course
*/
Expand All @@ -60,6 +58,23 @@ function search_members_keyword($firstname, $lastname, $username, $official_code
*/
function sort_users($user_a, $user_b)
{
global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$cmp = api_strcmp($user_a['official_code'], $user_b['official_code']);
if ($cmp !== 0) {
return $cmp;
} else {
$cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
if ($cmp !== 0) {
return $cmp;
} else {
return api_strcmp($user_a['username'], $user_b['username']);
}
}
}

if (api_sort_by_first_name()) {
$cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
if ($cmp !== 0) {
Expand Down Expand Up @@ -98,6 +113,7 @@ function check_group_members($value)
if (isset($value['max_student']) && isset($value['group_members']) && $value['max_student'] < count($value['group_members'])) {
return array('group_members' => get_lang('GroupTooMuchMembers'));
}

return true;
}

Expand All @@ -121,7 +137,24 @@ function check_group_members($value)
if (!empty($complete_user_list)) {
usort($complete_user_list, 'sort_users');
foreach ($complete_user_list as $index => $user) {
$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
$officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;

$name = api_get_person_name(
$user['firstname'],
$user['lastname']
).' ('.$user['username'].')'.$officialCode;

global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$officialCode = !empty($user['official_code']) ? $user['official_code']." - " : '? - ';
$name = $officialCode." ".api_get_person_name(
$user['firstname'],
$user['lastname']
).' ('.$user['username'].')';
}
$possible_users[$user['user_id']] = $name;
}
}

Expand All @@ -134,7 +167,13 @@ function check_group_members($value)
$selected_users[] = $user['user_id'];
}
}
$group_members_element = $form->addElement('advmultiselect', 'group_members', get_lang('GroupMembers'), $possible_users, 'style="width: 280px;"');
$group_members_element = $form->addElement(
'advmultiselect',
'group_members',
get_lang('GroupMembers'),
$possible_users,
'style="width: 280px;"'
);

$group_members_element->setElementTemplate('
{javascript}
Expand Down
35 changes: 34 additions & 1 deletion main/group/tutor_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ function search_members_keyword($firstname, $lastname, $username, $official_code
*/
function sort_users($user_a, $user_b)
{
global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$cmp = api_strcmp($user_a['official_code'], $user_b['official_code']);
if ($cmp !== 0) {
return $cmp;
} else {
$cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
if ($cmp !== 0) {
return $cmp;
} else {
return api_strcmp($user_a['username'], $user_b['username']);
}
}
}

if (api_sort_by_first_name()) {
$cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
if ($cmp !== 0) {
Expand Down Expand Up @@ -115,7 +132,23 @@ function sort_users($user_a, $user_b)
usort($complete_user_list, 'sort_users');

foreach ($complete_user_list as $index => $user) {
$possible_users[$user['user_id']] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')';
$officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
$name = api_get_person_name(
$user['firstname'],
$user['lastname']
).' ('.$user['username'].')'.$officialCode;

global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$officialCode = !empty($user['official_code']) ? $user['official_code']." - " : '? - ';
$name = $officialCode." ".api_get_person_name(
$user['firstname'],
$user['lastname']
).' ('.$user['username'].')';
}
$possible_users[$user['user_id']] = $name;
}
}

Expand Down
18 changes: 16 additions & 2 deletions main/inc/lib/groupmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1399,6 +1399,13 @@ public static function get_subscribed_users($group_id)
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_group_user = Database :: get_course_table(TABLE_GROUP_USER);
$order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$order_clause = " ORDER BY u.official_code, u.firstname, u.lastname";
}

if (empty($group_id)) {
return array();
}
Expand Down Expand Up @@ -1436,8 +1443,15 @@ public static function get_subscribed_tutors($group_id, $id_only = false)
{
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR);
$order_clause = api_sort_by_first_name(
) ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';
$order_clause = api_sort_by_first_name() ? ' ORDER BY u.firstname, u.lastname' : ' ORDER BY u.lastname, u.firstname';

global $_configuration;
if (isset($_configuration['order_user_list_by_official_code']) &&
$_configuration['order_user_list_by_official_code']
) {
$order_clause = " ORDER BY u.official_code, u.firstname, u.lastname";
}

$group_id = Database::escape_string($group_id);
$course_id = api_get_course_int_id();

Expand Down
2 changes: 2 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,5 @@
//$_configuration['session_days_after_coach_access'] = 0;
// PDF Logo header located in main/css/xxx/images/pdf_logo_header.png
//$_configuration['pdf_logo_header'] = false;
// Order inscription user list by official_code
//$_configuration['order_user_list_by_official_code'] = false;

0 comments on commit ea16dbd

Please sign in to comment.