1
|
|
|
<?php |
2
|
|
|
/* vim: set noexpandtab sw=2 ts=2 sts=2: */ |
3
|
|
|
namespace App\Model\Table; |
4
|
|
|
|
5
|
|
|
use Cake\ORM\TableRegistry; |
6
|
|
|
use Cake\Model\Model; |
7
|
|
|
use Cake\ORM\Table; |
8
|
|
|
/** |
9
|
|
|
* Notification model representing a notification for new report. |
10
|
|
|
* |
11
|
|
|
* phpMyAdmin Error reporting server |
12
|
|
|
* Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
13
|
|
|
* |
14
|
|
|
* Licensed under The MIT License |
15
|
|
|
* For full copyright and license information, please see the LICENSE.txt |
16
|
|
|
* Redistributions of files must retain the above copyright notice. |
17
|
|
|
* |
18
|
|
|
* @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/) |
19
|
|
|
* @package Server.Model |
20
|
|
|
* @link https://www.phpmyadmin.net/ |
21
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Notification Model |
26
|
|
|
* |
27
|
|
|
* @property Developer $Developer |
28
|
|
|
* @property Report $Report |
29
|
|
|
*/ |
30
|
|
|
class NotificationsTable extends Table { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Validation rules |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
public $validate = array( |
38
|
|
|
'developer_id' => array( |
39
|
|
|
'numeric' => array( |
40
|
|
|
'rule' => array('numeric'), |
41
|
|
|
'allowEmpty' => false, |
42
|
|
|
'required' => true, |
43
|
|
|
), |
44
|
|
|
), |
45
|
|
|
'report_id' => array( |
46
|
|
|
'numeric' => array( |
47
|
|
|
'rule' => array('numeric'), |
48
|
|
|
'allowEmpty' => false, |
49
|
|
|
'required' => true, |
50
|
|
|
), |
51
|
|
|
), |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
//The Associations below have been created with all possible keys, those that are not needed can be removed |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* belongsTo associations |
58
|
|
|
* |
59
|
|
|
* @var array |
60
|
|
|
*/ |
61
|
9 |
|
public function initialize(array $config) |
62
|
|
|
{ |
63
|
9 |
|
$this->belongsTo('Reports', [ |
64
|
9 |
|
'className' => 'Reports', |
65
|
|
|
'foreignKey' => 'report_id' |
66
|
|
|
]); |
67
|
9 |
|
} |
68
|
|
|
/** |
69
|
|
|
* To Add Multiple Notifications for New report. |
70
|
|
|
* |
71
|
|
|
* @param integer $report_id id of the new Report |
72
|
|
|
* |
73
|
|
|
* @return Boolean value. True on success. False on any type of failure. |
74
|
|
|
*/ |
75
|
3 |
|
public static function addNotifications($report_id) |
76
|
|
|
{ |
77
|
3 |
|
if (!is_int($report_id)) { |
78
|
|
|
throw new InvalidArgumentException('Invalid Argument "$report_id"! Integer Expected.'); |
79
|
|
|
} |
80
|
3 |
|
$devs = TableRegistry::get('Developers')->find('all'); |
81
|
3 |
|
$notoficationTable = TableRegistry::get('Notifications'); |
82
|
3 |
|
$res = true; |
83
|
3 |
|
foreach ($devs as $dev) { |
84
|
3 |
|
$notification = $notoficationTable->newEntity(); |
85
|
3 |
|
$notification->developer_id = $dev['id']; |
|
|
|
|
86
|
3 |
|
$notification->report_id = $report_id; |
|
|
|
|
87
|
3 |
|
$notification->created = date('Y-m-d H:i:s', time()); |
|
|
|
|
88
|
3 |
|
$notification->modified = date('Y-m-d H:i:s', time()); |
|
|
|
|
89
|
3 |
|
$res = $notoficationTable->save($notification); |
90
|
|
|
} |
91
|
3 |
|
return($res); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: