ChartController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 69
c 2
b 0
f 0
dl 0
loc 116
rs 10
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A bubble() 0 10 1
A radar() 0 11 1
A bar() 0 10 1
A polar() 0 7 1
A line() 0 10 1
A doughnut() 0 7 1
A getDB() 0 8 1
A changedb() 0 12 2
A pie() 0 18 1
1
<?php
2
3
namespace App\Http\Controllers\Dashboard;
4
5
use App\Person;
6
use App\Traits\ConnectionTrait;
7
use Illuminate\Http\Request;
8
use Illuminate\Routing\Controller;
9
use Illuminate\Support\Facades\Auth;
10
use LaravelEnso\Charts\Factories\Bar;
11
use LaravelEnso\Charts\Factories\Bubble;
12
use LaravelEnso\Charts\Factories\Doughnut;
13
use LaravelEnso\Charts\Factories\Line;
14
use LaravelEnso\Charts\Factories\Pie;
15
use LaravelEnso\Charts\Factories\Polar;
16
use LaravelEnso\Charts\Factories\Radar;
17
use LaravelEnso\Multitenancy\Enums\Connections;
18
use LaravelEnso\Multitenancy\Services\Tenant;
19
20
class ChartController extends Controller
21
{
22
    use ConnectionTrait;
23
    // use SystemConnection;
24
25
    public function line()
26
    {
27
        return (new Line())
28
            ->title('Income')
29
            ->labels(['January', 'February', 'March', 'April', 'May', 'June', 'July'])
30
            ->datasets([
31
                'Sales' => [65, 59, 80, 81, 26, 25, 10],
32
                'Revenue' => [15, 29, 60, 31, 56, 65, 44],
33
            ])->fill()
34
            ->get();
35
    }
36
37
    public function bar()
38
    {
39
        return (new Bar())
40
            ->title('Sales')
41
            ->labels(['Ian', 'Feb', 'Mar'])
42
            ->datasets([
43
                'Sales' => [1233, 1231, 3123],
44
                'Spendings' => [1250, 1730, 5300],
45
                'Profit' => [1250 - 1233, 1730 - 1231, 5300 - 3123],
46
            ])->get();
47
    }
48
49
    public function pie()
50
    {
51
        // \DB::table('some')->get();
52
        $male = Person::where('sex', 'M')->get()->count();
53
        $female = Person::where('sex', 'F')->get()->count();
54
        $unknown = Person::whereNull('sex')->get()->count();
55
        $sv = \Session::get('db', env('DB_DATABASE'));
0 ignored issues
show
Unused Code introduced by
The assignment to $sv is dead and can be removed.
Loading history...
56
        $user = Auth::user();
57
        $companies = $user->person->company();
0 ignored issues
show
Bug introduced by
Accessing person on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
Unused Code introduced by
The assignment to $companies is dead and can be removed.
Loading history...
58
        $current_db = \Session::get('companyId');
0 ignored issues
show
Unused Code introduced by
The assignment to $current_db is dead and can be removed.
Loading history...
59
60
        // return $current_db;
61
        // return $sv;
62
        return (new Pie())
63
            ->title('Genders')
64
            ->labels(['Male', 'Female', 'Unknown'])
65
            ->datasets([$male, $female, $unknown])
66
            ->get();
67
    }
68
69
    public function doughnut()
70
    {
71
        return (new Doughnut())
72
            ->title('Colors Two')
73
            ->labels(['Green', 'Red', 'Azzure'])
74
            ->datasets([400, 50, 100])
75
            ->get();
76
    }
77
78
    public function radar()
79
    {
80
        return (new Radar())
81
            ->title('Habits')
82
            ->labels([
83
                'Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running',
84
            ])
85
            ->datasets([
86
                '2005' => [65, 59, 90, 81, 56, 55, 40],
87
                '2006' => [28, 48, 40, 19, 96, 27, 100],
88
            ])->get();
89
    }
90
91
    public function polar()
92
    {
93
        return (new Polar())
94
            ->title('Again Colors')
95
            ->labels(['Green', 'Red', 'Azzure', 'Portocaliu', 'Purple'])
96
            ->datasets([11, 16, 7, 14, 14])
97
            ->get();
98
    }
99
100
    public function bubble()
101
    {
102
        return (new Bubble())
103
            ->title('City Population by Age')
104
            ->labels(['Geneva', 'Besel', 'Bucharest'])
105
            ->datasets([
106
                0 => [[1010, 59, 4800], [2011, 55, 1800], [1012, 45, 2000], [413, 58, 4400]],
107
                1 => [[2010, 48, 1700], [1211, 67, 1200], [2012, 96, 1233], [813, 35, 3000]],
108
                2 => [[1510, 44, 2000], [811, 62, 1500], [212, 55, 1299], [1213, 39, 4000]],
109
            ])->get();
110
    }
111
112
    // change database to use
113
    public function changedb(Request $request)
114
    {
115
        $company_id = $request->get('comid');
116
        if (! empty($company_id)) {
117
            $db = Connections::Tenant.$company_id;
118
            $this->setConnection(Connections::Tenant, $db);
119
        } else {
120
            $this->setConnection('mysql');
121
        }
122
        $conn = $this->getConnection();
123
124
        return $conn;
125
    }
126
127
    // get companies of user.
128
    public function getDB()
129
    {
130
        $user = Auth::user();
131
        $companies = $user->person->companies()->get();
0 ignored issues
show
Bug introduced by
Accessing person on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
132
        $ret = [];
133
        $ret['company'] = $companies;
134
135
        return $ret;
136
    }
137
}
138