|
1
|
|
|
<?php |
|
2
|
|
|
/* vim: set noexpandtab sw=2 ts=2 sts=2: */ |
|
3
|
|
|
namespace App\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use App\Controller\AppController; |
|
6
|
|
|
use Cake\Log\Log; |
|
7
|
|
|
use Cake\Routing\Router; |
|
8
|
|
|
use Cake\Event\Event; |
|
9
|
|
|
use Cake\ORM\TableRegistry; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Notifications controller handling notification creation and rendering |
|
13
|
|
|
* |
|
14
|
|
|
* phpMyAdmin Error reporting server |
|
15
|
|
|
* Copyright (c) phpMyAdmin project (http://www.phpmyadmin.net) |
|
16
|
|
|
* |
|
17
|
|
|
* Licensed under The MIT License |
|
18
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
|
19
|
|
|
* Redistributions of files must retain the above copyright notice. |
|
20
|
|
|
* |
|
21
|
|
|
* @copyright Copyright (c) phpMyAdmin project (http://www.phpmyadmin.net) |
|
22
|
|
|
* @package Server.Controller |
|
23
|
|
|
* @link http://www.phpmyadmin.net |
|
24
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
|
25
|
|
|
*/ |
|
26
|
|
|
/** |
|
27
|
|
|
* Notifications Controller |
|
28
|
|
|
* |
|
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
|
1 |
|
public function beforeFilter(Event $event) { |
|
39
|
1 |
|
if ($this->action != 'clean_old_notifs') { |
|
40
|
1 |
|
parent::beforeFilter($event); |
|
41
|
1 |
|
} |
|
42
|
1 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function index() |
|
45
|
|
|
{ |
|
46
|
|
|
// no need to do anything here. Just render the view. |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
public function data_tables() |
|
50
|
|
|
{ |
|
51
|
|
|
$current_developer = TableRegistry::get('Developers')-> |
|
|
|
|
|
|
52
|
|
|
findById($this->request->session()->read('Developer.id'))->all()->first(); |
|
53
|
|
|
|
|
54
|
|
|
$aColumns = [ |
|
55
|
|
|
'report_id' => 'Reports.id', |
|
56
|
|
|
'error_message' => 'Reports.error_message', |
|
57
|
|
|
'error_name' => 'Reports.error_name', |
|
58
|
|
|
'pma_version' => 'Reports.pma_version', |
|
59
|
|
|
'exception_type' => 'Reports.exception_type', |
|
60
|
|
|
'created_time' => 'Notifications.created' |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
$orderConditions = $this->OrderSearch->getOrder($aColumns); |
|
64
|
|
|
$searchConditions = $this->OrderSearch->getSearchConditions($aColumns); |
|
65
|
|
|
|
|
66
|
|
|
$aColumns['id'] = 'Notifications.id'; |
|
67
|
|
|
$params = [ |
|
68
|
|
|
'contain' => 'Reports', |
|
69
|
|
|
'fields' => $aColumns, |
|
70
|
|
|
'conditions' => [ |
|
71
|
|
|
'AND' => [ |
|
72
|
|
|
array('Notifications.developer_id ' => $current_developer['id']), |
|
73
|
|
|
$searchConditions |
|
74
|
|
|
] |
|
75
|
1 |
|
], |
|
76
|
|
|
'order' => $orderConditions |
|
77
|
|
|
]; |
|
78
|
|
|
//$current_developer = Sanitize::clean($current_developer); |
|
79
|
|
|
|
|
80
|
|
|
$pagedParams = $params; |
|
81
|
|
|
$pagedParams['limit'] = intval($this->request->query('iDisplayLength')); |
|
82
|
|
|
$pagedParams['offset'] = intval($this->request->query('iDisplayStart')); |
|
83
|
|
|
|
|
84
|
|
|
$rows = $this->Notifications->find('all', $pagedParams); |
|
85
|
|
|
//$rows = Sanitize::clean($rows); |
|
86
|
|
|
|
|
87
|
|
|
// Make the display rows array |
|
88
|
|
|
$dispRows = array(); |
|
89
|
|
|
$tmp_row = array(); |
|
90
|
|
|
foreach($rows as $row) { |
|
91
|
|
|
$tmp_row[0] = '<input type="checkbox" name="notifs[]" value="' |
|
92
|
|
|
. $row['id'] |
|
93
|
|
|
. '"/>'; |
|
94
|
|
|
$tmp_row[1] ='<a href="' |
|
95
|
|
|
. Router::url( |
|
96
|
|
|
array( |
|
97
|
|
|
'controller' => 'reports', |
|
98
|
|
|
'action' => 'view', |
|
99
|
|
|
$row['report_id'] |
|
100
|
|
|
) |
|
101
|
|
|
) |
|
102
|
|
|
. '">' |
|
103
|
|
|
. $row['report_id'] |
|
104
|
|
|
. '</a>'; |
|
105
|
|
|
$tmp_row[2] = $row['error_name']; |
|
106
|
|
|
$tmp_row[3] = $row['error_message']; |
|
107
|
|
|
$tmp_row[4] = $row['pma_version']; |
|
108
|
|
|
$tmp_row[5] = ($row['exception_type'])?('php'):('js'); |
|
109
|
|
|
$tmp_row[6] = $row['created_time']; |
|
110
|
|
|
array_push($dispRows, $tmp_row); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
$response = array( |
|
114
|
|
|
'iTotalDisplayRecords' => count($dispRows), |
|
115
|
|
|
'iTotalRecords' => $this->Notifications->find('all', $params)->count(), |
|
116
|
|
|
'sEcho' => intval($this->request->query('sEcho')), |
|
117
|
|
|
'aaData' => $dispRows |
|
118
|
|
|
); |
|
119
|
|
|
$this->autoRender = false; |
|
120
|
|
|
$this->response->body(json_encode($response)); |
|
121
|
|
|
return $this->response; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* To carry out mass actions on Notifications. |
|
126
|
|
|
* Currently it deletes them (marks them "read"). |
|
127
|
|
|
* Can be Extended for other mass operations as well. |
|
128
|
|
|
* Expects an array of Notification Ids as a POST parameter. |
|
129
|
|
|
* |
|
130
|
|
|
*/ |
|
131
|
1 |
|
public function mass_action() |
|
132
|
|
|
{ |
|
133
|
1 |
|
$msg = "Selected Notifications have been marked <i>Read</i>!"; |
|
134
|
1 |
|
$flash_class = "alert alert-success"; |
|
135
|
1 |
|
foreach($this->request->data['notifs'] as $notif_id) |
|
136
|
|
|
{ |
|
137
|
1 |
|
if(!$this->Notifications->delete($this->Notifications->get(intval($notif_id)))) { |
|
138
|
|
|
$msg = "<b>ERROR</b>: There was some problem in deleting Notification(ID:" |
|
139
|
|
|
. $notif_id |
|
140
|
|
|
. ")!"; |
|
141
|
|
|
$flash_class = "alert alert-error"; |
|
142
|
|
|
break; |
|
143
|
|
|
} |
|
144
|
1 |
|
} |
|
145
|
1 |
|
$this->Flash->default($msg, |
|
|
|
|
|
|
146
|
1 |
|
array("params" => array("class" => $flash_class))); |
|
147
|
1 |
|
$this->redirect("/notifications/"); |
|
148
|
1 |
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: