X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FGroup.php;h=8de4c5033b1b2095734038fb9a686bb3db7b9f74;hb=03038e7a3bb74bdab497d26b7f829a5c3036d1c2;hp=d8d5fb1c592086e9e2574fb246fbdf8eb08a5992;hpb=1de3960e267a8d298348fbca18cf1be1f6a20f7a;p=friendica.git diff --git a/src/Module/Group.php b/src/Module/Group.php index d8d5fb1c59..8de4c5033b 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -12,6 +12,7 @@ use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\DI; use Friendica\Model; use Friendica\Util\Strings; @@ -19,17 +20,17 @@ require_once 'boot.php'; class Group extends BaseModule { - public static function post() + public static function post(array $parameters = []) { - $a = self::getApp(); + $a = DI::app(); - if ($a->isAjax()) { + if (DI::mode()->isAjax()) { self::ajaxPost(); } if (!local_user()) { notice(L10n::t('Permission denied.')); - $a->internalRedirect(); + DI::baseUrl()->redirect(); } // @TODO: Replace with parameter from router @@ -42,12 +43,12 @@ class Group extends BaseModule info(L10n::t('Group created.')); $r = Model\Group::getIdByName(local_user(), $name); if ($r) { - $a->internalRedirect('group/' . $r); + DI::baseUrl()->redirect('group/' . $r); } } else { notice(L10n::t('Could not create group.')); } - $a->internalRedirect('group'); + DI::baseUrl()->redirect('group'); } // @TODO: Replace with parameter from router @@ -57,7 +58,7 @@ class Group extends BaseModule $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user()]); if (!DBA::isResult($group)) { notice(L10n::t('Group not found.')); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } $groupname = Strings::escapeTags(trim($_POST['groupname'])); if (strlen($groupname) && ($groupname != $group['name'])) { @@ -71,7 +72,7 @@ class Group extends BaseModule public static function ajaxPost() { try { - $a = self::getApp(); + $a = DI::app(); if (!local_user()) { throw new \Exception(L10n::t('Permission denied.'), 403); @@ -87,34 +88,28 @@ class Group extends BaseModule throw new \Exception(L10n::t('Unknown group.'), 404); } - $contact = DBA::selectFirst('contact', ['pending', 'blocked', 'deleted'], ['id' => $contact_id, 'uid' => local_user()]); + $contact = DBA::selectFirst('contact', ['deleted'], ['id' => $contact_id, 'uid' => local_user()]); if (!DBA::isResult($contact)) { throw new \Exception(L10n::t('Contact not found.'), 404); } - if ($contact['pending']) { - throw new \Exception(L10n::t('Contact is unavailable.'), 400); - } - if ($contact['deleted']) { throw new \Exception(L10n::t('Contact is deleted.'), 410); } switch($command) { case 'add': - if ($contact['blocked']) { - throw new \Exception(L10n::t('Contact is blocked, unable to add it to a group.'), 400); - } - if (!Model\Group::addMember($group_id, $contact_id)) { throw new \Exception(L10n::t('Unable to add the contact to the group.'), 500); } + $message = L10n::t('Contact successfully added to group.'); break; case 'remove': if (!Model\Group::removeMember($group_id, $contact_id)) { throw new \Exception(L10n::t('Unable to remove the contact from the group.'), 500); } + $message = L10n::t('Contact successfully removed from group.'); break; default: @@ -132,7 +127,7 @@ class Group extends BaseModule } } - public static function content() + public static function content(array $parameters = []) { $change = false; @@ -140,14 +135,14 @@ class Group extends BaseModule throw new \Friendica\Network\HTTPException\ForbiddenException(); } - $a = self::getApp(); + $a = DI::app(); $a->page['aside'] = Model\Group::sidebarWidget('contact', 'group', 'extended', (($a->argc > 1) ? $a->argv[1] : 'everyone')); // With no group number provided we jump to the unassigned contacts as a starting point // @TODO: Replace with parameter from router if ($a->argc == 1) { - $a->internalRedirect('group/none'); + DI::baseUrl()->redirect('group/none'); } // Switch to text mode interface if we have more than 'n' contacts or group members @@ -205,7 +200,7 @@ class Group extends BaseModule if (intval($a->argv[2])) { if (!Model\Group::exists($a->argv[2], local_user())) { notice(L10n::t('Group not found.')); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } if (Model\Group::remove($a->argv[2])) { @@ -214,7 +209,7 @@ class Group extends BaseModule notice(L10n::t('Unable to remove group.')); } } - $a->internalRedirect('group'); + DI::baseUrl()->redirect('group'); } // @TODO: Replace with parameter from router @@ -231,7 +226,7 @@ class Group extends BaseModule $group = DBA::selectFirst('group', ['id', 'name'], ['id' => $a->argv[1], 'uid' => local_user(), 'deleted' => false]); if (!DBA::isResult($group)) { notice(L10n::t('Group not found.')); - $a->internalRedirect('contact'); + DI::baseUrl()->redirect('contact'); } $members = Model\Contact::getByGroupId($group['id']);