Proyectos de Subversion LeadersLinked - Backend

Rev

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