Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 6102 | Rev 6106 | 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() {
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);
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.
6103 eleazar 59
        $graph = new Graph\PieGraph(600, 340);
5866 eleazar 60
        $graph->clearTheme();
61
        $graph->SetShadow();
62
 
63
        // Create the bar pot
64
        $bplot = new Plot\PiePlot($datay);
6095 eleazar 65
        $bplot->SetLegends($datax);
5866 eleazar 66
 
67
        // Setup color for gradient fill style
68
        // Set color for the frame of each bar
69
        $bplot->SetColor("white");
70
        $graph->Add($bplot);
71
 
72
 
6098 eleazar 73
        $graph->Stroke($filename);
5866 eleazar 74
    }
75
 
6071 eleazar 76
    function BarDiagram($w, $h, $data, $format, $color=null, $maxVal=0, $nbDiv=4)
77
    {
78
        $this->SetFont('Courier', '', 10);
79
        $this->SetLegends($data,$format);
80
 
81
        $XPage = $this->GetX();
82
        $YPage = $this->GetY();
83
        $margin = 2;
84
        $YDiag = $YPage + $margin;
85
        $hDiag = floor($h - $margin * 2);
86
        $XDiag = $XPage + $margin * 2 + $this->wLegend;
87
        $lDiag = floor($w - $margin * 3 - $this->wLegend);
88
        if($color == null)
89
            $color=array(155,155,155);
90
        if ($maxVal == 0) {
91
            $maxVal = max($data);
92
        }
93
        $valIndRepere = ceil($maxVal / $nbDiv);
94
        $maxVal = $valIndRepere * $nbDiv;
95
        $lRepere = floor($lDiag / $nbDiv);
96
        $lDiag = $lRepere * $nbDiv;
97
        $unit = $lDiag / $maxVal;
98
        $hBar = floor($hDiag / ($this->NbVal + 1));
99
        $hDiag = $hBar * ($this->NbVal + 1);
100
        $eBaton = floor($hBar * 80 / 100);
101
 
102
        $this->SetLineWidth(0.2);
103
        $this->Rect($XDiag, $YDiag, $lDiag, $hDiag);
104
 
105
        $this->SetFont('Courier', '', 10);
106
        $this->SetFillColor($color[0],$color[1],$color[2]);
107
        $i=0;
108
        foreach($data as $val) {
109
            //Bar
110
            $xval = $XDiag;
111
            $lval = (int)($val * $unit);
112
            $yval = $YDiag + ($i + 1) * $hBar - $eBaton / 2;
113
            $hval = $eBaton;
114
            $this->Rect($xval, $yval, $lval, $hval, 'DF');
115
            //Legend
116
            $this->SetXY(0, $yval);
117
            $this->Cell($xval - $margin, $hval, $this->legends[$i],0,0,'R');
118
            $i++;
119
        }
120
 
121
        //Scales
122
        for ($i = 0; $i <= $nbDiv; $i++) {
123
            $xpos = $XDiag + $lRepere * $i;
124
            $this->Line($xpos, $YDiag, $xpos, $YDiag + $hDiag);
125
            $val = $i * $valIndRepere;
126
            $xpos = $XDiag + $lRepere * $i - $this->GetStringWidth($val) / 2;
127
            $ypos = $YDiag + $hDiag - $margin;
128
            $this->Text($xpos, $ypos, $val);
129
        }
130
    }
131
 
5866 eleazar 132
}