Completed
Pull Request — develop (#184)
by Neil
25:03
created

GraphController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A json() 0 11 1
A png() 0 10 1
A csv() 0 11 1
1
<?php
2
/**
3
 * app/Api/Controllers/GraphController.php
4
 *
5
 * API Controller for alerts log data
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2016 Neil Lathwood
23
 * @author     Neil Lathwood <[email protected]>
24
 */
25
26
namespace App\Api\Controllers;
27
28
use Dingo\Api\Http;
29
use Dingo\Api\Routing\Helpers;
30
use Illuminate\Http\Request;
31
use Symfony\Component\Process\Process;
32
use Symfony\Component\Process\Exception\ProcessFailedException;
33
34
class GraphController extends Controller
35
{
36
37
    use Helpers;
38
39
    /**
40
     * Obtain and format data for json output
41
     *
42
     * @param Request $request
43
     * @param string $type
44
     * @return \Illuminate\Pagination\LengthAwarePaginator
45
     */
46
    public function json(Request $request, $type)
47
    {
48
        ob_start('ob_gzhandler');
49
        $class = 'App\Graphs\\' . ucfirst($type);
50
        $input = json_decode($request->{'input'});
51
        $data=new $class();
52
        $data->setType($type);
53
        $data->setInput($input);
54
        $data->setDevice($input);
55
        return $data->json($request);
56
    }
57
58
    /**
59
     * Obtain and format data for png output
60
     *
61
     * @param Request $request
62
     * @param string $type
63
     * @return \Illuminate\Pagination\LengthAwarePaginator
64
     */
65
    public function png(Request $request, $type)
66
    {
67
        $class = 'App\Graphs\\' . ucfirst($type);
68
        $input = json_decode($request->{'input'});
69
        $data=new $class();
70
        $data->setType($type);
71
        $data->setInput($input);
72
        $data->setDevice($input);
73
        return $data->png($request);
74
    }
75
76
    /**
77
     * Obtain and format data for csv output
78
     *
79
     * @param Request $request
80
     * @param string $type
81
     * @return \Illuminate\Pagination\LengthAwarePaginator
82
     */
83
    public function csv(Request $request, $type)
84
    {
85
        ob_start('ob_gzhandler');
86
        $class = 'App\Graphs\\' . ucfirst($type);
87
        $input = json_decode($request->{'input'});
88
        $data=new $class();
89
        $data->setType($type);
90
        $data->setInput($input);
91
        $data->setDevice($input);
92
        return $data->csv($request);
93
    }
94
95
}
96