Skip to content

Commit

Permalink
Add export reports to PDF see BT#10043
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed Jun 30, 2015
1 parent 6600da3 commit 33a9576
Show file tree
Hide file tree
Showing 6 changed files with 336 additions and 28 deletions.
130 changes: 130 additions & 0 deletions main/gradebook/gradebook_display_summary.php
@@ -0,0 +1,130 @@
<?php
/* For licensing terms, see /license.txt */

/**
* Script
* @package chamilo.gradebook
*/

$language_file = 'gradebook';

require_once '../inc/global.inc.php';
$current_course_tool = TOOL_GRADEBOOK;

api_protect_course_script();

set_time_limit(0);
ini_set('max_execution_time', 0);
api_block_anonymous_users();

if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
}

$cat_id = isset($_GET['selectcat']) ? (int)$_GET['selectcat'] : null;
$action = isset($_GET['action']) && $_GET['action'] ? $_GET['action'] : null;

$userList = CourseManager::get_user_list_from_course_code(
api_get_course_id(),
api_get_session_id()
);

switch ($action) {
case 'export_all':

$params = array();
$pdf = new PDF('A4', 'P', $params);

$pdfList = array();
foreach ($userList as $index => $value) {
$pdfList[] = GradebookUtils::generateTable(
$value['user_id'],
$cat_id,
false,
true
);
}

if (!empty($pdfList)) {
// Print certificates (without the common header/footer/watermark
// stuff) and return as one multiple-pages PDF
$pdf->html_to_pdf(
$pdfList,
null,
null,
false,
false,
true
);
}

break;
case 'download':
$userId = isset($_GET['user_id']) && $_GET['user_id'] ? $_GET['user_id'] : null;
GradebookUtils::generateTable($userId, $cat_id);
break;
/*case 'generate_all_certificates':
$user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id());
if (!empty($user_list)) {
foreach ($user_list as $user_info) {
if ($user_info['status'] == INVITEE) {
continue;
}
Category::register_user_certificate($cat_id, $user_info['user_id']);
}
}
break;
case 'delete_all_certificates':
Category::deleteAllCertificates($cat_id);
break;*/
}

$course_code = api_get_course_id();

$interbreadcrumb[] = array('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?', 'name' => get_lang('Gradebook'));
$interbreadcrumb[] = array('url' => '#','name' => get_lang('GradebookListOfStudentsReports'));

$this_section = SECTION_COURSES;

Display::display_header('');

$token = Security::get_token();

echo Display::page_header(get_lang('GradebookListOfStudentsReports'));

echo '<div class="btn-group">';
/*$url = api_get_self().'?action=generate_all_certificates'.'&'.api_get_cidReq().'&selectcat='.$cat_id;
echo Display::url(get_lang('GenerateCertificates'), $url, array('class' => 'btn'));
*/
/*$url = api_get_self().'?action=delete_all_certificates'.'&'.api_get_cidReq().'&selectcat='.$cat_id;
echo Display::url(get_lang('DeleteAllCertificates'), $url, array('class' => 'btn'));*/

if (count($userList) > 0) {
$url = api_get_self().'?action=export_all&'.api_get_cidReq().'&selectcat='.$cat_id;
echo Display::url(get_lang('ExportAllToPDF'), $url, array('class' => 'btn btn-default'));
}
echo '</div>';

if (count($userList) == 0 ) {
echo Display::display_warning_message(get_lang('NoResultsAvailable'));
} else {
echo '<br /><br /><table class="data_table">';
foreach ($userList as $index => $value) {
echo '<tr>
<td width="100%" >'.
get_lang('Student').' : '.api_get_person_name($value['firstname'], $value['lastname']).' ('.$value['username'].') </td>';
echo '<td>';
$url = api_get_self().'?'.api_get_cidreq().'&action=download&user_id='.$value['user_id'].'&selectcat='.$cat_id;
$link = Display::url(
get_lang('ExportToPDF'),
$url,
array('target' => '_blank', 'class' => 'btn btn-default')
);
echo $link;
echo '</td></tr>';
}
echo '</table>';
}

Display::display_footer();
89 changes: 89 additions & 0 deletions main/gradebook/lib/GradebookUtils.php
Expand Up @@ -1299,4 +1299,93 @@ public static function getUserCertificatesInSessions($userId, $includeNonPublicC
return $sessionList;
}

/**
* @param int $userId
* @param int $categoryId
* @param bool $saveToFile
* @param bool $saveToHtmlFile
*
* @return string
*/
public static function generateTable($userId, $categoryId, $saveToFile = false, $saveToHtmlFile = false)
{
$courseInfo = api_get_course_info();
$userInfo = api_get_user_info($userId);

$cats = Category::load($categoryId, null, null, null, null, null, false);
$cat = $cats[0];

$allcat = $cats[0]->get_subcategories(
$userId,
api_get_course_id(),
api_get_session_id()
);
$alleval = $cats[0]->get_evaluations($userId);
$alllink = $cats[0]->get_links($userId);

$gradebooktable = new GradebookTable(
$cat,
$allcat,
$alleval,
$alllink,
null, // params
true, // $exportToPdf
false, // showteacher
$userId
);

if (api_is_allowed_to_edit()) {
$gradebooktable->td_attributes = [
4 => 'class=centered'
];
} else {
$gradebooktable->td_attributes = [
3 => 'class=centered',
4 => 'class=centered',
5 => 'class=centered',
6 => 'class=centered',
7 => 'class=centered'
];
}

$table = $gradebooktable->return_table();
$graph = $gradebooktable->getGraph();

$sessionName = api_get_session_name(api_get_session_id());
$sessionName = !empty($sessionName) ? " - $sessionName" : '';
$params = array(
//'filename' => get_lang('FlatView') . '_' . api_get_utc_datetime(),
'pdf_title' => $courseInfo['title'].$sessionName,
'course_code' => api_get_course_id(),
'session_info' => api_get_session_info(api_get_session_id()),
'add_signatures' => false,
'student_info' => $userInfo,
'show_grade_generated_date' => true,
'show_real_course_teachers' => true
);

$file = api_get_path(SYS_ARCHIVE_PATH).uniqid().'.html';

$content =
$table.
$graph.
'<br />'.get_lang('Feedback').'<br />
<textarea rows="5" cols="100" ></textarea>';

$pdf = new PDF('A4', $params['orientation'], $params);

$result = $pdf->html_to_pdf_with_template(
$content,
$saveToFile,
$saveToHtmlFile
);

if ($saveToHtmlFile) {
file_put_contents($file, $result);
return $file;
}

return $file;
}

}
13 changes: 13 additions & 0 deletions main/gradebook/lib/fe/displaygradebook.php
Expand Up @@ -584,6 +584,19 @@ static function header(
. "</td>";
}

$header .= "<td style=\"vertical-align: top;\">"
. Display::url(
Display::return_icon(
'user.png',
get_lang('GradebookListOfStudentsReports'),
'',
ICON_SIZE_MEDIUM
),
"gradebook_display_summary.php?$my_api_cidreq&selectcat=" . intval($_GET['selectcat'])
)
. "</td>";


// Right icons
$modify_icons = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . '&amp;cidReq=' . $catobj->get_course_code() . '&id_session='.$catobj->get_session_id(). '">' .
Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_MEDIUM) . '</a>';
Expand Down

0 comments on commit 33a9576

Please sign in to comment.