Rev 15152 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpnamespace LeadersLinked\Library;use Fpdf\Fpdf;use Amenadiel\JpGraph\Graph\PieGraph;use Amenadiel\JpGraph\Plot\PiePlot;use Amenadiel\JpGraph\Graph\Graph;use Amenadiel\JpGraph\Plot\LinePlot;use Amenadiel\JpGraph\Plot\BarPlot;use Amenadiel\JpGraph\Themes\UniversalTheme;use Amenadiel\JpGraph\Themes\PastelTheme;use Amenadiel\JpGraph\Themes\SoftyTheme;class SurveyReport extends FPDF {public $header;public $footer;/*** Header PDF*/function Header() {if ($this->header != '') {$this->Image($this->header, 10, 8, 190);$this->SetY(55);}}/*** 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);if($headerUsername) {$this->SetFont('Arial', '', 10);$this->Cell(180, 10, $headerUsername, 0, 0, 'C');$this->setY($this->getY() + 10);}}/*** Footer PDF*/function Footer() {if ($this->footer != '') {$this->SetY(-40);$this->Image($this->footer, 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) {// Setup the graph.$graph = new PieGraph(600, 240);$graph->SetTheme(new SoftyTheme());//$graph->clearTheme();//$graph->SetShadow();// Create the bar pot$bplot = new PiePlot($values);$bplot->SetLegends($labels);$bplot->SetCenter(0.2);// 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($labels, $values, $title, $filename){$graph = new Graph(700, count($values) * 100, 'auto');$graph->SetScale('textint');$graph->clearTheme();$graph->SetShadow();$graph->Set90AndMargin(130, 30, 60, 30);$graph->yscale->ticks->SupressZeroLabel(false);// Setup X-axis labels$graph->xaxis->SetTickLabels($labels);$graph->xaxis->SetLabelAngle(40);$bplot = new BarPlot($values);$bplot->SetFillColor('orange');$bplot->SetShadow();$bplot->SetCenter(0.2);$bplot->SetWidth(0.6);$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, $this-> cleanStringToPdf($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, $this-> cleanStringToPdf($rs['title']), 1, 0, 'L', false);$this->MultiCell(140, 10, $this-> cleanStringToPdf($rs['content']), 1, 'L', false);$this->Ln();} else {$this->SetFont('Arial', '', 9);$this->MultiCell(190, 6, $this-> cleanStringToPdf($rs['content']), 1, 'L', false);}}$this->Ln(5);}private function cleanStringToPdf($s){$s = html_entity_decode($s);$detect = mb_detect_encoding($s);if(strtoupper($detect) != 'UTF8') {$s = mb_convert_encoding($s, 'UTF8', $detect);}return strip_tags($s);}}