Completed
Push — master ( bc825a...1aba9a )
by William
06:03
created

NotificationsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
/**
5
 * Notifications controller handling notification creation and rendering.
6
 *
7
 * phpMyAdmin Error reporting server
8
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
16
 *
17
 * @see      https://www.phpmyadmin.net/
18
 */
19
20
namespace App\Controller;
21
22
use Cake\Event\Event;
23
use Cake\ORM\TableRegistry;
24
use Cake\Routing\Router;
25
26
/**
27
 * Notifications Controller.
28
 */
29
class NotificationsController extends AppController
30
{
31
    public $components = [
32
        'RequestHandler',
33
        'OrderSearch',
34
    ];
35
36
    public $helpers = [
37
        'Html',
38
        'Form',
39
        'Reports',
40
    ];
41
42
    public $uses = [
43
        'Notification',
44
        'Developer',
45
        'Report',
46
    ];
47
48 3
    public function beforeFilter(Event $event)
49
    {
50 3
        if ($this->request->getParam('action') != 'clean_old_notifs') {
51 3
            parent::beforeFilter($event);
52
        }
53 3
    }
54
55 1
    public function index()
56
    {
57
        // no need to do anything here. Just render the view.
58 1
    }
59
60 1
    public function data_tables()
61
    {
62 1
        $current_developer = TableRegistry::get('Developers')->
0 ignored issues
show
Deprecated Code introduced by
The function Cake\ORM\TableRegistry::get() has been deprecated: 3.6.0 Use \Cake\ORM\Locator\TableLocator::get() instead. ( Ignorable by Annotation )

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

62
        $current_developer = /** @scrutinizer ignore-deprecated */ TableRegistry::get('Developers')->

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...
63 1
                    findById($this->request->session()->read('Developer.id'))->all()->first();
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::session() has been deprecated: 3.5.0 Use getSession() instead. The setter part will be removed. ( Ignorable by Annotation )

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

63
                    findById(/** @scrutinizer ignore-deprecated */ $this->request->session()->read('Developer.id'))->all()->first();

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...
64
65
        $aColumns = [
66 1
            'report_id' => 'Reports.id',
67
            'error_message' => 'Reports.error_message',
68
            'error_name' => 'Reports.error_name',
69
            'pma_version' => 'Reports.pma_version',
70
            'exception_type' => 'Reports.exception_type',
71
            'created_time' => 'Notifications.created',
72
        ];
73
74 1
        $orderConditions = $this->OrderSearch->getOrder($aColumns);
0 ignored issues
show
Bug Best Practice introduced by
The property OrderSearch does not exist on App\Controller\NotificationsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
75 1
        $searchConditions = $this->OrderSearch->getSearchConditions($aColumns);
76
77 1
        $aColumns['id'] = 'Notifications.id';
78
        $params = [
79 1
            'contain' => 'Reports',
80 1
            'fields' => $aColumns,
81
            'conditions' => [
82
                'AND' => [
83 1
                    ['Notifications.developer_id ' => $current_developer['id']],
84 1
                    $searchConditions,
85
                ],
86
            ],
87 1
            'order' => $orderConditions,
88
        ];
89
90 1
        $pagedParams = $params;
91 1
        $pagedParams['limit'] = intval($this->request->query('iDisplayLength'));
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

91
        $pagedParams['limit'] = intval(/** @scrutinizer ignore-deprecated */ $this->request->query('iDisplayLength'));

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 1
        $pagedParams['offset'] = intval($this->request->query('iDisplayStart'));
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

92
        $pagedParams['offset'] = intval(/** @scrutinizer ignore-deprecated */ $this->request->query('iDisplayStart'));

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...
93
94 1
        $rows = $this->Notifications->find('all', $pagedParams);
0 ignored issues
show
Bug Best Practice introduced by
The property Notifications does not exist on App\Controller\NotificationsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
95 1
        $totalFiltered = $this->Notifications->find(
96 1
            'all',
97
            [
98
                'conditions' => [
99 1
                    'developer_id' => $current_developer['id'],
100
                ],
101
            ]
102 1
        )->count();
103
104
        // Make the display rows array
105 1
        $dispRows = [];
106 1
        $tmp_row = [];
107 1
        foreach ($rows as $row) {
108 1
            $tmp_row[0] = '<input type="checkbox" name="notifs[]" value="'
109 1
                . $row['id']
110 1
                . '"/>';
111 1
            $tmp_row[1] = '<a href="'
112 1
                . Router::url(
113
                    [
114 1
                        'controller' => 'reports',
115 1
                        'action' => 'view',
116 1
                        $row['report_id'],
117
                    ]
118
                )
119 1
                . '">'
120 1
                . $row['report_id']
121 1
                . '</a>';
122 1
            $tmp_row[2] = $row['error_name'];
123 1
            $tmp_row[3] = $row['error_message'];
124 1
            $tmp_row[4] = $row['pma_version'];
125 1
            $tmp_row[5] = ($row['exception_type']) ? ('php') : ('js');
126 1
            $tmp_row[6] = $row['created_time'];
127 1
            array_push($dispRows, $tmp_row);
128
        }
129
130
        $response = [
131 1
            'iTotalDisplayRecords' => $totalFiltered,
132 1
            'iTotalRecords' => $this->Notifications->find('all', $params)->count(),
133 1
            'sEcho' => intval($this->request->query('sEcho')),
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

133
            'sEcho' => intval(/** @scrutinizer ignore-deprecated */ $this->request->query('sEcho')),

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...
134 1
            'aaData' => $dispRows,
135
        ];
136 1
        $this->autoRender = false;
137 1
        $this->response->body(json_encode($response));
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\Response::body() has been deprecated: 3.4.0 Mutable response methods are deprecated. Use `withBody()`/`withStringBody()` and `getBody()` instead. ( Ignorable by Annotation )

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

137
        /** @scrutinizer ignore-deprecated */ $this->response->body(json_encode($response));

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...
138
139 1
        return $this->response;
140
    }
141
142
    /**
143
     * To carry out mass actions on Notifications.
144
     * Currently it deletes them (marks them "read").
145
     * Can be Extended for other mass operations as well.
146
     * Expects an array of Notification Ids as a POST parameter.
147
     * @return void
148
     */
149 1
    public function mass_action()
150
    {
151 1
        $msg = 'Selected Notifications have been marked \'Read\'!';
152 1
        $flash_class = 'alert alert-success';
153
154 1
        if ($this->request->getData('mark_all')) {
155
            // Delete all notifications for this Developer
156 1
            $this->Notifications->deleteAll(
0 ignored issues
show
Bug Best Practice introduced by
The property Notifications does not exist on App\Controller\NotificationsController. Since you implemented __get, consider adding a @property annotation.
Loading history...
157 1
                ['developer_id' => $this->request->session()->read('Developer.id')]
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::session() has been deprecated: 3.5.0 Use getSession() instead. The setter part will be removed. ( Ignorable by Annotation )

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

157
                ['developer_id' => /** @scrutinizer ignore-deprecated */ $this->request->session()->read('Developer.id')]

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...
158
            );
159
160 1
            $msg = 'All your notifications have been marked \'Read\'';
161
        } else {
162 1
            foreach ($this->request->data['notifs'] as $notif_id) {
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Http\ServerRequest::$data has been deprecated: 3.4.0 This public property will be removed in 4.0.0. Use getData() instead. ( Ignorable by Annotation )

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

162
            foreach (/** @scrutinizer ignore-deprecated */ $this->request->data['notifs'] as $notif_id) {

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

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

Loading history...
163 1
                if (! $this->Notifications->delete($this->Notifications->get(intval($notif_id)))) {
164
                    $msg = '<b>ERROR</b>: There was some problem in deleting Notification(ID:'
165
                        . $notif_id
166
                        . ')!';
167
                    $flash_class = 'alert alert-error';
168 1
                    break;
169
                }
170
            }
171
        }
172 1
        $this->Flash->default(
173 1
            $msg,
174 1
            ['params' => ['class' => $flash_class]]
175
        );
176 1
        $this->redirect('/notifications/');
177 1
    }
178
}
179