Commit ad200e40 authored by Johannes's avatar Johannes Committed by Johannes

Moved sendEmailIfLastAdminLeftGroup($goupId) to NotificationService

parent a7542e0e
......@@ -12,21 +12,25 @@ use Foodsharing\Modules\Core\DBConstants\Region\Type;
use Foodsharing\Modules\Core\DBConstants\Region\RegionIDs;
use Foodsharing\Modules\Region\ForumFollowerGateway;
use Foodsharing\Modules\Store\StoreModel;
use Foodsharing\Services\NotificationService;
final class FoodsaverGateway extends BaseGateway
{
private $dataHelper;
private $forumFollowerGateway;
private $notificationService;
public function __construct(
Database $db,
DataHelper $dataHelper,
ForumFollowerGateway $forumFollowerGateway
ForumFollowerGateway $forumFollowerGateway,
NotificationService $notificationService
) {
parent::__construct($db);
$this->dataHelper = $dataHelper;
$this->forumFollowerGateway = $forumFollowerGateway;
$this->notificationService = $notificationService;
}
public function getFoodsaversByRegion(int $regionId, bool $hideRecentlyOnline = false): array
......@@ -770,6 +774,7 @@ final class FoodsaverGateway extends BaseGateway
$this->db->delete('fs_botschafter', ['bezirk_id' => $regionId, 'foodsaver_id' => $fsId]);
$this->db->delete('fs_foodsaver_has_bezirk', ['bezirk_id' => $regionId, 'foodsaver_id' => $fsId]);
$this->notificationService->sendEmailIfLastAdminLeftGroup($bezirk_id);
$this->forumFollowerGateway->deleteForumSubscription($regionId, $fsId);
$mainRegion_id = $this->db->fetchValueByCriteria('fs_foodsaver', 'bezirk_id', ['id' => $fsId]);
......
......@@ -121,30 +121,8 @@ final class RegionXhr extends Control
unset($data);
if ($this->session->mayBezirk($groupId)) {
$wasAdminForThisGroup = $this->session->isAdminFor($groupId);
$this->foodsaverGateway->deleteFromRegion($groupId, $this->session->id());
if ($wasAdminForThisGroup && count($this->foodsaverGateway->getBotschafter($groupId)) < 1) {
$recipient = ['[email protected]', '[email protected]'];
$groupName = $this->regionGateway->getRegionName($groupId);
$idStructure = $this->regionGateway->listRegionsIncludingParents([$groupId]);
$idStructureList = [];
foreach ($idStructure as $id) {
$idStructureList[] = '' . $id . ' - ' . $this->regionGateway->getRegionName($id) . '';
}
$idStructureList = implode('<br>', $idStructureList);
$messageText = $this->translationHelper->sv('message_text_to_group_admin_workgroup', ['groupId' => $groupId, '$idStructureList' => $idStructureList, 'groupName' => $groupName]);
$this->emailHelper->tplMail('general/workgroup_contact', $recipient, [
'gruppenname' => $groupName,
'message' => $messageText,
'username' => $this->session->user('name'),
'userprofile' => BASE_URL . '/profile/' . $this->session->id()
], $this->session->user('email'));
}
return ['status' => 1];
}
......
......@@ -5,7 +5,10 @@ namespace Foodsharing\Services;
use Foodsharing\Helpers\EmailHelper;
use Foodsharing\Helpers\TranslationHelper;
use Foodsharing\Modules\Bell\BellGateway;
use Foodsharing\Modules\Foodsaver\FoodsaverGateway;
use Foodsharing\Modules\FoodSharePoint\FoodSharePointGateway;
use Foodsharing\Modules\Region\RegionGateway;
use Foodsharing\Lib\Session;
final class NotificationService
{
......@@ -14,19 +17,28 @@ final class NotificationService
private $sanitizerService;
private $emailHelper;
private $translationHelper;
private $regionGateway;
private $foodsaverGateway;
private $session;
public function __construct(
BellGateway $bellGateway,
FoodSharePointGateway $foodSharePoint,
SanitizerService $sanitizerService,
EmailHelper $emailHelper,
TranslationHelper $translationHelper
TranslationHelper $translationHelper,
RegionGateway $regionGateway,
Session $session,
FoodsaverGateway $foodsaverGateway
) {
$this->bellGateway = $bellGateway;
$this->foodSharePointGateway = $foodSharePoint;
$this->sanitizerService = $sanitizerService;
$this->emailHelper = $emailHelper;
$this->translationHelper = $translationHelper;
$this->regionGateway = $regionGateway;
$this->session = $session;
$this->foodsaverGateway = $foodsaverGateway;
}
public function newFoodSharePointPost(int $foodSharePointId)
......@@ -73,4 +85,30 @@ final class NotificationService
}
}
}
public function sendEmailIfLastAdminLeftGroup($groupId)
{
$wasAdminForThisGroup = $this->session->isAdminFor($groupId);
if ($wasAdminForThisGroup && count($this->foodsaverGateway->getBotschafter($groupId)) < 1) {
$recipient = ['[email protected]', '[email protected]'];
$groupName = $this->regionGateway->getRegionName($groupId);
$idStructure = $this->regionGateway->listRegionsIncludingParents([$groupId]);
$idStructureList = [];
foreach ($idStructure as $id) {
$idStructureList[] = '' . $id . ' - ' . $this->regionGateway->getRegionName($id) . '';
}
$idStructureList = implode('<br>', $idStructureList);
$messageText = $this->translationHelper->sv('message_text_to_group_admin_workgroup', ['groupId' => $groupId, '$idStructureList' => $idStructureList, 'groupName' => $groupName]);
$this->emailHelper->tplMail('general/workgroup_contact', $recipient, [
'gruppenname' => $groupName,
'message' => $messageText,
'username' => $this->session->user('name'),
'userprofile' => BASE_URL . '/profile/' . $this->session->id()
], $this->session->user('email'));
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment