Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 6908 | Rev 6916 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5866 eleazar 1
<?php
2
 
3
namespace LeadersLinked\Library;
4
 
5
use Fpdf\Fpdf;
6
use Amenadiel\JpGraph\Graph;
7
use Amenadiel\JpGraph\Plot;
8
 
9
class SurveyReport extends FPDF {
10
 
11
    /**
12
     * Header PDF
13
     */
14
    function Header() {
6847 eleazar 15
        $this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/header_background.png', 10, 8, 190);
16
        $this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/header_logo.png', 130, 20, 60);
5866 eleazar 17
    }
18
    /**
19
     * Header custom PDF
20
     * @param string $headerFormName
21
     * @param string $headerUsername
22
     */
23
    function customHeader($headerFormName, $headerUsername) {
24
        $s = utf8_decode(' Página: ' . $this->PageNo());
25
        $this->SetFont('Arial', '', 10);
26
        $this->SetY(40);
27
        $this->Cell(190, 10, $s, 0, 0, 'R');
28
 
29
        $this->SetFont('Arial', 'B', 15);
30
        $this->SetY(50);
31
        $this->Cell(180, 10, $headerFormName, 0, 0, 'C');
32
        $this->setY($this->getY() + 8);
33
 
34
 
35
        $this->SetFont('Arial', '', 10);
36
        $this->Cell(180, 10, $headerUsername, 0, 0, 'C');
37
        $this->setY($this->getY() + 10);
38
    }
39
    /**
40
     * Footer PDF
41
     */
42
    function Footer() {
43
        $this->SetY(-30);
44
        $this->Image($_SERVER['DOCUMENT_ROOT'] . '/pdf/footer_background.jpg', 10, $this->getY(), 190);
45
    }
46
    /**
47
     * Create chart PDF
48
     * @param string[] $labels
49
     * @param float[] $values
50
     * @param string $title
51
     * @param string $filename
52
     */
6039 eleazar 53
    function pieChart($labels, $values, $title, $filename) {
5866 eleazar 54
        // We need some data
55
        $datay = $values;
56
        $datax = $labels;
57
 
58
        // Setup the graph.
6106 eleazar 59
        $graph = new Graph\PieGraph(400, 240);
5866 eleazar 60
        $graph->clearTheme();
61
        $graph->SetShadow();
62
 
63
        // Create the bar pot
64
        $bplot = new Plot\PiePlot($datay);
6128 eleazar 65
        $bplot->SetLabels($datax);
66
        $bplot->SetLabelPos(1);
5866 eleazar 67
 
68
        // Setup color for gradient fill style
69
        // Set color for the frame of each bar
70
        $bplot->SetColor("white");
6128 eleazar 71
        $bplot->SetLabelType(PIE_VALUE_PER);
5866 eleazar 72
        $graph->Add($bplot);
73
 
74
 
6098 eleazar 75
        $graph->Stroke($filename);
5866 eleazar 76
    }
6143 eleazar 77
 
78
    function barChart($label, $values, $title, $filename)
79
    {
6168 eleazar 80
        $graph = new Graph\Graph(700, count($values) * 50, 'auto');
6148 eleazar 81
        $graph->SetScale('textint');
6143 eleazar 82
        $graph->clearTheme();
83
        $graph->SetShadow();
6179 eleazar 84
        $graph->Set90AndMargin(130, 30, 60, 30);
6147 eleazar 85
 
6143 eleazar 86
        $graph->xaxis->SetTickLabels($label);
6144 eleazar 87
 
88
        $bplot = new Plot\BarPlot($values);
89
        $bplot->SetFillColor('orange');
90
        $bplot->SetWidth(0.5);
91
        $bplot->SetShadow();
92
 
93
        $bplot->value->Show();
94
        $graph->Add($bplot);
95
 
96
        $graph->Stroke($filename);
6143 eleazar 97
    }
6908 eleazar 98
 
6911 eleazar 99
    function SetLegends($values, $format)
6908 eleazar 100
    {
101
        $this->legends=array();
102
        $this->wLegend=0;
6911 eleazar 103
        $this->sum=array_sum($values);
104
        $this->NbVal=count($values);
105
        foreach($values as $l=>$val)
6908 eleazar 106
        {
107
            $p=sprintf('%.2f',$val/$this->sum*100).'%';
108
            $legend=str_replace(array('%l','%v','%p'),array($l,$val,$p),$format);
109
            $this->legends[]=$legend;
110
            $this->wLegend=max($this->GetStringWidth($legend),$this->wLegend);
111
        }
112
    }
5866 eleazar 113
}