When exporting to PDF now we use a Twig template see BT#4080

skala
Julio Montoya 14 years ago
parent 4af783618c
commit 6456623814
  1. 1
      main/gradebook/gradebook_edit_cat.php
  2. 7
      main/gradebook/gradebook_flatview.php
  3. 6
      main/gradebook/index.php
  4. 13
      main/gradebook/lib/fe/catform.class.php
  5. 17
      main/gradebook/lib/flatview_data_generator.class.php
  6. 99
      main/gradebook/lib/gradebook_functions.inc.php
  7. 35
      main/inc/lib/display.lib.php
  8. 26
      main/inc/lib/pdf.lib.php
  9. 53
      main/template/default/gradebook/flatview.pdf.tpl

@ -120,7 +120,6 @@ if ($form->validate()) {
$cat->save();
$parent_id = $cat->get_parent_id();
if ($parent_id == 0) {
//do something
if (isset($values['grade_model_id']) && !empty($values['grade_model_id'])) {

@ -102,7 +102,10 @@ $flatviewtable->set_additional_parameters($parameters);
if (isset($_GET['export_pdf']) && $_GET['export_pdf'] == 'category') {
$params = array();
$params['only_total_category'] = true;
export_pdf_flatview($cat, $users, $alleval, $alllinks, $params);
if ($cat[0]->is_locked() == true || api_is_platform_admin()) {
Display :: set_header(null, false, false);
export_pdf_flatview($cat, $users, $alleval, $alllinks, $params);
}
}
if (isset($_GET['exportpdf'])) {
@ -110,10 +113,12 @@ if (isset($_GET['exportpdf'])) {
'url' => api_get_self().'?selectcat=' . Security::remove_XSS($_GET['selectcat']),
'name' => get_lang('FlatView')
);
$export_pdf_form = new DataForm(DataForm::TYPE_EXPORT_PDF, 'export_pdf_form', null, api_get_self().'?exportpdf=&offset='.intval($_GET['offset']).'&selectcat='.intval($_GET['selectcat']), '_blank', '');
if ($export_pdf_form->validate()) {
$params = $export_pdf_form->exportValues();
Display :: set_header(null, false, false);
export_pdf_flatview($cat, $users, $alleval, $alllinks, $params);
} else {
Display :: display_header(get_lang('ExportPDF'));

@ -854,11 +854,11 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
if (!empty($cats)) {
if (api_is_allowed_to_edit(null, true) && api_get_setting('teachers_can_change_grade_model_settings') == 'true') {
if (api_is_platform_admin() || (api_is_allowed_to_edit(null, true) && api_get_setting('teachers_can_change_grade_model_settings') == 'true')) {
//Getting grade models
$obj = new GradeModel();
$grade_models = $obj->get_all();
$options = array('-1' => get_lang('none'));
$options = array('-1' => get_lang('None'));
if (!empty($grade_models)) {
foreach ($grade_models as $item) {
@ -867,7 +867,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
}
$grade_model_id = $cats[0]->get_grade_model_id();
//No children
if (count($cats) == 1 && empty($grade_model_id)) {
if (!empty($grade_models)) {

@ -158,6 +158,7 @@ class CatForm extends FormValidator {
}
$global_weight = api_get_setting('gradebook_default_weight');
if (isset($global_weight)) {
$value = $global_weight;
} else {
@ -182,8 +183,7 @@ class CatForm extends FormValidator {
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
$this->add_textfield('certif_min_score', get_lang('CertificateMinScore'),false,array('class'=>'span1','maxlength'=>'5'));
$this->addRule('certif_min_score', get_lang('ThisFieldIsRequired'), 'required');
$this->addRule('certif_min_score',get_lang('OnlyNumbers'),'numeric');
//$this->addRule('certif_min_score',get_lang('NoDecimals'),'nopunctuation');
$this->addRule('certif_min_score',get_lang('OnlyNumbers'),'numeric');
$this->addRule(array('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
} else {
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
@ -191,13 +191,14 @@ class CatForm extends FormValidator {
$this->addElement('hidden','hid_user_id');
$this->addElement('hidden','hid_parent_id');
$this->addElement('textarea', 'description', get_lang('Description'),array('class'=>'span3','cols' => '34'));
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0 && api_get_setting('teachers_can_change_grade_model_settings') == 'true') {
$this->addElement('textarea', 'description', get_lang('Description'), array('class'=>'span3','cols' => '34'));
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0 && (api_is_platform_admin() || api_get_setting('teachers_can_change_grade_model_settings') == 'true')) {
//Getting grade models
$obj = new GradeModel();
$grade_models = $obj->get_all();
$options = array(-1 => get_lang('none'));
$options = array(-1 => get_lang('None'));
foreach ($grade_models as $item) {
$options[$item['id']] = $item['name'];
}

@ -93,10 +93,8 @@ class FlatViewDataGenerator
if (!isset($this->params['only_total_category'])) {
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start];
//$headers[] = $item->get_name().' <br /> '.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' ';
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$weight = round($item->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight() *100, 2);
$headers[] = $item->get_name().' '.$weight.' % ';
}
@ -202,13 +200,15 @@ class FlatViewDataGenerator
}
}
$grade_model_id = $this->category->get_grade_model_id();
$parent_id = $this->category->get_parent_id();
if ($parent_id == 0) {
$main_weight = $this->category->get_weight();
$grade_model_id = $this->category->get_grade_model_id();
} else {
$main_cat = Category::load($parent_id, null, null);
$main_weight = $main_cat[0]->get_weight();
$grade_model_id = $main_cat[0]->get_grade_model_id();
}
$use_grade_model = true;
@ -228,10 +228,11 @@ class FlatViewDataGenerator
$convert_using_the_global_weight = false;
if ($use_grade_model) {
if ($parent_id == 0) {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$allcat = $this->category->get_subcategories(null, $course_code, $session_id);
$allcat = $this->category->get_subcategories(null, $course_code, $session_id);
foreach ($allcat as $sub_cat) {
$score = $sub_cat->calc_score($user_id);
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
@ -241,8 +242,7 @@ class FlatViewDataGenerator
//Fixing total when using one or multiple gradebooks
$percentage = round($sub_cat->get_weight()/($sub_cat_percentage) * $sub_cat_percentage/$this->category->get_weight(), 2);
$item_value = $percentage*$item_value;
$item_value = $percentage*$item_value;
$item_total += $sub_cat->get_weight();
if ($convert_using_the_global_weight) {
@ -251,6 +251,7 @@ class FlatViewDataGenerator
}
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
if (!isset($this->params['only_total_category'])) {
if (!$show_all) {
$row[] = $temp_score.' ';
@ -317,7 +318,7 @@ class FlatViewDataGenerator
$item_total = round($item_total);
$total_score = array($item_value_total, $item_total);
if (!$show_all) {
if (!$show_all) {
$row[] = $scoredisplay->display_score($total_score);
} else {
$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT_WITH_CUSTOM);

@ -12,6 +12,7 @@
* @version april 2007
*/
require_once 'gradebook_functions_users.inc.php';
require_once api_get_path(LIBRARY_PATH).'grade_model.lib.php';
/**
* Adds a resource to the unique gradebook of a given course
@ -176,20 +177,19 @@ function build_edit_icons_cat($cat, $selectcat) {
if (api_is_allowed_to_edit(null, true)) {
//Locking button
if (api_get_setting('gradebook_locking_enabled') == 'true') {
if (api_get_setting('gradebook_locking_enabled') == 'true') {
if ($cat->is_locked()) {
if (api_is_platform_admin()) {
$modify_icons .= '&nbsp;<a onclick="javascrip:unlock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=unlock">'.Display::return_icon('unlock.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'</a>';
$modify_icons .= '&nbsp;<a onclick="javascrip:unlock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=unlock">'.Display::return_icon('unlock.png', get_lang('Unlock'),'',ICON_SIZE_SMALL).'</a>';
} else {
$modify_icons .= '&nbsp;<a href="#">'.Display::return_icon('unlock_na.png', get_lang('GradebookLockedAlert'),'',ICON_SIZE_SMALL).'</a>';
}
$modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).'</a>';
} else {
$modify_icons .= '&nbsp;<a onclick="javascrip:lock_confirmation()" href="' . api_get_self() . '?'. api_get_cidreq().'&category_id=' . $cat->get_id() . '&action=lock">'.Display::return_icon('lock.png', get_lang('Lock'),'',ICON_SIZE_SMALL).'</a>';
}
}
//PDF
$modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).'</a>';
//$modify_icons .= '&nbsp;<a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_SMALL).'</a>';
}
}
if (empty($grade_model_id) || $grade_model_id == -1) {
if ($cat->is_locked() && !api_is_platform_admin()) {
@ -721,45 +721,59 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$html = '';
$img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
$img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
if (file_exists($img)) {
$img = api_get_path(WEB_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
$html .= "<img src='$img'>";
$organization = "<img src='$img'>";
} else {
if (!empty($organization)) {
$html .= '<h2 align="left">'.$organization.'</h2>';
$organization = '<h2 align="left">'.$organization.'</h2>';
}
}
Display::$global_template->assign('organization', $organization);
$parent_id = $cat[0]->get_parent_id();
if (isset($cat[0]) && isset($parent_id)) {
if ($parent_id == 0) {
$grade_model_id = $cat[0]->get_grade_model_id();
} else {
$parent_cat = Category::load($parent_id);
$grade_model_id = $parent_cat[0]->get_grade_model_id();
}
}
$grade_model_id = $cat[0]->get_grade_model_id();
$use_grade_model = true;
if (empty($grade_model_id) || $grade_model_id == -1) {
$use_grade_model = false;
}
//var_dump($use_grade_model);exit;
if ($use_grade_model) {
$html .= '<h2 align="center">'.get_lang('FlatView').'</h2>';
if ($use_grade_model) {
if ($parent_id == 0) {
$title = '<h2 align="center">'.get_lang('FlatView').'</h2>';
} else {
$title = '<h2 align="center">'.$cat[0]->get_description().' - ('.$cat[0]->get_name().') </h2>';
}
} else {
$html .= '<h2 align="center">'.get_lang('FlatView').'</h2>';
$title = '<h2 align="center">'.get_lang('FlatView').'</h2>';
}
$html .= '<table align="center" width="100%"><tr><td valign="top">';
$html .= '<table align="left" width="33%">';
$session_name = api_get_session_name(api_get_session_id());
$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code);
if (!empty($session_name)) {
$html .= Display::tag('tr', Display::tag('td', get_lang('Session')).Display::tag('td', Display::tag('strong', $session_name)));
}
$html .= Display::tag('tr', Display::tag('td', get_lang('Course')).Display::tag('td', Display::tag('strong', $course_code)));
$html .= Display::tag('tr', Display::tag('td', get_lang('Date')).Display::tag('td', Display::tag('strong', api_convert_and_format_date(date('Y-m-d', time()), DATE_TIME_FORMAT_LONG))));
$html .= Display::tag('tr', Display::tag('td', get_lang('Teacher')).Display::tag('td', Display::tag('strong', $teacher_list)));
$html .= '</table></td>';
$html .= '<td valign="top"><table align="left" width="33%">';
Display::$global_template->assign('pdf_title', $title);
//Showing only the current teacher/admin instead the all teacherlist name see BT#4080
//$teacher_list = CourseManager::get_teacher_list_from_course_code_to_string($course_code);
$user_info = api_get_user_info();
$teacher_list = $user_info['complete_name'];
$session_name = api_get_session_name(api_get_session_id());
if (!empty($session_name)) {
Display::$global_template->assign('pdf_session', $session_name);
}
Display::$global_template->assign('pdf_course', $course_code);
Display::$global_template->assign('pdf_date', api_format_date(api_get_utc_datetime(), DATE_TIME_FORMAT_LONG));
Display::$global_template->assign('pdf_teachers', $teacher_list);
/*
if (!empty($total)) {
foreach($total as $label => $count) {
$total_custom_score = round($count/count($user_results), 2) *100;
@ -768,7 +782,8 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
}
$html .= '</table></td>';
$html .= '<td valign="top"><table align="left" width="33%">';
$headers = $printable_data[0];
$headers = $printable_data[0];
unset($headers[0]);
unset($headers[1]);
unset($headers[count($headers)+1]);
@ -776,8 +791,9 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
foreach ($headers as $head) {
$html .= Display::tag('tr', Display::tag('td', Display::tag('strong', $head)));
}
$html .= '</table></td></table><br />';
$html .= '</table></td></table><br />';
*/
$columns = count($printable_data[0]);
$has_data = is_array($printable_data[1]) && count($printable_data[1]) > 0;
@ -815,14 +831,19 @@ function export_pdf_flatview($cat, $users, $alleval, $alllinks, $params = array(
$table->setCellContents($row, $column, get_lang('NoResults'));
$table->updateCellAttributes($row, $column, 'colspan="'.$columns.'" align="center" class="row_odd"');
}
$html .= $table->toHtml();
Display::$global_template->assign('pdf_table', $table->toHtml());
unset($printable_data);
unset($table);
// Conversion of the created HTML report to a PDF report
// Conversion of the created HTML report to a PDF report
$gradebook_tpl = Display::$global_template->get_template('gradebook/flatview.pdf.tpl');
$gradebook_flatview = Display::$global_template->fetch($gradebook_tpl);
//Header
$html = $gradebook_flatview;
$html = api_utf8_encode($html);
$page_format = $params['orientation'] == 'landscape' ? 'A4-L' : 'A4';
$pdf = new PDF($page_format, $params['orientation']);

@ -51,11 +51,6 @@ class Display {
* @param string Optional help file name
*/
public static function display_header($tool_name ='', $help = null, $page_header = null) {
/*
global $_plugins, $lp_theme_css, $mycoursetheme, $user_theme, $platform_theme;
global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $text_dir, $plugins, $_user, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF;
global $menu_navigation;
global $htmlCSSXtra; */
self::$global_template = new Template($tool_name);
self::$global_template->set_help($help);
if (!empty(self::$preview_style)) {
@ -67,38 +62,28 @@ class Display {
}
echo self::$global_template->show_header_template();
}
/*
*
public static function assign_template_variable($variable, $content) {
if (isset(self::$global_template)) {
self::$global_template->assign($variable, $content);
} else {
//Dev message
echo 'You need to called the display_header first';
exit;
}
}*/
/**
* Displays the reduced page header (without banner)
*/
public static function display_reduced_header() {
global $_plugins, $lp_theme_css, $mycoursetheme, $user_theme, $platform_theme;
global $httpHeadXtra, $htmlHeadXtra, $htmlIncHeadXtra, $_course, $_user, $text_dir, $plugins, $_user, $_cid, $interbreadcrumb, $charset, $language_file, $noPHP_SELF, $language_interface;
global $menu_navigation;
public static function display_reduced_header() {
global $show_learnpath;
//require api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
self::$global_template = new Template($tool_name, false, false, $show_learnpath);
echo self::$global_template ->show_header_template();
}
/**
* Displays the reduced page header (without banner)
*/
public static function set_header() {
global $show_learnpath;
self::$global_template = new Template($tool_name, false, false, $show_learnpath);
}
/**
* Display the page footer
*/
public static function display_footer() {
global $_plugins, $global_tpl;
public static function display_footer() {
echo self::$global_template ->show_footer_template();
}

@ -404,8 +404,7 @@ class PDF {
}
public function set_header($course_data) {
// $pdf->SetBasePath($basehref);
public function set_header($course_data) {
$this->pdf->defaultheaderfontsize = 10; // in pts
$this->pdf->defaultheaderfontstyle = BI; // blank, B, I, or BI
@ -415,29 +414,22 @@ class PDF {
$teacher_list = CourseManager::get_teacher_list_from_course_code($course_data['code']);
$teachers = '';
if (!empty($teacher_list)) {
foreach($teacher_list as $teacher) {
foreach ($teacher_list as $teacher) {
//$teachers[]= api_get_person_name($teacher['firstname'], $teacher['lastname']);
$teachers[]= $teacher['firstname'].' '.$teacher['lastname'];
}
}
if (count($teachers) > 1) {
$teachers = get_lang('Teachers').': '.implode(', ', $teachers);
} else {
$teachers = get_lang('Teacher').': '.implode('', $teachers);
}
}
/*$img = api_get_path(SYS_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
if (file_exists($img)) {
$img = api_get_path(WEB_CODE_PATH).'css/'.api_get_visual_theme().'/images/header-logo.png';
$left_content = '<img src="'.$img.'">';
} else {
if (!empty($organization)) {
$html .= '<h2 align="left">'.$organization.'</h2>';
}
}*/
//do not show the teacher list see BT#4080 only the current teacher name
$user_info = api_get_user_info();
$teachers = $user_info['complete_name'];
}
//$left_content = '';
$left_content = '';
$center_content = '';
$right_content = $teachers;

@ -0,0 +1,53 @@
{{ organization }}
<h2> {{ pdf_title }} </h2>
<table align="center" width="100%">
<tr>
<td>
<strong>{{ "Teacher" | get_lang }}:</strong> {{ pdf_teachers }}
</td>
</tr>
{% if pdf_session != null %}
<tr>
<td>
<strong>{{ "Session" | get_lang }}:</strong> {{ pdf_session }}
</td>
</tr>
{% endif %}
<tr>
<td>
<strong>{{ "Course" | get_lang }}:</strong> {{ pdf_course }}
</td>
</tr>
<tr>
<td>
<strong>{{ "Date" | get_lang }}:</strong> {{ pdf_date }}
</td>
</tr>
</table>
<br />
{{ pdf_table }}
<br />
<br />
<table style="text-align:center" width="100%">
<tr>
<td>
_____________________________
<br />
{{ "RRHH" | get_lang }}
</td>
<td>
_____________________________<br />
{{ "Teacher" | get_lang }}
</td>
<td>
_____________________________<br />
{{ "Date" | get_lang }}
</td>
</tr>
</table>
Loading…
Cancel
Save