Completed
Pull Request — master (#114)
by Deven
15:41
created

NotificationsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 31.03%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 9
c 4
b 1
f 0
lcom 1
cbo 6
dl 0
loc 95
ccs 18
cts 58
cp 0.3103
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A index() 0 4 1
A beforeFilter() 0 5 2
A data_tables() 0 49 3
A mass_action() 0 18 3
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');
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')->
0 ignored issues
show
Documentation Bug introduced by
The method findById does not exist on object<Cake\ORM\Table>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and 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 __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
52
					findById($this->request->session()->read('Developer.id'))->all()->first();
53
		//$current_developer = Sanitize::clean($current_developer
54
		$params = ['conditions' => ['Notifications.developer_id = ' . $current_developer['id']]];
55
56
		$pagedParams = $params;
57
		$pagedParams['limit'] = intval($this->request->query('iDisplayLength'));
58
		$pagedParams['offset'] = intval($this->request->query('iDisplayStart'));
59
60
		$rows = $this->Notifications->find('all', $pagedParams)->contain(['Reports']);
61
		//$rows = Sanitize::clean($rows);
62
63
		// Make the display rows array
64
		$dispRows = array();
65
		$tmp_row = array();
66
		foreach($rows as $row) {
67
			$tmp_row[0] = '<input type="checkbox" name="notifs[]" value="'
68
				. $row['id']
69
				. '"/>';
70
			$tmp_row[1] ='<a href="'
71
				. Router::url(
72
					array(
73
						'controller' => 'reports',
74
						'action' => 'view',
75 1
						$row['report_id']
76
						)
77
					)
78
				. '">'
79
				. $row['report_id']
80
				. '</a>';
81
			$tmp_row[2] = $row['report']['error_name'];
82
			$tmp_row[3] = $row['report']['error_message'];
83
			$tmp_row[4] = $row['report']['pma_version'];
84
			$tmp_row[5] = ($row['report']['exception_type'])?('php'):('js');
85
			$tmp_row[6] = $row['created'];
86 1
			array_push($dispRows, $tmp_row);
87
		}
88
		$response = array(
89
			'iTotalDisplayRecords' => count($dispRows),
90
			'iTotalRecords' => $this->Notifications->find('all', $params)->count(),
91
			'sEcho' => intval($this->request->query('sEcho')),
92
			'aaData' => $dispRows
93
		);
94
		$this->autoRender = false;
95
        $this->response->body(json_encode($response));
96
        return $this->response;
97
     }
98
99
	/**
100
	 * To carry out mass actions on Notifications.
101
	 * Currently it deletes them (marks them "read").
102
	 * Can be Extended for other mass operations as well.
103
	 * Expects an array of Notification Ids as a POST parameter.
104
	 *
105
	 */
106 1
	public function mass_action()
107
	{
108 1
		$msg = "Selected Notifications have been marked <i>Read</i>!";
109 1
		$flash_class = "alert alert-success";
110 1
		foreach($this->request->data['notifs'] as $notif_id)
111
		{
112 1
			if(!$this->Notifications->delete($this->Notifications->get(intval($notif_id)))) {
113
				$msg = "<b>ERROR</b>: There was some problem in deleting Notification(ID:"
114
					. $notif_id
115
					. ")!";
116
				$flash_class = "alert alert-error";
117
				break;
118
			}
119 1
		}
120 1
		$this->Flash->default($msg,
0 ignored issues
show
Documentation Bug introduced by
The method default does not exist on object<Cake\Controller\Component\FlashComponent>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and 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 __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
121 1
			array("params" => array("class" => $flash_class)));
122 1
		$this->redirect("/notifications/");
123 1
	}
124
}
125