Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7146 | Rev 15154 | 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;
15152 efrain 6
use Amenadiel\JpGraph\Graph\PieGraph;
7
use Amenadiel\JpGraph\Plot\PiePlot;
8
use Amenadiel\JpGraph\Graph\Graph;
9
use Amenadiel\JpGraph\Plot\LinePlot;
10
use Amenadiel\JpGraph\Plot\BarPlot;
11
use Amenadiel\JpGraph\Themes\UniversalTheme;
12
use Amenadiel\JpGraph\Themes\PastelTheme;
13
use Amenadiel\JpGraph\Themes\SoftyTheme;
5866 eleazar 14
 
15152 efrain 15
 
5866 eleazar 16
class SurveyReport extends FPDF {
17
 
15152 efrain 18
 
19
    public $header;
20
    public $footer;
21
 
22
 
5866 eleazar 23
    /**
24
     * Header PDF
25
     */
26
    function Header() {
15152 efrain 27
 
28
        if ($this->header != '') {
29
            $this->Image($this->header, 10, 8, 190);
30
            $this->SetY(55);
31
        }
5866 eleazar 32
    }
33
    /**
34
     * Header custom PDF
35
     * @param string $headerFormName
36
     * @param string $headerUsername
37
     */
38
    function customHeader($headerFormName, $headerUsername) {
39
        $s = utf8_decode(' Página: ' . $this->PageNo());
40
        $this->SetFont('Arial', '', 10);
41
        $this->SetY(40);
42
        $this->Cell(190, 10, $s, 0, 0, 'R');
43
 
44
        $this->SetFont('Arial', 'B', 15);
45
        $this->SetY(50);
46
        $this->Cell(180, 10, $headerFormName, 0, 0, 'C');
47
        $this->setY($this->getY() + 8);
48
 
49
 
50
        $this->SetFont('Arial', '', 10);
51
        $this->Cell(180, 10, $headerUsername, 0, 0, 'C');
52
        $this->setY($this->getY() + 10);
53
    }
54
    /**
55
     * Footer PDF
56
     */
57
    function Footer() {
15152 efrain 58
        if ($this->footer != '') {
59
            $this->SetY(-40);
60
            $this->Image($this->footer, 10, $this->getY(), 190);
61
        }
5866 eleazar 62
    }
63
    /**
64
     * Create chart PDF
65
     * @param string[] $labels
66
     * @param float[] $values
67
     * @param string $title
68
     * @param string $filename
69
     */
6039 eleazar 70
    function pieChart($labels, $values, $title, $filename) {
6916 eleazar 71
 
5866 eleazar 72
        // Setup the graph.
15152 efrain 73
        $graph = new PieGraph(600, 240);
74
        $graph->SetTheme(new SoftyTheme());
75
        //$graph->clearTheme();
76
        //$graph->SetShadow();
5866 eleazar 77
 
15152 efrain 78
 
5866 eleazar 79
        // Create the bar pot
15152 efrain 80
        $bplot = new PiePlot($values);
81
        $bplot->SetLegends($labels);
82
        $bplot->SetCenter(0.2);
5866 eleazar 83
 
84
        // Setup color for gradient fill style
85
        // Set color for the frame of each bar
86
        $bplot->SetColor("white");
6128 eleazar 87
        $bplot->SetLabelType(PIE_VALUE_PER);
15152 efrain 88
 
5866 eleazar 89
        $graph->Add($bplot);
15152 efrain 90
 
5866 eleazar 91
 
92
 
6098 eleazar 93
        $graph->Stroke($filename);
5866 eleazar 94
    }
15152 efrain 95
 
6143 eleazar 96
 
15152 efrain 97
 
98
    function barChart($labels, $values, $title, $filename)
6143 eleazar 99
    {
15152 efrain 100
        $graph = new Graph(700, count($values) * 100, 'auto');
6148 eleazar 101
        $graph->SetScale('textint');
6143 eleazar 102
        $graph->clearTheme();
103
        $graph->SetShadow();
6179 eleazar 104
        $graph->Set90AndMargin(130, 30, 60, 30);
15152 efrain 105
 
106
        $graph->yscale->ticks->SupressZeroLabel(false);
107
 
108
        // Setup X-axis labels
109
        $graph->xaxis->SetTickLabels($labels);
110
        $graph->xaxis->SetLabelAngle(40);
111
 
6144 eleazar 112
 
15152 efrain 113
        $bplot = new BarPlot($values);
7048 eleazar 114
        $bplot->SetFillColor('orange');
15152 efrain 115
 
7048 eleazar 116
        $bplot->SetShadow();
15152 efrain 117
        $bplot->SetCenter(0.2);
118
        $bplot->SetWidth(0.6);
6144 eleazar 119
 
120
        $bplot->value->Show();
121
        $graph->Add($bplot);
122
 
123
        $graph->Stroke($filename);
6143 eleazar 124
    }
6908 eleazar 125
 
6935 eleazar 126
     /**
127
     * Create Table
128
     * @param string $title
129
     * @param array $content
130
     */
131
    function borderTable($title, $content) {
132
 
133
        // Header Table
134
        $this->SetFillColor(204, 204, 204);
135
        $this->SetDrawColor(0, 0, 0);
136
        $this->SetLineWidth(0);
137
        $this->SetFont('Arial', 'B', 9);
138
 
15152 efrain 139
        $this->Cell(190, 6, $this-> cleanStringToPdf($title), 1, 0, 'L', true);
6935 eleazar 140
        $this->Ln();
141
 
142
        // Body Table
143
        $this->SetFillColor(225, 255, 255);
144
        $this->SetTextColor(0);
145
 
146
        foreach ($content as $rs) {
147
            if (isset($rs['title'])) {
148
 
149
                $this->SetFont('Arial', 'B', 9);
15152 efrain 150
                $this->Cell(50, 10, $this-> cleanStringToPdf($rs['title']), 1, 0, 'L', false);
151
                $this->MultiCell(140, 10, $this-> cleanStringToPdf($rs['content']), 1, 'L', false);
6935 eleazar 152
                $this->Ln();
153
            } else {
154
 
155
                $this->SetFont('Arial', '', 9);
15152 efrain 156
                $this->MultiCell(190, 6, $this-> cleanStringToPdf($rs['content']), 1, 'L', false);
6935 eleazar 157
            }
158
        }
159
        $this->Ln(5);
160
    }
15152 efrain 161
 
162
 
163
    private function cleanStringToPdf($s)
164
    {
165
 
166
        $s = html_entity_decode($s);
167
        $detect = mb_detect_encoding($s);
168
 
169
        if(strtoupper($detect) != 'UTF8') {
170
 
171
            $s = mb_convert_encoding($s, 'UTF8', $detect);
172
 
173
        }
174
 
175
 
176
        return strip_tags($s);
177
    }
5866 eleazar 178
}