Completed
Pull Request — master (#182)
by
unknown
03:01
created

NotificationsController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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
23
use Cake\Event\Event;
24
use Cake\ORM\TableRegistry;
25
use Cake\Routing\Router;
26
27
/**
28
 * Notifications Controller.
29
 */
30
class NotificationsController extends AppController
31
{
32
    public $components = array('RequestHandler', 'OrderSearch');
33
34
    public $helpers = array('Html', 'Form', 'Reports');
35
36
    public $uses = array('Notification', 'Developer', 'Report');
37
38 3
    public function beforeFilter(Event $event)
39
    {
40 3
        if ($this->action != 'clean_old_notifs') {
41 3
            parent::beforeFilter($event);
42
        }
43 3
    }
44
45 1
    public function index()
46
    {
47
        // no need to do anything here. Just render the view.
48 1
    }
49
50 1
    public function data_tables()
51
    {
52 1
        $current_developer = TableRegistry::get('Developers')->
0 ignored issues
show
Deprecated Code introduced by
The method Cake\ORM\TableRegistry::get() has been deprecated with message: 3.6.0 Use \Cake\ORM\Locator\TableLocator::get() instead.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
53 1
                    findById($this->request->session()->read('Developer.id'))->all()->first();
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Http\ServerRequest::session() has been deprecated with message: 3.5.0 Use getSession() instead. The setter part will be removed.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
54
55
        $aColumns = array(
56 1
            'report_id' => 'Reports.id',
57
            'error_message' => 'Reports.error_message',
58
            'error_name' => 'Reports.error_name',
59
            'pma_version' => 'Reports.pma_version',
60
            'exception_type' => 'Reports.exception_type',
61
            'created_time' => 'Notifications.created',
62
        );
63
64 1
        $orderConditions = $this->OrderSearch->getOrder($aColumns);
65 1
        $searchConditions = $this->OrderSearch->getSearchConditions($aColumns);
66
67 1
        $aColumns['id'] = 'Notifications.id';
68
        $params = array(
69 1
            'contain' => 'Reports',
70 1
            'fields' => $aColumns,
71
            'conditions' => array(
72
                'AND' => array(
73 1
                    array('Notifications.developer_id ' => $current_developer['id']),
74 1
                    $searchConditions,
75
                ),
76
            ),
77 1
            'order' => $orderConditions,
78
        );
79
80 1
        $pagedParams = $params;
81 1
        $pagedParams['limit'] = intval($this->request->query('iDisplayLength'));
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Http\ServerRequest::query() has been deprecated with message: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
82 1
        $pagedParams['offset'] = intval($this->request->query('iDisplayStart'));
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Http\ServerRequest::query() has been deprecated with message: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
83
84 1
        $rows = $this->Notifications->find('all', $pagedParams);
85 1
        $totalFiltered = $this->Notifications->find(
86 1
            'all',
87
            array(
88
                'conditions' => array(
89 1
                    'developer_id' => $current_developer['id']
90
                )
91
            )
92 1
        )->count();
93
94
        // Make the display rows array
95 1
        $dispRows = array();
96 1
        $tmp_row = array();
97 1
        foreach ($rows as $row) {
98 1
            $tmp_row[0] = '<input type="checkbox" name="notifs[]" value="'
99 1
                . $row['id']
100 1
                . '"/>';
101 1
            $tmp_row[1] = '<a href="'
102 1
                . Router::url(
103
                    array(
104 1
                        'controller' => 'reports',
105 1
                        'action' => 'view',
106 1
                        $row['report_id'],
107
                        )
108
                    )
109 1
                . '">'
110 1
                . $row['report_id']
111 1
                . '</a>';
112 1
            $tmp_row[2] = $row['error_name'];
113 1
            $tmp_row[3] = $row['error_message'];
114 1
            $tmp_row[4] = $row['pma_version'];
115 1
            $tmp_row[5] = ($row['exception_type']) ? ('php') : ('js');
116 1
            $tmp_row[6] = $row['created_time'];
117 1
            array_push($dispRows, $tmp_row);
118
        }
119
120
        $response = array(
121 1
            'iTotalDisplayRecords' => $totalFiltered,
122 1
            'iTotalRecords' => $this->Notifications->find('all', $params)->count(),
123 1
            'sEcho' => intval($this->request->query('sEcho')),
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Http\ServerRequest::query() has been deprecated with message: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
124 1
            'aaData' => $dispRows,
125
        );
126 1
        $this->autoRender = false;
127 1
        $this->response->body(json_encode($response));
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Http\Response::body() has been deprecated with message: 3.4.0 Mutable response methods are deprecated. Use `withBody()`/`withStringBody()` and `getBody()` instead.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
128
129 1
        return $this->response;
130
    }
131
132
    /**
133
     * To carry out mass actions on Notifications.
134
     * Currently it deletes them (marks them "read").
135
     * Can be Extended for other mass operations as well.
136
     * Expects an array of Notification Ids as a POST parameter.
137
     */
138 1
    public function mass_action()
139
    {
140 1
        $msg = 'Selected Notifications have been marked \'Read\'!';
141 1
        $flash_class = 'alert alert-success';
142
143 1
        if ($this->request->getData('mark_all')) {
144
145
            // Delete all notifications for this Developer
146 1
            $this->Notifications->deleteAll(
147 1
                ['developer_id' => $this->request->session()->read('Developer.id')]
0 ignored issues
show
Deprecated Code introduced by
The method Cake\Http\ServerRequest::session() has been deprecated with message: 3.5.0 Use getSession() instead. The setter part will be removed.

This method 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 method will be removed from the class and what other method or class to use instead.

Loading history...
148
            );
149
150 1
            $msg = 'All your notifications have been marked \'Read\'';
151
        } else {
152 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 with message: 3.4.0 This public property will be removed in 4.0.0. Use getData() instead.

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...
153 1
                if (!$this->Notifications->delete($this->Notifications->get(intval($notif_id)))) {
154
                    $msg = '<b>ERROR</b>: There was some problem in deleting Notification(ID:'
155
                        . $notif_id
156
                        . ')!';
157
                    $flash_class = 'alert alert-error';
158
                    break;
159
                }
160
            }
161
        }
162 1
        $this->Flash->default($msg,
163 1
            array('params' => array('class' => $flash_class)));
164 1
        $this->redirect('/notifications/');
165 1
    }
166
}
167