Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7047 | Rev 7049 | 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);
7048 eleazar 92
        $bplot->SetFillColor('orange');
93
        $bplot->SetWidth(0.5);
94
        $bplot->SetShadow();
95
        $bplot->SetLegend($label);
7021 eleazar 96
        $bplot->SetCenter(0.3);
6144 eleazar 97
 
98
        $bplot->value->Show();
99
        $graph->Add($bplot);
100
 
101
        $graph->Stroke($filename);
6143 eleazar 102
    }
6908 eleazar 103
 
6911 eleazar 104
    function SetLegends($values, $format)
6908 eleazar 105
    {
106
        $this->legends=array();
107
        $this->wLegend=0;
6911 eleazar 108
        $this->sum=array_sum($values);
109
        $this->NbVal=count($values);
110
        foreach($values as $l=>$val)
6908 eleazar 111
        {
112
            $p=sprintf('%.2f',$val/$this->sum*100).'%';
113
            $legend=str_replace(array('%l','%v','%p'),array($l,$val,$p),$format);
114
            $this->legends[]=$legend;
115
            $this->wLegend=max($this->GetStringWidth($legend),$this->wLegend);
116
        }
117
    }
6935 eleazar 118
 
119
     /**
120
     * Create Table
121
     * @param string $title
122
     * @param array $content
123
     */
124
    function borderTable($title, $content) {
125
 
126
        // Header Table
127
        $this->SetFillColor(204, 204, 204);
128
        $this->SetDrawColor(0, 0, 0);
129
        $this->SetLineWidth(0);
130
        $this->SetFont('Arial', 'B', 9);
131
 
132
        $this->Cell(190, 6, utf8_decode($title), 1, 0, 'L', true);
133
        $this->Ln();
134
 
135
        // Body Table
136
        $this->SetFillColor(225, 255, 255);
137
        $this->SetTextColor(0);
138
 
139
        foreach ($content as $rs) {
140
            if (isset($rs['title'])) {
141
 
142
                $this->SetFont('Arial', 'B', 9);
143
                $this->Cell(50, 10, utf8_decode($rs['title']), 1, 0, 'L', false);
144
                $this->MultiCell(140, 10, utf8_decode($rs['content']), 1, 'L', false);
145
                $this->Ln();
146
            } else {
147
 
148
                $this->SetFont('Arial', '', 9);
149
                $this->MultiCell(190, 6, utf8_decode($rs['content']), 1, 'L', false);
150
            }
151
        }
152
        $this->Ln(5);
153
    }
5866 eleazar 154
}