Proyectos de Subversion LeadersLinked - Backend

Rev

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