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

Resolved circular reference problem by moving methods. Added structured region id list back in.

parent 8c711bc1
......@@ -26,5 +26,5 @@ $g_lang['online'] = 'Multilokal auf mumble.foodsharing.de';
$g_lang['mumble_room'] = 'In welchem mumble Konferenzraum treffen wir uns?';
$g_lang['dateend'] = 'Enddatum';
$g_lang['post_could_not_saved'] = 'Post konnte nicht gespeichert werden.';
$g_lang['message_text_to_group_admin_workgroup'] = 'Die Region/AG <b>{groupName}</b> hat <b>keinen</b> Botschafter/Admin mehr.<br><br>Die ID lautet: {groupId}<br><br>URL: <a href="https://foodsharing.de/?page=bezirk&bid={groupId}&sub=forum" target="_blank">Klicke hier um zur zur Region/AG zu gehen</a>';
$g_lang['message_text_to_group_admin_workgroup'] = 'Die Region/AG <b>{groupName}</b> hat <b>keinen</b> Botschafter/Admin mehr.<br><br><br>Sie besitzt folgende ID-Struktur:<br>{idStructureList}<br><br>Die ID lautet: {groupId}<br><br>URL: <a href="https://foodsharing.de/?page=bezirk&bid={groupId}&sub=forum" target="_blank">Klicke hier um zur zur Region/AG zu gehen</a>';
$g_lang['redirect_to_forum_no_workgroup'] = 'Für Regionen gibt es keine Pinnwand. Du wurdest zum Forum weitergeleitet.';
......@@ -12,25 +12,21 @@ 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,
NotificationService $notificationService
ForumFollowerGateway $forumFollowerGateway
) {
parent::__construct($db);
$this->dataHelper = $dataHelper;
$this->forumFollowerGateway = $forumFollowerGateway;
$this->notificationService = $notificationService;
}
public function getFoodsaversByRegion(int $regionId, bool $hideRecentlyOnline = false): array
......@@ -774,7 +770,6 @@ 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]);
......
......@@ -6,23 +6,27 @@ use Foodsharing\Lib\Xhr\XhrResponses;
use Foodsharing\Modules\Core\Control;
use Foodsharing\Modules\Region\RegionGateway;
use Foodsharing\Services\SanitizerService;
use Foodsharing\Services\NotificationService;
class FoodsaverXhr extends Control
{
private $foodsaverGateway;
private $regionGateway;
private $sanitizerService;
private $notificationService;
public function __construct(
FoodsaverView $view,
RegionGateway $regionGateway,
SanitizerService $sanitizerService,
FoodsaverGateway $foodsaverGateway
FoodsaverGateway $foodsaverGateway,
NotificationService $notificationService
) {
$this->view = $view;
$this->foodsaverGateway = $foodsaverGateway;
$this->regionGateway = $regionGateway;
$this->sanitizerService = $sanitizerService;
$this->notificationService = $notificationService;
parent::__construct();
}
......@@ -70,6 +74,7 @@ class FoodsaverXhr extends Control
return XhrResponses::PERMISSION_DENIED;
}
$this->foodsaverGateway->deleteFromRegion($_GET['bid'], $_GET['id']);
$this->notificationService->sendEmailIfGroupHasNoAdmin($_GET['bid']);
return [
'status' => 1,
......
......@@ -6,6 +6,7 @@ use Foodsharing\Lib\Xhr\XhrResponses;
use Foodsharing\Modules\Core\Control;
use Foodsharing\Modules\Foodsaver\FoodsaverGateway;
use Foodsharing\Permissions\ForumPermissions;
use Foodsharing\Services\NotificationService;
final class RegionXhr extends Control
{
......@@ -17,6 +18,7 @@ final class RegionXhr extends Control
private $forumPermissions;
private $regionHelper;
private $twig;
private $notificationService;
public function __construct(
RegionGateway $regionGateway,
......@@ -25,7 +27,8 @@ final class RegionXhr extends Control
RegionHelper $regionHelper,
\Twig\Environment $twig,
FoodsaverGateway $foodsaverGateway,
ForumFollowerGateway $forumFollowerGateway
ForumFollowerGateway $forumFollowerGateway,
NotificationService $notificationService
) {
$this->regionGateway = $regionGateway;
$this->foodsaverGateway = $foodsaverGateway;
......@@ -35,6 +38,7 @@ final class RegionXhr extends Control
$this->regionHelper = $regionHelper;
$this->twig = $twig;
$this->responses = new XhrResponses();
$this->notificationService = $notificationService;
parent::__construct();
}
......@@ -119,6 +123,7 @@ final class RegionXhr extends Control
if ($this->session->mayBezirk($groupId)) {
$this->foodsaverGateway->deleteFromRegion($groupId, $this->session->id());
$this->notificationService->sendEmailIfGroupHasNoAdmin($groupId);
return ['status' => 1];
}
......
......@@ -86,22 +86,19 @@ final class NotificationService
}
}
public function sendEmailIfLastAdminLeftGroup($groupId): void
public function sendEmailIfGroupHasNoAdmin($groupId): void
{
$wasAdminForThisGroup = $this->session->isAdminFor($groupId);
if ($wasAdminForThisGroup && count($this->foodsaverGateway->getBotschafter($groupId)) < 1) {
if (count($this->foodsaverGateway->getBotschafter($groupId)) < 1) {
$recipient = ['[email protected]', '[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 = '';
foreach ($idStructure as $key => $id) {
$idStructureList .= str_repeat('---', $key + 1) . '> <b>' . $id . '</b> - ' . $this->regionGateway->getRegionName($id) . '<br>';
}
$idStructureList = implode('<br>', $idStructureList);
$messageText = $this->translationHelper->sv('message_text_to_group_admin_workgroup', ['groupId' => $groupId, '$idStructureList' => $idStructureList, 'groupName' => $groupName]);
$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,
......
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