391 Notification refactorings (#441)
* Refactor notifications to allow easier plugins * Notification refactoring * Formatting * Move news to NewsService; cleanup of events * More refactoring; added send email out for news item and the template * Formatting * Formatting
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Support\ClassLoader;
|
||||
use function get_class;
|
||||
use Nwidart\Modules\Facades\Module;
|
||||
|
||||
class AwardService extends Service
|
||||
@@ -18,9 +19,9 @@ class AwardService extends Service
|
||||
$awards = [];
|
||||
$formatted_awards = [];
|
||||
|
||||
// Find the awards in the app/Awards directory
|
||||
$classes = ClassLoader::getClassesInPath(app_path('/Awards'));
|
||||
$awards = array_merge($awards, $classes);
|
||||
// Find the awards in the modules/Awards directory
|
||||
// $classes = ClassLoader::getClassesInPath(module_path('Awards'));
|
||||
// $awards = array_merge($awards, $classes);
|
||||
|
||||
// Look throughout all the other modules, in the module/{MODULE}/Awards directory
|
||||
foreach (Module::all() as $module) {
|
||||
@@ -33,7 +34,7 @@ class AwardService extends Service
|
||||
}
|
||||
|
||||
foreach ($awards as $award) {
|
||||
$formatted_awards[\get_class($award)] = $award;
|
||||
$formatted_awards[get_class($award)] = $award;
|
||||
}
|
||||
|
||||
return $formatted_awards;
|
||||
|
||||
44
app/Services/NewsService.php
Normal file
44
app/Services/NewsService.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Contracts\Service;
|
||||
use App\Events\NewsAdded;
|
||||
use App\Repositories\NewsRepository;
|
||||
|
||||
class NewsService extends Service
|
||||
{
|
||||
private $newsRepo;
|
||||
|
||||
public function __construct(NewsRepository $newsRepo)
|
||||
{
|
||||
$this->newsRepo = $newsRepo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a news item
|
||||
*
|
||||
* @param array $attrs
|
||||
*
|
||||
* @throws \Prettus\Validator\Exceptions\ValidatorException
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function addNews(array $attrs)
|
||||
{
|
||||
$news = $this->newsRepo->create($attrs);
|
||||
event(new NewsAdded($news));
|
||||
|
||||
return $news;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete something from the news items
|
||||
*
|
||||
* @param int $id ID of the news row to delete
|
||||
*/
|
||||
public function deleteNews($id)
|
||||
{
|
||||
$this->newsRepo->delete($id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user