diff --git a/src/Alerts/Base.php b/src/Alerts/Base.php
index 2a40346..804885f 100644
--- a/src/Alerts/Base.php
+++ b/src/Alerts/Base.php
@@ -65,18 +65,25 @@ abstract class Base
protected $cacheKey = 'notifications';
/**
- * The required method to handle the Alert.
- *
- * @return mixed
+ * Base constructor.
*/
- abstract protected function getData(): Collection;
+ public function __construct()
+ {
+
+ $this->data = $this->getData();
+ $this->name = $this->getName();
+ $this->type = $this->getType();
+
+ $this->notifier = $this->getNotifier();
+
+ }
/**
- * The type of notification.
+ * The required method to handle the Alert.
*
- * @return string
+ * @return mixed
*/
- abstract protected function getType(): string;
+ abstract protected function getData(): Collection;
/**
* The name of the alert. This is also the name
@@ -87,26 +94,11 @@ abstract protected function getType(): string;
abstract protected function getName(): string;
/**
- * Fields in a collection row that make the alert
- * unique.
+ * The type of notification.
*
- * @return array
- */
- abstract protected function getUniqueFields(): array;
-
- /**
- * Base constructor.
+ * @return string
*/
- public function __construct()
- {
-
- $this->data = $this->getData();
- $this->name = $this->getName();
- $this->type = $this->getType();
-
- $this->notifier = $this->getNotifier();
-
- }
+ abstract protected function getType(): string;
/**
* Return the full class of the notifier from the config.
@@ -154,6 +146,57 @@ public function handle()
}
+ /**
+ * @param $data
+ *
+ * @return bool
+ */
+ public function isOldNotification($data)
+ {
+
+ $hash = $this->getDataHash($data);
+
+ if (cache($this->cacheKey . $hash))
+ return true;
+
+ // Check the database.
+ $in_db = NotificationHistory::whereHash($hash)
+ ->first();
+
+ // If its in the db, add it to the cache
+ if ($in_db) {
+
+ Cache::forever($this->cacheKey . $hash, true);
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * @param $data
+ *
+ * @return string
+ */
+ public function getDataHash($data)
+ {
+
+ $hashable = collect($data)
+ ->only($this->getUniqueFields())
+ ->implode(',');
+
+ return md5($this->type . $this->name . $hashable);
+ }
+
+ /**
+ * Fields in a collection row that make the alert
+ * unique.
+ *
+ * @return array
+ */
+ abstract protected function getUniqueFields(): array;
+
/**
* @return \Illuminate\Support\Collection
*/
@@ -219,49 +262,6 @@ public function affiliationOk($group, $data)
}
- /**
- * @param $data
- *
- * @return string
- */
- public function getDataHash($data)
- {
-
- $hashable = collect($data)
- ->only($this->getUniqueFields())
- ->implode(',');
-
- return md5($this->type . $this->name . $hashable);
- }
-
- /**
- * @param $data
- *
- * @return bool
- */
- public function isOldNotification($data)
- {
-
- $hash = $this->getDataHash($data);
-
- if (cache($this->cacheKey . $hash))
- return true;
-
- // Check the database.
- $in_db = NotificationHistory::whereHash($hash)
- ->first();
-
- // If its in the db, add it to the cache
- if ($in_db) {
-
- Cache::forever($this->cacheKey . $hash, true);
-
- return true;
- }
-
- return false;
- }
-
/**
* @param $data
*/
diff --git a/src/Alerts/Char/NewMailMessage.php b/src/Alerts/Char/NewMailMessage.php
index 6c8ed22..5c6f267 100644
--- a/src/Alerts/Char/NewMailMessage.php
+++ b/src/Alerts/Char/NewMailMessage.php
@@ -29,29 +29,29 @@ class NewMailMessage extends Base
{
/**
- * The required method to handle the Alert.
+ * The field to use from the data when trying
+ * to infer an affiliation.
*
- * @return mixed
+ * @return string
*/
- protected function getData(): Collection
+ public function getAffiliationField()
{
- return MailMessage::with('body')
- ->where('sentDate', '>', carbon('now')->subMonth())
- ->get();
-
+ return 'characterID';
}
/**
- * The field to use from the data when trying
- * to infer an affiliation.
+ * The required method to handle the Alert.
*
- * @return string
+ * @return mixed
*/
- public function getAffiliationField()
+ protected function getData(): Collection
{
- return 'characterID';
+ return MailMessage::with('body')
+ ->where('sentDate', '>', carbon('now')->subMonth())
+ ->get();
+
}
/**
diff --git a/src/Alerts/Corp/MemberApiState.php b/src/Alerts/Corp/MemberApiState.php
index b3dd521..c3f365e 100644
--- a/src/Alerts/Corp/MemberApiState.php
+++ b/src/Alerts/Corp/MemberApiState.php
@@ -35,6 +35,18 @@ class MemberApiState extends Base
use Corporation, Members;
+ /**
+ * The field to use from the data when trying
+ * to infer an affiliation.
+ *
+ * @return string
+ */
+ public function getAffiliationField()
+ {
+
+ return 'corporation_id';
+ }
+
/**
* The required method to handle the Alert.
*
@@ -60,18 +72,6 @@ protected function getData(): Collection
return $members;
}
- /**
- * The field to use from the data when trying
- * to infer an affiliation.
- *
- * @return string
- */
- public function getAffiliationField()
- {
-
- return 'corporation_id';
- }
-
/**
* The type of notification.
*
diff --git a/src/Alerts/Corp/MemberInactivity.php b/src/Alerts/Corp/MemberInactivity.php
index d41e615..9fd7104 100644
--- a/src/Alerts/Corp/MemberInactivity.php
+++ b/src/Alerts/Corp/MemberInactivity.php
@@ -34,28 +34,28 @@ class MemberInactivity extends Base
{
/**
- * The required method to handle the Alert.
+ * The field to use form the data when trying
+ * to infer an affiliation.
*
- * @return mixed
+ * @return string
*/
- protected function getData(): Collection
+ public function getAffiliationField()
{
- return MemberTracking::where(
- 'logoffDateTime', '<', DB::raw('date_sub(NOW(), INTERVAL 3 MONTH)'))
- ->get();
+ return 'corporationID';
}
/**
- * The field to use form the data when trying
- * to infer an affiliation.
+ * The required method to handle the Alert.
*
- * @return string
+ * @return mixed
*/
- public function getAffiliationField()
+ protected function getData(): Collection
{
- return 'corporationID';
+ return MemberTracking::where(
+ 'logoffDateTime', '<', DB::raw('date_sub(NOW(), INTERVAL 3 MONTH)'))
+ ->get();
}
/**
diff --git a/src/Alerts/Corp/StarbaseFuel.php b/src/Alerts/Corp/StarbaseFuel.php
index 98d8b1f..afc2b38 100644
--- a/src/Alerts/Corp/StarbaseFuel.php
+++ b/src/Alerts/Corp/StarbaseFuel.php
@@ -31,6 +31,18 @@ class StarbaseFuel extends Base
use Starbases;
+ /**
+ * The field to use from the data when trying
+ * to infer an affiliation.
+ *
+ * @return string
+ */
+ public function getAffiliationField()
+ {
+
+ return 'corporation_id';
+ }
+
/**
* The required method to handle the Alert.
*
@@ -79,18 +91,6 @@ function ($starbase) use ($corporation_id, &$low_feul) {
}
- /**
- * The field to use from the data when trying
- * to infer an affiliation.
- *
- * @return string
- */
- public function getAffiliationField()
- {
-
- return 'corporation_id';
- }
-
/**
* The type of notification.
*
diff --git a/src/Alerts/Corp/StarbaseStateChange.php b/src/Alerts/Corp/StarbaseStateChange.php
index 0363d2d..fca8e1a 100644
--- a/src/Alerts/Corp/StarbaseStateChange.php
+++ b/src/Alerts/Corp/StarbaseStateChange.php
@@ -36,6 +36,18 @@ class StarbaseStateChange extends Base
use Starbases, EveRepository;
+ /**
+ * The field to use from the data when trying
+ * to infer an affiliation.
+ *
+ * @return string
+ */
+ public function getAffiliationField()
+ {
+
+ return 'corporation_id';
+ }
+
/**
* The required method to handle the Alert.
*
@@ -75,18 +87,6 @@ function ($starbase) use ($corporation_id, &$starbases) {
return $starbases;
}
- /**
- * The field to use from the data when trying
- * to infer an affiliation.
- *
- * @return string
- */
- public function getAffiliationField()
- {
-
- return 'corporation_id';
- }
-
/**
* The type of notification.
*
diff --git a/src/Models/NotificationGroup.php b/src/Models/NotificationGroup.php
index 77e3723..40bd6cd 100644
--- a/src/Models/NotificationGroup.php
+++ b/src/Models/NotificationGroup.php
@@ -40,15 +40,6 @@ class NotificationGroup extends Model
'name', 'type'
];
- /**
- * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
- */
- public function integrations()
- {
-
- return $this->belongsToMany(Integration::class);
- }
-
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
@@ -72,24 +63,33 @@ public function affiliations()
*
* @return mixed
*/
- public function notificationChannels() : array
+ public function notificationChannels(): array
{
return $this->integrations()
->pluck('type')->unique()->all();
}
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
+ */
+ public function integrations()
+ {
+
+ return $this->belongsToMany(Integration::class);
+ }
+
/**
* Return the URL used to route Slack Notifications.
*
* @return mixed
*/
- public function routeNotificationForSlack() : string
+ public function routeNotificationForSlack(): string
{
return $this->integrations
- ->where('type', 'slack')
- ->first()->settings['url'];
+ ->where('type', 'slack')
+ ->first()->settings['url'];
}
/**
@@ -97,12 +97,12 @@ public function routeNotificationForSlack() : string
*
* @return mixed
*/
- public function routeNotificationForMail() : string
+ public function routeNotificationForMail(): string
{
return $this->integrations
- ->where('type', 'mail')
- ->first()->settings['email'];
+ ->where('type', 'mail')
+ ->first()->settings['email'];
}
}
diff --git a/src/NotificationsServiceProvider.php b/src/NotificationsServiceProvider.php
index 407f13b..9c58ad3 100644
--- a/src/NotificationsServiceProvider.php
+++ b/src/NotificationsServiceProvider.php
@@ -79,23 +79,23 @@ public function add_publications()
}
/**
- * Include the translations and set the namespace
+ * Include the routes
*/
- public function add_translations()
+ public function add_routes()
{
- $this->loadTranslationsFrom(__DIR__ . '/lang', 'notifications');
+ if (!$this->app->routesAreCached()) {
+ include __DIR__ . '/Http/routes.php';
+ }
}
/**
- * Include the routes
+ * Include the translations and set the namespace
*/
- public function add_routes()
+ public function add_translations()
{
- if (!$this->app->routesAreCached()) {
- include __DIR__ . '/Http/routes.php';
- }
+ $this->loadTranslationsFrom(__DIR__ . '/lang', 'notifications');
}
/**
diff --git a/src/resources/views/groups/edit.blade.php b/src/resources/views/groups/edit.blade.php
index d26fb4a..44b903f 100644
--- a/src/resources/views/groups/edit.blade.php
+++ b/src/resources/views/groups/edit.blade.php
@@ -257,10 +257,10 @@ class="btn btn-xs btn-danger pull-right">
diff --git a/src/resources/views/groups/list.blade.php b/src/resources/views/groups/list.blade.php
index 76693f3..b2cc5d3 100644
--- a/src/resources/views/groups/list.blade.php
+++ b/src/resources/views/groups/list.blade.php
@@ -76,21 +76,21 @@
diff --git a/src/resources/views/integrations/list.blade.php b/src/resources/views/integrations/list.blade.php
index 8694838..9a1293b 100644
--- a/src/resources/views/integrations/list.blade.php
+++ b/src/resources/views/integrations/list.blade.php
@@ -62,8 +62,8 @@
$('table#integrations').DataTable({
processing: true,
serverSide: true,
- ajax: '{{ route('notifications.integrations.list.data') }}',
- columns: [
+ ajax : '{{ route('notifications.integrations.list.data') }}',
+ columns : [
{data: 'name', name: 'name'},
{data: 'type', name: 'type'},
{