-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.php
More file actions
114 lines (96 loc) · 3.12 KB
/
Copy pathModule.php
File metadata and controls
114 lines (96 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Alt Notification
* @link https://www.cuzy.app
* @license https://www.cuzy.app/cuzy-license
* @author [Marc FARRE](https://marc.fun)
*/
namespace humhub\modules\altNotification;
use humhub\modules\altNotification\models\Configuration;
use Yii;
use yii\helpers\Url;
use yii\web\NotFoundHttpException;
/**
*
* @property-read mixed $configUrl
* @property-read Configuration $configuration
* @property-read string[] $notifications
*/
class Module extends \humhub\components\Module
{
/**
* @var string defines the icon
*/
public $icon = 'bell';
private ?Configuration $_configuration = null;
public function getConfiguration(): Configuration
{
if ($this->_configuration === null) {
$this->_configuration = new Configuration(['settingsManager' => $this->settings]);
$this->_configuration->loadBySettings();
}
return $this->_configuration;
}
/**
* @inheritdoc
*/
public function getConfigUrl()
{
return Url::to(['/alt-notification/config']);
}
/**
* @inerhitdoc
*/
public function getName()
{
return Yii::t('AltNotificationModule.base', 'Alternative Notifications');
}
/**
* @inerhitdoc
*/
public function getDescription()
{
return Yii::t('AltNotificationModule.base', 'Replaces the "{fieldName}" Notification Settings with a new behavior.', [
'fieldName' => Yii::t('NotificationModule.base', 'Receive \'New Content\' Notifications for the following spaces'),
]);
}
public function enable()
{
if (parent::enable() === false) {
return false;
}
// Copy all Spaces from **Admin Settings** to **Module Settings**.
/** @var \humhub\modules\notification\Module $notificationModule */
$notificationModule = Yii::$app->getModule('notification');
$notificationSettings = $notificationModule->settings;
$spaceGuis = (array)$notificationSettings->getSerialized('sendNotificationSpaces');
$notificationSettings->setSerialized('sendNotificationSpaces', []);
$this->configuration->newContentNotifSpaceGuids = $spaceGuis;
$this->configuration->save();
return true;
}
public function disable()
{
$spaceGuis = $this->configuration->newContentNotifSpaceGuids;
if (parent::disable() === false) {
return false;
}
// Copy all Spaces from **Module Settings** to **Admin Settings**.
/** @var \humhub\modules\notification\Module $notificationModule */
$notificationModule = Yii::$app->getModule('notification');
$notificationModule->settings->setSerialized('sendNotificationSpaces', $spaceGuis);
return true;
}
/**
* @throws NotFoundHttpException
*/
public static function getInstance(): static
{
/** @var ?static $module */
$module = Yii::$app->getModule('alt-notification');
if (!$module?->isEnabled) {
throw new NotFoundHttpException('Alternate Notification module not enabled');
}
return $module;
}
}