Test Failed
Push — master ( 8c47c2...3acf9f )
by Steve
12:37
created

notifications/actions/notifications/settings.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * Saves user notification settings
5
 */
6
7
$guid = get_input('guid');
8
$user = get_entity($guid);
9
10 View Code Duplication
if (!$user || !$user->canEdit()) {
1 ignored issue
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
	register_error(elgg_echo('actionnotauthorized'));
12
	forward('', '403');
13
}
14
15
$methods = elgg_get_notification_methods();
16
if (empty($methods)) {
17
	forward(REFERRER, '404');
18
}
19
20
$personal_settings = (array) get_input('personal', []);
21
foreach ($methods as $method) {
22
	$user->setNotificationSetting($method, in_array($method, $personal_settings));
23
}
24
25
$collections_by_method = [];
26
27
$collection_settings = get_input('collections');
28
if ($collection_settings !== null) {
29
	if (!empty($collection_settings)) {
30
		foreach ($collection_settings as $collection_id => $preferred_methods) {
31
			if (!is_array($preferred_methods)) {
32
				$preferred_methods = [];
33
			}
34
			foreach ($preferred_methods as $preferred_method) {
35
				$collections_by_method[$preferred_method][] = $collection_id;
36
			}
37
		}
38
	}
39
40
	foreach ($methods as $method) {
41
		$metaname = 'collections_notifications_preferences_' . $method;
42
		$user->$metaname = array_unique($collections_by_method[$method]);
43
	}
44
}
45
46
47
system_message(elgg_echo('notifications:subscriptions:success'));
48