Proyectos de Subversion LeadersLinked - Backend

Rev

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