Issues (323)

statistic_builder/components/chartbar.blade.php (3 issues)

1
@if($command=='layout')
2
    <div id='{{$componentID}}' class='border-box'>
3
4
        <div class="panel panel-default">
5
            <div class="panel-heading">
6
                [name]
7
            </div>
8
            <div class="panel-body">
9
                [sql]
10
            </div>
11
        </div>
12
13
        <div class='action pull-right'>
14
            <a href='javascript:void(0)' data-componentid='{{$componentID}}' data-name='Panel Area' class='btn-edit-component'><i class='fa fa-pencil'></i></a>
15
            &nbsp;
16
            <a href='javascript:void(0)' data-componentid='{{$componentID}}' class='btn-delete-component'><i class='fa fa-trash'></i></a>
17
        </div>
18
    </div>
19
@elseif($command=='configuration')
20
    <form method='post'>
21
        <input type='hidden' name='_token' value='{{csrf_token()}}'/>
22
        <input type='hidden' name='componentid' value='{{$componentID}}'/>
23
        <div class="form-group">
24
            <label>Name</label>
25
            <input class="form-control" required name='config[name]' type='text' value='{{@$config->name}}'/>
26
        </div>
27
28
        <div class="form-group">
29
            <label>SQL Query Line</label>
30
            <textarea name='config[sql]' required rows="4" class='form-control'>{{@$config->sql}}</textarea>
31
            <div class="block-help">
32
                Use column name 'label' as line chart label. Use name 'value' as value of line chart. Sparate with ; each sql line. Use [SESSION_NAME] to use
33
                alias session.
34
            </div>
35
        </div>
36
37
        <div class="form-group">
38
            <label>Bar Area Name</label>
39
            <input class="form-control" required name='config[area_name]' type='text' value='{{@$config->area_name}}'/>
40
            <div class="block-help">You can naming each line area. Write name sparate with ;</div>
41
        </div>
42
43
        <div class="form-group">
44
            <label>Goals Value</label>
45
            <input class="form-control" name='config[goals]' type='number' value='{{@$config->goals}}'/>
46
        </div>
47
    </form>
48
@elseif($command=='showFunction')
49
50
    @if($key == 'sql')
51
        <?php
52
        $sqls = explode(';', $value);
53
        $dataPoints = array();
54
        $datax = array();
55
56
        foreach ($sqls as $i => $sql) {
57
58
            $datamerger = array();
59
60
            $sessions = Session::all();
61
            foreach ($sessions as $key => $val) {
62
                $sql = str_replace("[".$key."]", $val, $sql);
63
            }
64
65
            try {
66
                $query = DB::select(DB::raw($sql));
67
                foreach ($query as $r) {
68
                    $datax[] = $r->label;
69
                    $datamerger[] = $r->value;
70
                }
71
            } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
72
73
            }
74
75
            $dataPoints[$i] = $datamerger;
76
        }
77
78
        $datax = array_unique($datax);
79
80
        $area_name = explode(';', $config->area_name);
81
        $area_name_safe = $area_name;
82
        foreach ($area_name_safe as &$a) {
83
            $a = str_slug($a, '_');
0 ignored issues
show
Deprecated Code introduced by
The function str_slug() has been deprecated: Str::slug() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

83
            $a = /** @scrutinizer ignore-deprecated */ str_slug($a, '_');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
84
        }
85
86
        $data_result = array();
87
        foreach ($datax as $i => $d) {
88
            $dr = array();
89
            $dr['y'] = $d;
90
            foreach ($area_name as $e => $name) {
91
                $name = str_slug($name, '_');
0 ignored issues
show
Deprecated Code introduced by
The function str_slug() has been deprecated: Str::slug() should be used directly instead. Will be removed in Laravel 6.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

91
                $name = /** @scrutinizer ignore-deprecated */ str_slug($name, '_');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
92
                $dr[$name] = $dataPoints[$e][$i];
93
            }
94
            $data_result[] = $dr;
95
        }
96
97
        $data_result = json_encode($data_result);
98
        // $data_result = preg_replace('/"([a-zA-Z_]+[a-zA-Z0-9_]*)":/','$1:',$data_result);
99
100
        ?>
101
        <div id="chartContainer-{{$componentID}}" style="height: 250px;"></div>
102
103
104
        <script type="text/javascript">
105
106
            $(function () {
107
                new Morris.Bar({
108
                    element: 'chartContainer-{{$componentID}}',
109
                    data: $.parseJSON("{!! addslashes($data_result) !!}"),
110
                    xkey: 'y',
111
                    ykeys: {!! json_encode($area_name_safe) !!},
112
                    labels: {!! json_encode($area_name) !!},
113
                    resize: true,
114
                    parseTime: false,
115
                    @if($config->goals)
116
                    goals: [{{$config->goals}}],
117
                    @endif
118
                    behaveLikeLine: true,
119
                    hideHover: 'auto'
120
                });
121
            })
122
        </script>
123
124
    @else
125
126
        {!! $value !!}
127
    @endif
128
@endif