Skip to content

Commit

Permalink
Lps: Show users from a group + remove submit button see BT#17370
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Nov 10, 2020
1 parent 0aaebc2 commit 52d5c3c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
55 changes: 50 additions & 5 deletions main/lp/lp_report.php
Expand Up @@ -39,15 +39,51 @@
$em = Database::getManager();
// Check LP subscribers
if ('1' === $lp->getSubscribeUsers()) {
$course = api_get_course_entity($courseId);
$session = api_get_session_entity($sessionId);

/** @var ItemPropertyRepository $itemRepo */
$itemRepo = $em->getRepository('ChamiloCourseBundle:CItemProperty');
$subscribedUsersInLp = $itemRepo->getUsersSubscribedToItem(
'learnpath',
$lpId,
api_get_course_entity($courseId),
api_get_session_entity($sessionId)
$course,
$session
);

// Subscribed groups to a LP
$subscribedGroupsInLp = $itemRepo->getGroupsSubscribedToItem(
'learnpath',
$lpId,
$course,
$session
);

$groups = [];
/** @var CItemProperty $itemProperty */
if (!empty($subscribedGroupsInLp)) {
foreach ($subscribedGroupsInLp as $itemProperty) {
if (!empty($itemProperty)) {
$getGroup = $itemProperty->getGroup();
if (!empty($getGroup)) {
$groups[] = $itemProperty->getGroup()->getId();
}
}
}
}

$users = [];
if (!empty($groups)) {
foreach ($groups as $groupId) {
$students = GroupManager::getStudents($groupId);
if (!empty($students)) {
foreach ($students as $studentInfo) {
$users[]['user_id'] = $studentInfo['user_id'];
}
}
}
}

if (!empty($subscribedUsersInLp)) {
foreach ($subscribedUsersInLp as $itemProperty) {
$user = $itemProperty->getToUser();
Expand Down Expand Up @@ -115,9 +151,12 @@
'group_filter',
get_lang('Groups'),
array_column($groups, 'name', 'iid'),
['placeholder' => get_lang('All')]
[
'id' => 'group_filter',
'placeholder' => get_lang('All')
]
);
$form->addButtonSearch(get_lang('Search'));
//$form->addButtonSearch(get_lang('Search'));

if (!empty($groupFilter)) {
$users = GroupManager::getStudents($groupFilter, true);
Expand Down Expand Up @@ -174,8 +213,13 @@
$userList = [];
$showEmail = api_get_setting('show_email_addresses');
if (!empty($users)) {
$added = [];
foreach ($users as $user) {
$userId = $user['user_id'];
if (in_array($userId, $added)) {
continue;
}

$userInfo = api_get_user_info($userId);
$lpTime = Tracking::get_time_spent_in_lp(
$userId,
Expand Down Expand Up @@ -230,6 +274,7 @@
'lp_progress' => "$lpProgress%",
'lp_last_connection' => $lpLastConnection,
];
$added[] = $userId;
}
} else {
Display::addFlash(Display::return_message(get_lang('NoUserAdded'), 'warning'));
Expand Down Expand Up @@ -271,7 +316,7 @@
),
$url.'&reset=group',
[
'onclick' => 'javascript: if (!confirm(\''.addslashes(get_lang('AreYouSureToDeleteResults').': '.$userListToString).'\')) return false;',
'onclick' => 'javascript: if(!confirm(\''.addslashes(get_lang('AreYouSureToDeleteResults').': '.$userListToString).'\')) return false;',
]
);
}
Expand Down
9 changes: 9 additions & 0 deletions main/template/default/learnpath/report.tpl
@@ -1,5 +1,14 @@
{{ group_form }}

<script>
$(function(){
$('#group_filter').on('change', function() {
var groupId = $(this).val();
window.location.href = "{{ url }}&group_filter=" + groupId;
});
});
</script>
<div class="table-responsive">
<table class="table table-hover table-striped table-bordered">
<thead>
Expand Down

0 comments on commit 52d5c3c

Please sign in to comment.