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