Rev 7145 | Rev 15154 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?php
namespace LeadersLinked\Library;
use Fpdf\Fpdf;
use Amenadiel\JpGraph\Graph;
use Amenadiel\JpGraph\Plot;
class SurveyReport extends FPDF {
/**
* Header PDF
*/
function Header() {
$this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/header_background.png', 10, 8, 190);
$this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/header_logo.png', 130, 20, 60);
}
/**
* Header custom PDF
* @param string $headerFormName
* @param string $headerUsername
*/
function customHeader($headerFormName, $headerUsername) {
$s = utf8_decode(' Página: ' . $this->PageNo());
$this->SetFont('Arial', '', 10);
$this->SetY(40);
$this->Cell(190, 10, $s, 0, 0, 'R');
$this->SetFont('Arial', 'B', 15);
$this->SetY(50);
$this->Cell(180, 10, $headerFormName, 0, 0, 'C');
$this->setY($this->getY() + 8);
$this->SetFont('Arial', '', 10);
$this->Cell(180, 10, $headerUsername, 0, 0, 'C');
$this->setY($this->getY() + 10);
}
/**
* Footer PDF
*/
function Footer() {
$this->SetY(-30);
$this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/footer_background.jpg', 10, $this->getY(), 190);
}
/**
* Create chart PDF
* @param string[] $labels
* @param float[] $values
* @param string $title
* @param string $filename
*/
function pieChart($labels, $values, $title, $filename) {
// We need some data
$datay = $values;
$datax = $labels;
// Setup the graph.
$graph = new Graph\PieGraph(400, 240);
$graph->clearTheme();
$graph->SetShadow();
// Create the bar pot
$bplot = new Plot\PiePlot($datay);
$bplot->SetLegends($datax);
$bplot->SetCenter(0.3);
// Setup color for gradient fill style
// Set color for the frame of each bar
$bplot->SetColor("white");
$bplot->SetLabelType(PIE_VALUE_PER);
$graph->Add($bplot);
$graph->Stroke($filename);
}
function barChart($label, $values, $title, $filename)
{
$graph = new Graph\Graph(700, count($values) * 50, 'auto');
$graph->SetScale('textint');
$graph->clearTheme();
$graph->SetShadow();
$graph->Set90AndMargin(130, 30, 60, 30);
$bplot = new Plot\BarPlot($values);
$bplot->SetFillColor('orange');
$bplot->SetWidth(0.5);
$bplot->SetShadow();
$bplot->SetCenter(0.3);
$bplot->value->Show();
$graph->Add($bplot);
$graph->Stroke($filename);
}
/**
* Create Table
* @param string $title
* @param array $content
*/
function borderTable($title, $content) {
// Header Table
$this->SetFillColor(204, 204, 204);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0);
$this->SetFont('Arial', 'B', 9);
$this->Cell(190, 6, utf8_decode($title), 1, 0, 'L', true);
$this->Ln();
// Body Table
$this->SetFillColor(225, 255, 255);
$this->SetTextColor(0);
foreach ($content as $rs) {
if (isset($rs['title'])) {
$this->SetFont('Arial', 'B', 9);
$this->Cell(50, 10, utf8_decode($rs['title']), 1, 0, 'L', false);
$this->MultiCell(140, 10, utf8_decode($rs['content']), 1, 'L', false);
$this->Ln();
} else {
$this->SetFont('Arial', '', 9);
$this->MultiCell(190, 6, utf8_decode($rs['content']), 1, 'L', false);
}
}
$this->Ln(5);
}
}