X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FGroup.php;h=8da062a93e9dfbfb9619725e45e4245164aa23d7;hb=1792046a4f270f15d904d591c1e9eb0444ff2349;hp=ccb4f8bdf81381f7a8c35a31e01c0af67a30bf36;hpb=6d7362da4134cce31f28a5efa2c623a11f89afc2;p=friendica.git diff --git a/src/Module/Group.php b/src/Module/Group.php index ccb4f8bdf8..8da062a93e 100644 --- a/src/Module/Group.php +++ b/src/Module/Group.php @@ -1,14 +1,27 @@ . + * */ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Core\Config; -use Friendica\Core\L10n; -use Friendica\Core\PConfig; use Friendica\Core\Renderer; use Friendica\Core\System; use Friendica\Database\DBA; @@ -29,7 +42,7 @@ class Group extends BaseModule } if (!local_user()) { - notice(L10n::t('Permission denied.')); + notice(DI::l10n()->t('Permission denied.')); DI::baseUrl()->redirect(); } @@ -40,13 +53,12 @@ class Group extends BaseModule $name = Strings::escapeTags(trim($_POST['groupname'])); $r = Model\Group::create(local_user(), $name); if ($r) { - info(L10n::t('Group created.')); $r = Model\Group::getIdByName(local_user(), $name); if ($r) { DI::baseUrl()->redirect('group/' . $r); } } else { - notice(L10n::t('Could not create group.')); + notice(DI::l10n()->t('Could not create group.')); } DI::baseUrl()->redirect('group'); } @@ -57,13 +69,13 @@ 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.')); + notice(DI::l10n()->t('Group not found.')); DI::baseUrl()->redirect('contact'); } $groupname = Strings::escapeTags(trim($_POST['groupname'])); if (strlen($groupname) && ($groupname != $group['name'])) { - if (Model\Group::update($group['id'], $groupname)) { - info(L10n::t('Group name changed.')); + if (!Model\Group::update($group['id'], $groupname)) { + notice(DI::l10n()->t('Group name was not changed.')); } } } @@ -75,7 +87,7 @@ class Group extends BaseModule $a = DI::app(); if (!local_user()) { - throw new \Exception(L10n::t('Permission denied.'), 403); + throw new \Exception(DI::l10n()->t('Permission denied.'), 403); } // POST /group/123/add/123 @@ -85,41 +97,41 @@ class Group extends BaseModule list($group_id, $command, $contact_id) = array_slice($a->argv, 1); if (!Model\Group::exists($group_id, local_user())) { - throw new \Exception(L10n::t('Unknown group.'), 404); + throw new \Exception(DI::l10n()->t('Unknown group.'), 404); } $contact = DBA::selectFirst('contact', ['deleted'], ['id' => $contact_id, 'uid' => local_user()]); if (!DBA::isResult($contact)) { - throw new \Exception(L10n::t('Contact not found.'), 404); + throw new \Exception(DI::l10n()->t('Contact not found.'), 404); } if ($contact['deleted']) { - throw new \Exception(L10n::t('Contact is deleted.'), 410); + throw new \Exception(DI::l10n()->t('Contact is deleted.'), 410); } switch($command) { case 'add': if (!Model\Group::addMember($group_id, $contact_id)) { - throw new \Exception(L10n::t('Unable to add the contact to the group.'), 500); + throw new \Exception(DI::l10n()->t('Unable to add the contact to the group.'), 500); } - $message = L10n::t('Contact successfully added to group.'); + $message = DI::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); + throw new \Exception(DI::l10n()->t('Unable to remove the contact from the group.'), 500); } - $message = L10n::t('Contact successfully removed from group.'); + $message = DI::l10n()->t('Contact successfully removed from group.'); break; default: - throw new \Exception(L10n::t('Unknown group command.'), 400); + throw new \Exception(DI::l10n()->t('Unknown group command.'), 400); } } else { - throw new \Exception(L10n::t('Bad request.'), 400); + throw new \Exception(DI::l10n()->t('Bad request.'), 400); } - notice($message); + info($message); System::jsonExit(['status' => 'OK', 'message' => $message]); } catch (\Exception $e) { notice($e->getMessage()); @@ -146,24 +158,24 @@ class Group extends BaseModule } // Switch to text mode interface if we have more than 'n' contacts or group members - $switchtotext = PConfig::get(local_user(), 'system', 'groupedit_image_limit'); + $switchtotext = DI::pConfig()->get(local_user(), 'system', 'groupedit_image_limit'); if (is_null($switchtotext)) { - $switchtotext = Config::get('system', 'groupedit_image_limit', 200); + $switchtotext = DI::config()->get('system', 'groupedit_image_limit', 200); } $tpl = Renderer::getMarkupTemplate('group_edit.tpl'); $context = [ - '$submit' => L10n::t('Save Group'), - '$submit_filter' => L10n::t('Filter'), + '$submit' => DI::l10n()->t('Save Group'), + '$submit_filter' => DI::l10n()->t('Filter'), ]; // @TODO: Replace with parameter from router if (($a->argc == 2) && ($a->argv[1] === 'new')) { return Renderer::replaceMacros($tpl, $context + [ - '$title' => L10n::t('Create a group of contacts/friends.'), - '$gname' => ['groupname', L10n::t('Group Name: '), '', ''], + '$title' => DI::l10n()->t('Create a group of contacts/friends.'), + '$gname' => ['groupname', DI::l10n()->t('Group Name: '), '', ''], '$gid' => 'new', '$form_security_token' => BaseModule::getFormSecurityToken("group_edit"), ]); @@ -178,7 +190,7 @@ class Group extends BaseModule $nogroup = true; $group = [ 'id' => $id, - 'name' => L10n::t('Contacts not in any group'), + 'name' => DI::l10n()->t('Contacts not in any group'), ]; $members = []; @@ -186,7 +198,7 @@ class Group extends BaseModule $context = $context + [ '$title' => $group['name'], - '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''], + '$gname' => ['groupname', DI::l10n()->t('Group Name: '), $group['name'], ''], '$gid' => $id, '$editable' => 0, ]; @@ -199,14 +211,12 @@ class Group extends BaseModule // @TODO: Replace with parameter from router if (intval($a->argv[2])) { if (!Model\Group::exists($a->argv[2], local_user())) { - notice(L10n::t('Group not found.')); + notice(DI::l10n()->t('Group not found.')); DI::baseUrl()->redirect('contact'); } - if (Model\Group::remove($a->argv[2])) { - info(L10n::t('Group removed.')); - } else { - notice(L10n::t('Unable to remove group.')); + if (!Model\Group::remove($a->argv[2])) { + notice(DI::l10n()->t('Unable to remove group.')); } } DI::baseUrl()->redirect('group'); @@ -225,11 +235,11 @@ class Group extends BaseModule if (($a->argc > 1) && intval($a->argv[1])) { $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.')); + notice(DI::l10n()->t('Group not found.')); DI::baseUrl()->redirect('contact'); } - $members = Model\Contact::getByGroupId($group['id']); + $members = Model\Contact\Group::getById($group['id']); $preselected = []; if (count($members)) { @@ -245,7 +255,7 @@ class Group extends BaseModule Model\Group::addMember($group['id'], $change); } - $members = Model\Contact::getByGroupId($group['id']); + $members = Model\Contact\Group::getById($group['id']); $preselected = []; if (count($members)) { foreach ($members as $member) { @@ -257,17 +267,17 @@ class Group extends BaseModule $drop_tpl = Renderer::getMarkupTemplate('group_drop.tpl'); $drop_txt = Renderer::replaceMacros($drop_tpl, [ '$id' => $group['id'], - '$delete' => L10n::t('Delete Group'), + '$delete' => DI::l10n()->t('Delete Group'), '$form_security_token' => BaseModule::getFormSecurityToken("group_drop"), ]); $context = $context + [ '$title' => $group['name'], - '$gname' => ['groupname', L10n::t('Group Name: '), $group['name'], ''], + '$gname' => ['groupname', DI::l10n()->t('Group Name: '), $group['name'], ''], '$gid' => $group['id'], '$drop' => $drop_txt, '$form_security_token' => BaseModule::getFormSecurityToken('group_edit'), - '$edit_name' => L10n::t('Edit Group Name'), + '$edit_name' => DI::l10n()->t('Edit Group Name'), '$editable' => 1, ]; } @@ -277,10 +287,10 @@ class Group extends BaseModule } $groupeditor = [ - 'label_members' => L10n::t('Members'), + 'label_members' => DI::l10n()->t('Members'), 'members' => [], - 'label_contacts' => L10n::t('All Contacts'), - 'group_is_empty' => L10n::t('Group is empty'), + 'label_contacts' => DI::l10n()->t('All Contacts'), + 'group_is_empty' => DI::l10n()->t('Group is empty'), 'contacts' => [], ]; @@ -293,7 +303,7 @@ class Group extends BaseModule $entry['label'] = 'members'; $entry['photo_menu'] = ''; $entry['change_member'] = [ - 'title' => L10n::t("Remove contact from group"), + 'title' => DI::l10n()->t("Remove contact from group"), 'gid' => $group['id'], 'cid' => $member['id'], 'sec_token' => $sec_token @@ -306,14 +316,14 @@ class Group extends BaseModule } if ($nogroup) { - $contacts = Model\Contact::getUngroupedList(local_user()); + $contacts = Model\Contact\Group::listUngrouped(local_user()); } else { $contacts_stmt = DBA::select('contact', [], - ['uid' => local_user(), 'pending' => false, 'blocked' => false, 'self' => false], + ['uid' => local_user(), 'pending' => false, 'blocked' => false, 'failed' => false, 'self' => false], ['order' => ['name']] ); $contacts = DBA::toArray($contacts_stmt); - $context['$desc'] = L10n::t('Click on a contact to add or remove.'); + $context['$desc'] = DI::l10n()->t('Click on a contact to add or remove.'); } if (DBA::isResult($contacts)) { @@ -327,7 +337,7 @@ class Group extends BaseModule if (!$nogroup) { $entry['change_member'] = [ - 'title' => L10n::t("Add contact to group"), + 'title' => DI::l10n()->t("Add contact to group"), 'gid' => $group['id'], 'cid' => $member['id'], 'sec_token' => $sec_token