Skip to content

Commit

Permalink
Certificates report and downloads - refs BT#9442
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Feb 27, 2015
1 parent bc44892 commit cc87b80
Show file tree
Hide file tree
Showing 3 changed files with 272 additions and 1 deletion.
150 changes: 150 additions & 0 deletions main/gradebook/certificate_report.php
@@ -0,0 +1,150 @@
<?php
/* For licensing terms, see /license.txt */
/**
* List all certificates filtered by session/course and month/year
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.gradebook
*/
$language_file = array('gradebook', 'exercice');
$cidReset = true;

require_once '../inc/global.inc.php';

$this_section = SECTION_TRACKING;

api_block_anonymous_users();

$interbreadcrumb[] = array(
"url" => api_get_path(WEB_CODE_PATH) . "mySpace/index.php",
"name" => get_lang("MySpace")
);

$selectedSession = isset($_POST['session']) && !empty($_POST['session']) ? intval($_POST['session']) : 0;
$selectedCourse = isset($_POST['course']) && !empty($_POST['course']) ? intval($_POST['course']) : 0;
$selectedMonth = isset($_POST['month']) && !empty($_POST['month']) ? intval($_POST['month']) : 0;
$selectedYear = isset($_POST['year']) && !empty($_POST['year']) ? $_POST['year'] : null;

$userId = api_get_user_id();
$sessions = SessionManager::getSessionsCoachedByUser($userId);

if ($selectedSession > 0) {
$courses = SessionManager::get_course_list_by_session_id($selectedSession);

if (is_array($courses)) {
foreach ($courses as &$course) {
$course['real_id'] = $course['id'];
}
}
} else {
$courses = CourseManager::get_courses_list_by_user_id($userId);

if (is_array($courses)) {
foreach ($courses as &$course) {
$courseInfo = api_get_course_info_by_id($course['real_id']);

$course = array_merge($course, $courseInfo);
}
}
}

$months = array();

for ($key = 1; $key <= 12; $key++) {
$months[] = array(
'key' => $key,
'name' => sprintf("%02d", $key)
);
}

$exportAllLink = null;
$certificateStudents = array();

$searchSessionAndCourse = $selectedSession > 0 && $selectedCourse > 0;
$searchCourseOnly = $selectedSession <= 0 && $selectedCourse > 0;

if ($searchSessionAndCourse || $searchCourseOnly) {
$selectedCourseInfo = api_get_course_info_by_id($selectedCourse);

$gradebookCategories = Category::load(null, null, $selectedCourseInfo['code'], null, false, $selectedSession);

$gradebook = current($gradebookCategories);

$exportAllLink = api_get_path(WEB_CODE_PATH) . "gradebook/gradebook_display_certificate.php?";
$exportAllLink .= http_build_query(array(
"action" => "export_all_certificates",
"cidReq" => $selectedCourseInfo['code'],
"id_session" => 0,
"gidReq" => 0,
"cat_id" => $gradebook->get_id()
));

$studentList = GradebookUtils::get_list_users_certificates($gradebook->get_id());

$certificateStudents = array();

if (is_array($studentList)) {
foreach ($studentList as $student) {
$certificateStudent = array(
'fullName' => api_get_person_name($student['firstname'], $student['lastname']),
'certificates' => array()
);

$studentCertificates = GradebookUtils::get_list_gradebook_certificates_by_user_id(
$student['user_id'],
$gradebook->get_id()
);

if (!is_array($studentCertificates)) {
continue;
}

foreach ($studentCertificates as $certificate) {
$creationDate = new DateTime($certificate['created_at']);
$creationMonth = $creationDate->format('m');
$creationYear = $creationDate->format('Y');
$creationMonthYear = $creationDate->format('m Y');

if ($selectedMonth > 0 && empty($selectedYear)) {
if ($creationMonth != $selectedMonth) {
continue;
}
} elseif ($selectedMonth <= 0 && !empty($selectedYear)) {
if ($creationYear != $selectedYear) {
continue;
}
} elseif ($selectedMonth > 0 && !empty($selectedYear)) {
if ($creationMonthYear != sprintf("%d %s", $selectedMonth, $selectedYear)) {
continue;
}
}

$certificateStudent['certificates'][] = array(
'createdAt' => api_convert_and_format_date($certificate['created_at']),
'id' => $certificate['id']
);
}

if (count($certificateStudent['certificates']) > 0) {
$certificateStudents[] = $certificateStudent;
}
}
}
}

/* View */
$template = new Template(get_lang('GradebookListOfStudentsCertificates'));

$template->assign('selectedSession', $selectedSession);
$template->assign('selectedCourse', $selectedCourse);
$template->assign('selectedMonth', $selectedMonth);
$template->assign('selectedYear', $selectedYear);
$template->assign('sessions', $sessions);
$template->assign('courses', $courses);
$template->assign('months', $months);
$template->assign('exportAllLink', $exportAllLink);
$template->assign('certificateStudents', $certificateStudents);
$content = $template->fetch("default/gradebook/certificate_report.tpl");

$template->assign('content', $content);

$template->display_one_col_template();
6 changes: 5 additions & 1 deletion main/mySpace/index.php
Expand Up @@ -6,7 +6,7 @@
* @package chamilo.reporting
*/

$language_file = array('registration', 'index', 'tracking', 'admin', 'exercice');
$language_file = array('registration', 'index', 'tracking', 'admin', 'exercice', 'gradebook');

// resetting the course id
$cidReset = true;
Expand Down Expand Up @@ -150,6 +150,10 @@
Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH)."auth/my_progress.php"
);
echo Display::url(
Display::return_icon("certificate_list.png", get_lang("GradebookSeeListOfStudentsCertificates"), array(), ICON_SIZE_MEDIUM),
api_get_path(WEB_CODE_PATH) . "gradebook/certificate_report.php"
);
}

// Actions menu
Expand Down
117 changes: 117 additions & 0 deletions main/template/default/gradebook/certificate_report.tpl
@@ -0,0 +1,117 @@
<script>
$(document).on('ready', function () {
$('select#session').on('change', function () {
var sessionId = parseInt(this.value, 10),
$selectCourse = $('select#course');
$selectCourse.empty();
$.get('{{ _p.web_main }}inc/ajax/course.ajax.php', {
a: 'display_sessions_courses',
session: sessionId
}, function (courseList) {
var $option = null;
$('<option>', {
value: 0,
text: "{{ 'Select' | get_lang }}"
}).appendTo($selectCourse);
if (courseList.length > 0) {
$.each(courseList, function (index, course) {
$('<option>', {
value: course.id,
text: course.name
}).appendTo($selectCourse);
});
}
}, 'json');
});
});
</script>

<form action="{{ _p.web_main }}gradebook/certificate_report.php" method="post" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="session">{{ 'Sessions' | get_lang }}</label>
<div class="controls">
<select name="session" id="session">
<option value="0">{{ 'Select' | get_lang }}</option>
{% for session in sessions %}
<option value="{{ session.id }}" {{ selectedSession == session.id ? 'selected' : '' }}>{{ session.name }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="course">{{ 'Courses' | get_lang }}</label>
<div class="controls">
<select name="course" id="course">
<option value="0">{{ 'Select' | get_lang }}</option>
{% for course in courses %}
<option value="{{ course.real_id }}" {{ selectedCourse == course.real_id ? 'selected' : ''}}>{{ course.title }}</option>
{% endfor %}
</select>
</div>
</div>
<div class="control-group">
<label class="control-label" for="month">{{ 'Date' | get_lang }}</label>
<div class="controls">
<select name="month" id="month">
<option value="0">{{ 'Select' | get_lang }}</option>
{% for month in months %}
<option value="{{ month.key }}" {{ selectedMonth == month.key ? 'selected' : ''}}>{{ month.name }}</option>
{% endfor %}
</select>
<input type="text" name="year" id="year" class="input-mini" value="{{ selectedYear }}">
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">{{ 'Search' | get_lang }}</button>
</div>
</div>
</form>

<h1 class="page-header">{{ 'GradebookListOfStudentsCertificates' | get_lang }}</h1>

{% if not certificateStudents is empty %}
<p>
<a href="{{ exportAllLink }}" class="btn btn-info">{{ 'ExportAllCertificatesToPDF' | get_lang }}</a>
</p>

<table class="table table-striped">
<thead>
<tr>
<th>{{ 'Student' | get_lang }}</th>
<th>{{ 'Date' | get_lang }}</th>
<th>{{ 'Certificate' | get_lang }}</th>
</tr>
</thead>
<tfoot>
<tr>
<th>{{ 'Student' | get_lang }}</th>
<th>{{ 'Date' | get_lang }}</th>
<th>{{ 'Certificate' | get_lang }}</th>
</tr>
</tfoot>
<tbody>
{% for student in certificateStudents %}
<tr>
<td>{{ student.fullName }}</td>
<td>
{% for certificate in student.certificates %}
<p>{{ certificate.createdAt }}</p>
{% endfor %}
</td>
<td>
{% for certificate in student.certificates %}
<a href="{{ _p.web }}certificates/index.php?id={{ certificate.id }}" class="btn">{{ 'Certificate' | get_lang }}</a>
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="alert alert-info">{{ 'NoResults' | get_lang }}</p>
{% endif %}

0 comments on commit cc87b80

Please sign in to comment.