1 | <?php |
||
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 | } |
||
42 | 1 | } |
|
43 | |||
44 | public function index() |
||
45 | { |
||
46 | // no need to do anything here. Just render the view. |
||
47 | } |
||
48 | |||
49 | 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 | ], |
||
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() |
|
149 | } |
||
150 |