Skip to content

Commit

Permalink
LP: Add reset progress in report view BT#17983
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Nov 5, 2020
1 parent ca9bff4 commit c045504
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 48 deletions.
119 changes: 92 additions & 27 deletions main/lp/lp_report.php
Expand Up @@ -11,30 +11,32 @@
require_once __DIR__.'/../inc/global.inc.php';

api_protect_course_script(true);

$isAllowedToEdit = api_is_allowed_to_edit(null, true);

if (!$isAllowedToEdit) {
api_not_allowed(true);
}

$lpTable = Database::get_course_table(TABLE_LP_MAIN);
$courseInfo = api_get_course_info();
$sessionId = api_get_session_id();
$courseId = api_get_course_int_id();
$courseCode = api_get_course_id();

$lpId = isset($_REQUEST['lp_id']) ? (int) $_REQUEST['lp_id'] : 0;
$studentId = isset($_REQUEST['student_id']) ? (int) $_REQUEST['student_id'] : 0;
$groupFilter = isset($_REQUEST['group_filter']) ? (int) $_REQUEST['group_filter'] : 0;
$export = isset($_REQUEST['export']);
$reset = isset($_REQUEST['reset']) ? $_REQUEST['reset'] : '';

$lp = new learnpath(api_get_course_id(), $lpId, api_get_user_id());
$lp = new learnpath($courseCode, $lpId, api_get_user_id());
if (empty($lp)) {
api_not_allowed(true);
}

$url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq().'&action=report&lp_id='.$lpId;
$url = api_get_path(WEB_CODE_PATH).
'lp/lp_controller.php?'.api_get_cidreq().'&action=report&lp_id='.$lpId.'&group_filter='.$groupFilter;

$em = Database::getManager();
$sessionId = api_get_session_id();
$courseId = api_get_course_int_id();
$courseCode = api_get_course_id();

// Check LP subscribers
if ('1' === $lp->getSubscribeUsers()) {
/** @var ItemPropertyRepository $itemRepo */
Expand All @@ -48,7 +50,10 @@
$users = [];
if (!empty($subscribedUsersInLp)) {
foreach ($subscribedUsersInLp as $itemProperty) {
$users[]['user_id'] = $itemProperty->getToUser()->getId();
$user = $itemProperty->getToUser();
if ($user) {
$users[]['user_id'] = $itemProperty->getToUser()->getId();
}
}
}
} else {
Expand All @@ -60,7 +65,10 @@
$users = [];
if (!empty($subscribedUsersInCategory)) {
foreach ($subscribedUsersInCategory as $item) {
$users[]['user_id'] = $item->getUser()->getId();
$user = $item->getUser();
if ($user) {
$users[]['user_id'] = $item->getUser()->getId();
}
}
}
} else {
Expand Down Expand Up @@ -96,30 +104,75 @@
'first'
);

$groups = GroupManager::get_group_list(null, api_get_course_info(), null, api_get_session_id());
$groupFilter = '';
$groups = GroupManager::get_group_list(null, $courseInfo, null, $sessionId);
$groupFilterForm = '';
if (!empty($groups)) {
$form = new FormValidator('group', 'post', $url);
$form = new FormValidator('group', 'GET', $url);
$form->addHidden('action', 'report');
$form->addHidden('lp_id', $lpId);
$form->addCourseHiddenParams();
$form->addSelect(
'group_id',
'group_filter',
get_lang('Groups'),
array_column($groups, 'name', 'iid'),
['placeholder' => get_lang('SelectAnOption')]
['placeholder' => get_lang('All')]
);
$form->addButtonSearch(get_lang('Search'));

if ($form->validate()) {
$groupId = $form->getSubmitValue('group_id');
if (!empty($groupId)) {
$users = GroupManager::getStudents($groupId, true);
}
if (!empty($groupFilter)) {
$users = GroupManager::getStudents($groupFilter, true);
$form->setDefaults(['group_filter' => $groupFilter]);
}
$groupFilterForm = $form->returnForm();
}

if ($reset) {
switch ($reset) {
case 'student':
if ($studentId) {
$studentInfo = api_get_user_info($studentId);
if ($studentInfo) {
Event::delete_student_lp_events(
$studentId,
$lpId,
$courseInfo,
$sessionId
);
Display::addFlash(
Display::return_message(
get_lang('LPWasReset').': '.$studentInfo['complete_name_with_username'],
'success'
)
);
}
}
break;
case 'group':
foreach ($users as $user) {
$userId = $user['user_id'];
$studentInfo = api_get_user_info($userId);
if ($studentInfo) {
Event::delete_student_lp_events(
$userId,
$lpId,
$courseInfo,
$sessionId
);
Display::addFlash(
Display::return_message(
get_lang('LPWasReset').': '.$studentInfo['complete_name_with_username'],
'success'
)
);
}
}
break;
}
$groupFilter = $form->returnForm();
api_location($url);
}

$userList = [];
$showEmail = api_get_setting('show_email_addresses');

if (!empty($users)) {
foreach ($users as $user) {
$userId = $user['user_id'];
Expand Down Expand Up @@ -167,6 +220,7 @@

$userList[] = [
'id' => $userId,
'username' => $userInfo['username'],
'first_name' => $userInfo['firstname'],
'last_name' => $userInfo['lastname'],
'email' => 'true' === $showEmail ? $userInfo['email'] : '',
Expand All @@ -181,7 +235,6 @@
Display::addFlash(Display::return_message(get_lang('NoUserAdded'), 'warning'));
}

// View
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(),
'name' => get_lang('LearningPaths'),
Expand All @@ -207,6 +260,20 @@
),
$url.'&export=pdf'
);
$userListToString = array_column($userList, 'username');
$userListToString = implode(', ', $userListToString);
$actions .= Display::url(
Display::return_icon(
'clean.png',
get_lang('Clean'),
[],
ICON_SIZE_MEDIUM
),
$url.'&reset=group',
[
'onclick' => 'javascript: if (!confirm(\''.addslashes(get_lang('AreYouSureToDeleteResults').': '.$userListToString).'\')) return false;',
]
);
}

$template = new Template(get_lang('StudentScore'));
Expand All @@ -216,13 +283,11 @@
$template->assign('lp_id', $lpId);
$template->assign('show_email', 'true' === $showEmail);
$template->assign('export', (int) $export);
$template->assign('groups', $groupFilter);

$template->assign('group_form', $groupFilterForm);
$template->assign('url', $url);
$layout = $template->get_template('learnpath/report.tpl');

$template->assign('header', $lpInfo['name']);
$template->assign('actions', Display::toolbarAction('lp_actions', [$actions]));

$result = $template->fetch($layout);
$template->assign('content', $result);

Expand Down
60 changes: 39 additions & 21 deletions main/template/default/learnpath/report.tpl
@@ -1,4 +1,5 @@
{{ groups }}
{{ group_form }}

<div class="table-responsive">
<table class="table table-hover table-striped table-bordered">
<thead>
Expand All @@ -19,26 +20,43 @@
</tr>
</thead>
<tbody>
{% for user in user_list %}
<tr id="row-{{ user.id }}">
<td>{{ user.first_name }}</td>
<td>{{ user.last_name }}</td>
{% if show_email %}
<td>{{ user.email }}</td>
{% endif %}
<td>{{ user.groups }}</td>
<td class="text-center">{{ user.lp_time }}</td>
<td class="text-right">{{ user.lp_progress }}</td>
<td class="text-right">{{ user.lp_score }}</td>
<td class="text-center">{{ user.lp_last_connection }}</td>
{% if not export %}
<td>
<button class="btn btn-primary btn-sm" data-id="{{ user.id }}">{{ 'Details'|get_lang }}</button>
</td>
{% endif %}
</tr>
<tr class="hide"></tr>
{% endfor %}
{% for user in user_list %}
{% set trackingUrl = _p.web ~ 'main/mySpace/myStudents.php?details=true' ~ _p.web_cid_query ~ '&course=' ~ course.code ~ '&origin=tracking_course&id_session='~ session_id ~'&student=' ~ user.id %}
<tr id="row-{{ user.id }}">
<td>
<a href="{{ trackingUrl }}" target="_blank">
{{ user.first_name }}
</a>
</td>
<td>
<a href="{{ trackingUrl }}" target="_blank">
{{ user.last_name }}
</a>
</td>
{% if show_email %}
<td>{{ user.email }}</td>
{% endif %}
<td>{{ user.groups }}</td>
<td class="text-center">{{ user.lp_time }}</td>
<td class="text-right">{{ user.lp_progress }}</td>
<td class="text-right">{{ user.lp_score }}</td>
<td class="text-center">{{ user.lp_last_connection }}</td>
{% if not export %}
<td>
<button class="btn btn-primary btn-sm" data-id="{{ user.id }}">
{{ 'Details'|get_lang }}
</button>
<a
href = "{{ url }}&student_id={{ user.id }}&reset=student"
onclick = "javascript:if(!confirm('{{ 'AreYouSureToDeleteJS' | get_lang | e('js') }}')) return false;"
>
<img title="{{ 'Reset' | get_lang }}" src="{{ 'clean.png'|icon(32) }}">
</a>
</td>
{% endif %}
</tr>
<tr class="hide"></tr>
{% endfor %}
</tbody>
</table>
</div>
Expand Down

0 comments on commit c045504

Please sign in to comment.