Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7022 | Rev 7044 | 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) {
6916 eleazar 54
 
55
        $this->SetLegends($values, '');
56
 
5866 eleazar 57
        // We need some data
58
        $datay = $values;
59
        $datax = $labels;
60
 
61
        // Setup the graph.
6106 eleazar 62
        $graph = new Graph\PieGraph(400, 240);
5866 eleazar 63
        $graph->clearTheme();
64
        $graph->SetShadow();
65
 
66
        // Create the bar pot
67
        $bplot = new Plot\PiePlot($datay);
7001 eleazar 68
        $bplot->SetLegends($datax);
7005 eleazar 69
        $bplot->SetCenter(0.3);
5866 eleazar 70
 
71
        // Setup color for gradient fill style
72
        // Set color for the frame of each bar
73
        $bplot->SetColor("white");
6128 eleazar 74
        $bplot->SetLabelType(PIE_VALUE_PER);
5866 eleazar 75
        $graph->Add($bplot);
76
 
77
 
6098 eleazar 78
        $graph->Stroke($filename);
5866 eleazar 79
    }
6143 eleazar 80
 
81
    function barChart($label, $values, $title, $filename)
82
    {
6168 eleazar 83
        $graph = new Graph\Graph(700, count($values) * 50, 'auto');
6148 eleazar 84
        $graph->SetScale('textint');
6143 eleazar 85
        $graph->clearTheme();
86
        $graph->SetShadow();
6179 eleazar 87
        $graph->Set90AndMargin(130, 30, 60, 30);
6147 eleazar 88
 
6143 eleazar 89
        $graph->xaxis->SetTickLabels($label);
6144 eleazar 90
 
91
        $bplot = new Plot\BarPlot($values);
92
        $bplot->SetFillColor('orange');
93
        $bplot->SetWidth(0.5);
94
        $bplot->SetShadow();
7021 eleazar 95
        $bplot->SetCenter(0.3);
6144 eleazar 96
 
97
        $bplot->value->Show();
98
        $graph->Add($bplot);
99
 
100
        $graph->Stroke($filename);
6143 eleazar 101
    }
6908 eleazar 102
 
6911 eleazar 103
    function SetLegends($values, $format)
6908 eleazar 104
    {
105
        $this->legends=array();
106
        $this->wLegend=0;
6911 eleazar 107
        $this->sum=array_sum($values);
108
        $this->NbVal=count($values);
109
        foreach($values as $l=>$val)
6908 eleazar 110
        {
111
            $p=sprintf('%.2f',$val/$this->sum*100).'%';
112
            $legend=str_replace(array('%l','%v','%p'),array($l,$val,$p),$format);
113
            $this->legends[]=$legend;
114
            $this->wLegend=max($this->GetStringWidth($legend),$this->wLegend);
115
        }
116
    }
6935 eleazar 117
 
118
     /**
119
     * Create Table
120
     * @param string $title
121
     * @param array $content
122
     */
123
    function borderTable($title, $content) {
124
 
125
        // Header Table
126
        $this->SetFillColor(204, 204, 204);
127
        $this->SetDrawColor(0, 0, 0);
128
        $this->SetLineWidth(0);
129
        $this->SetFont('Arial', 'B', 9);
130
 
131
        $this->Cell(190, 6, utf8_decode($title), 1, 0, 'L', true);
132
        $this->Ln();
133
 
134
        // Body Table
135
        $this->SetFillColor(225, 255, 255);
136
        $this->SetTextColor(0);
137
 
138
        foreach ($content as $rs) {
139
            if (isset($rs['title'])) {
140
 
141
                $this->SetFont('Arial', 'B', 9);
142
                $this->Cell(50, 10, utf8_decode($rs['title']), 1, 0, 'L', false);
143
                $this->MultiCell(140, 10, utf8_decode($rs['content']), 1, 'L', false);
144
                $this->Ln();
145
            } else {
146
 
147
                $this->SetFont('Arial', '', 9);
148
                $this->MultiCell(190, 6, utf8_decode($rs['content']), 1, 'L', false);
149
            }
150
        }
151
        $this->Ln(5);
152
    }
5866 eleazar 153
}