1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* vim: set expandtab sw=4 ts=4 sts=4: */ |
4
|
|
|
/** |
5
|
|
|
* Notification model representing a notification for new report. |
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\Model\Table; |
21
|
|
|
|
22
|
|
|
use Cake\Model\Model; |
23
|
|
|
use Cake\ORM\Table; |
24
|
|
|
use Cake\ORM\TableRegistry; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Notification Model. |
28
|
|
|
* |
29
|
|
|
* @property Developer $Developer |
30
|
|
|
* @property Report $Report |
31
|
|
|
*/ |
32
|
|
|
class NotificationsTable extends Table |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Validation rules. |
36
|
|
|
* |
37
|
|
|
* @var array |
38
|
|
|
*/ |
39
|
|
|
public $validate = array( |
40
|
|
|
'developer_id' => array( |
41
|
|
|
'numeric' => array( |
42
|
|
|
'rule' => array('numeric'), |
43
|
|
|
'allowEmpty' => false, |
44
|
|
|
'required' => true, |
45
|
|
|
), |
46
|
|
|
), |
47
|
|
|
'report_id' => array( |
48
|
|
|
'numeric' => array( |
49
|
|
|
'rule' => array('numeric'), |
50
|
|
|
'allowEmpty' => false, |
51
|
|
|
'required' => true, |
52
|
|
|
), |
53
|
|
|
), |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* The Associations below have been created with all possible keys, |
58
|
|
|
* those that are not needed can be removed. |
59
|
|
|
*/ |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* belongsTo associations. |
63
|
|
|
* |
64
|
|
|
* @var array |
65
|
|
|
*/ |
66
|
9 |
|
public function initialize(array $config) |
67
|
|
|
{ |
68
|
9 |
|
$this->belongsTo('Reports', array( |
69
|
9 |
|
'className' => 'Reports', |
70
|
|
|
'foreignKey' => 'report_id', |
71
|
|
|
)); |
72
|
9 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* To Add Multiple Notifications for New report. |
76
|
|
|
* |
77
|
|
|
* @param int $report_id id of the new Report |
78
|
|
|
* |
79
|
|
|
* @return bool value. True on success. False on any type of failure. |
80
|
|
|
*/ |
81
|
3 |
|
public static function addNotifications($report_id) |
82
|
|
|
{ |
83
|
3 |
|
if (!is_int($report_id)) { |
84
|
|
|
throw new InvalidArgumentException('Invalid Argument "$report_id"! Integer Expected.'); |
85
|
|
|
} |
86
|
3 |
|
$devs = TableRegistry::get('Developers')->find('all'); |
87
|
3 |
|
$notoficationTable = TableRegistry::get('Notifications'); |
88
|
3 |
|
$res = true; |
89
|
3 |
|
foreach ($devs as $dev) { |
90
|
3 |
|
$notification = $notoficationTable->newEntity(); |
91
|
3 |
|
$notification->developer_id = $dev['id']; |
|
|
|
|
92
|
3 |
|
$notification->report_id = $report_id; |
|
|
|
|
93
|
3 |
|
$notification->created = date('Y-m-d H:i:s', time()); |
|
|
|
|
94
|
3 |
|
$notification->modified = date('Y-m-d H:i:s', time()); |
|
|
|
|
95
|
3 |
|
$res = $notoficationTable->save($notification); |
96
|
|
|
} |
97
|
|
|
|
98
|
3 |
|
return $res; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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: