StaffInfoReport   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 158
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 58
c 0
b 0
f 0
dl 0
loc 158
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateGraph() 0 53 5
A setResults() 0 18 1
A __construct() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp\Reports;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author       Brian Wahoff <[email protected]>
19
 * @author       Eric Juden <[email protected]>
20
 * @author       XOOPS Development Team
21
 */
22
23
use XoopsModules\Xhelp;
24
use Amenadiel\JpGraph\Plot;
25
use Amenadiel\JpGraph\Graph;
26
27
//require_once \XHELP_JPGRAPH_PATH . '/jpgraph.php';
28
//require_once \XHELP_JPGRAPH_PATH . '/jpgraph_bar.php';
29
// require_once XHELP_CLASS_PATH . '/report.php';
30
Xhelp\Utility::includeReportLangFile('reports/staffInfo');
31
32
global $xoopsDB;
33
34
/**
35
 * class StaffInfoReport
36
 */
37
class StaffInfoReport extends Xhelp\Reports\Report
38
{
39
    /**
40
     * Xhelp\StaffInfoReport constructor.
41
     */
42
    public function __construct()
43
    {
44
        $this->initVar('results', \XOBJ_DTYPE_ARRAY, null, false);
45
        $this->initVar('hasResults', \XOBJ_DTYPE_INT, 0, false);
46
        $this->initVar('hasGraph', \XOBJ_DTYPE_INT, 1, false);
47
        /*
48
         if (PHP_VERSION >= 5) {      // Problems with JPGRAPH and php5 using bar graphs - Don't display for php5
49
         $this->setVar('hasGraph', 0);
50
         } else {
51
         $this->setVar('hasGraph', 1);
52
         }
53
         */
54
    }
55
56
    public $name       = 'staffInfoReport';
57
    public $meta       = [
58
        'name'        => \_XHELP_STAFF_INFO_NAME,
59
        'author'      => 'Eric Juden',
60
        'authorEmail' => '[email protected]',
61
        'description' => \_XHELP_STAFF_INFO_DESC,
62
        'version'     => '1.0',
63
        'dbFields'    => [
64
            'name'             => 'Name',
65
            'ticketsResponded' => 'Tickets Responded',
66
            'callsClosed'      => 'Calls Closed',
67
            'avgResponseTime'  => 'Average Response Time (in Minutes)',
68
        ],
69
    ];
70
    public $parameters = [];
71
    /*
72
     function generateReport()
73
     {
74
     if ($this->getVar('hasResults') == 0) {
75
     $this->setResults();
76
     }
77
     $aResults = $this->getVar('results');
78
79
     if (empty($aResults)) {       // If no records found
80
     $myReport = $this->generateReportNoData();
81
82
     return $myReport;
83
     }
84
85
     // Print graph
86
     $myReport = '';
87
     $myReport .= "<div id='xhelp_graph'>";
88
     $myReport .= "<img src='".XHELP_BASE_URL."/report.php?op=graph&name=staffInfo' align='center' width='500' height='300'>";
89
     $myReport .= "</div>";
90
91
     // Display report
92
     $myReport .= "<br>";
93
     $myReport .= "<div id='xhelp_report'>";
94
     $myReport .= "<table>";
95
     $myReport .= "<tr>";
96
     $dbFields = $this->meta['dbFields'];
97
     foreach ($dbFields as $dbField=>$field) {
98
     $myReport .= "<th>".$field."</th>";
99
     }
100
     $myReport .= "</tr>";
101
102
     foreach ($aResults as $result) {
103
     $myReport .= "<tr class='even'>";
104
     foreach ($dbFields as $dbField=>$field) {
105
     $myReport .= "<td>". $result[$dbField] ."</td>";
106
     }
107
     $myReport .= "</tr>";
108
     }
109
     $myReport .= "</table>";
110
     $myReport .= "</div>";
111
112
     return $myReport;
113
     }
114
     */
115
116
    /**
117
     * @return bool
118
     */
119
    public function generateGraph(): bool
120
    {
121
        if (0 == $this->getVar('hasGraph')) {
122
            return false;
123
        }
124
125
        if (0 == $this->getVar('hasResults')) {
126
            $this->setResults();
127
        }
128
        $aResults = $this->getVar('results');
129
130
        $graph = new Graph\Graph(500, 300);
131
        $graph->title->Set($this->meta['name']);
132
        $graph->setScale('textint');
133
        $graph->yaxis->scale->SetGrace(30);
134
135
        //$graph->ygrid->Show(true,true);
136
        $graph->ygrid->SetColor('gray', '[email protected]');
137
138
        // Setup graph colors
139
        $graph->SetMarginColor('white');
140
141
        $i    = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $i is dead and can be removed.
Loading history...
142
        $data = [];
143
        foreach ($aResults as $result) {
144
            $data[0][] = $result['name'];
145
            $data[1][] = $result['ticketsResponded'];
146
            $data[2][] = $result['callsClosed'];
147
            $data[3][] = $result['avgResponseTime'];
148
        }
149
150
        $datazero = [0, 0, 0, 0];
151
152
        // Create the "dummy" 0 bplot
153
        $bplotzero = new Plot\BarPlot($datazero);
154
155
        // Set names as x-axis label
156
        $graph->xaxis->SetTickLabels($data[0]);
157
158
        // Create the "Y" axis group
159
        foreach ($data as $d) {
160
            $ybplot1 = new Plot\BarPlot($d);
161
            $ybplot1->value->Show();
162
            $ybplot = new Plot\GroupBarPlot([$ybplot1, $bplotzero]);
163
164
            $graph->Add($ybplot);
165
        }
166
167
        // Set graph background image
168
        $graph->SetBackgroundImage(\XHELP_IMAGE_PATH . '/graph_bg.jpg', BGIMG_FILLFRAME);
169
170
        $graph->Stroke();
171
        return true;
172
    }
173
174
    /**
175
     * @return bool
176
     */
177
    public function setResults(): bool
178
    {
179
        global $xoopsDB;
180
        $sSQL = \sprintf(
181
            'SELECT DISTINCT s.ticketsResponded, s.callsClosed, s.email, u.name, s.responseTime / s.ticketsResponded / 60 AS avgResponseTime FROM `%s` s, %s u, %s t WHERE (s.uid = u.uid) AND (s.uid = t.ownership) AND (s.uid = t.closedBy) %s',
182
            $xoopsDB->prefix('xhelp_staff'),
183
            $xoopsDB->prefix('users'),
184
            $xoopsDB->prefix('xhelp_tickets'),
185
            $this->extraWhere
186
        );
187
188
        $result   = $xoopsDB->query($sSQL);
189
        $aResults = $this->arrayFromData($result);
190
191
        $this->setVar('results', \serialize($aResults));
192
        $this->setVar('hasResults', 1);
193
194
        return true;
195
    }
196
197
    /**
198
     * @return void
199
     */
200
    //    public function getParams()
201
    //    {
202
    //    }
203
}
204