Skip to content

Commit

Permalink
changed: updated for Elgg 6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Nov 26, 2024
1 parent 4bb1e18 commit 7ece60f
Show file tree
Hide file tree
Showing 30 changed files with 65 additions and 780 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Group Tools
===========

![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Elgg 6.1](https://img.shields.io/badge/Elgg-6.1-green.svg)
![Lint Checks](https://github.com/ColdTrick/group_tools/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/group_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/group_tools)
[![License](https://poser.pugx.org/coldtrick/group_tools/license.svg)](https://packagist.org/packages/coldtrick/group_tools)
Expand Down
5 changes: 1 addition & 4 deletions actions/groups/invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use Symfony\Component\HttpFoundation\File\UploadedFile;

$user_guids = (array) get_input('user_guid');
$non_group_members = (array) get_input('non_group_members');

$user_guids = array_merge($user_guids, $non_group_members);
$user_guids = array_filter($user_guids);

$adding = false;
Expand Down Expand Up @@ -55,7 +52,7 @@
return elgg_error_response(elgg_echo('error:missing_data'));
}

if (!$group->canEdit() && !group_tools_allow_members_invite($group)) {
if (!$group->canEdit()) {
return elgg_error_response(elgg_echo('actionunauthorized'));
}

Expand Down
16 changes: 0 additions & 16 deletions classes/ColdTrick/GroupTools/Menus/Filter/GroupsAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,6 @@
*/
class GroupsAll {

/**
* Rewrite group listing tabs
*
* @param \Elgg\Event $event 'register', 'menu:filter:groups/all'
*
* @return MenuItems
*/
public static function removeTabs(\Elgg\Event $event): MenuItems {
/* @var $return MenuItems */
$return = $event->getValue();

$return->remove('popular');

return $return;
}

/**
* Rewrite group listing tabs
*
Expand Down
16 changes: 16 additions & 0 deletions classes/ColdTrick/GroupTools/Menus/Filter/GroupsMembers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ColdTrick\GroupTools\Menus\Filter;

use Elgg\Database\QueryBuilder;
use Elgg\Menu\MenuItems;

/**
Expand Down Expand Up @@ -70,6 +71,21 @@ public static function registerEmailInvitations(\Elgg\Event $event) {
'guid' => $entity->guid,
]),
'priority' => 600,
'badge' => elgg_get_annotations([
'selects' => [
function(QueryBuilder $qb, $main_alias) {
return "SUBSTRING_INDEX({$main_alias}.value, '|', -1) AS invited_email";
},
],
'annotation_name' => 'email_invitation',
'annotation_owner_guid' => $entity->guid,
'wheres' => [
function(QueryBuilder $qb, $main_alias) {
return $qb->compare("{$main_alias}.value", 'LIKE', '%|%', ELGG_VALUE_STRING);
},
],
'count' => true,
]),
]);

return $result;
Expand Down
54 changes: 0 additions & 54 deletions classes/ColdTrick/GroupTools/Menus/FilterSortItems.php

This file was deleted.

101 changes: 1 addition & 100 deletions classes/ColdTrick/GroupTools/Menus/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,7 @@ public static function groupMembership(\Elgg\Event $event): ?MenuItems {
return null;
}

if ($user->hasRelationship($entity->guid, 'membership_request')) {
// user already requested to join this group
$menu_item->setText(elgg_echo('group_tools:joinrequest:already'));
$menu_item->setTooltip(elgg_echo('group_tools:joinrequest:already:tooltip'));
$menu_item->setHref(elgg_generate_action_url('groups/killrequest', [
'user_guid' => $user->guid,
'group_guid' => $entity->guid,
]));
} elseif ($entity->hasRelationship($user->guid, 'invited')) {
// the user was invited, so let him/her join
$menu_item->setName('groups:join');
$menu_item->setText(elgg_echo('groups:join'));
$menu_item->setTooltip(elgg_echo('group_tools:join:already:tooltip'));
$menu_item->setHref(elgg_generate_action_url('groups/join', [
'user_guid' => $user->guid,
'group_guid' => $entity->guid,
]));
} elseif (group_tools_check_domain_based_group($entity, $user)) {
if (group_tools_check_domain_based_group($entity, $user)) {
// user has a matching email domain
$menu_item->setName('groups:join');
$menu_item->setText(elgg_echo('groups:join'));
Expand All @@ -77,88 +60,6 @@ public static function groupMembership(\Elgg\Event $event): ?MenuItems {
return $menu_items;
}

/**
* Change the text of the group invite button, and maybe add it for group members
*
* @param \Elgg\Event $event 'register', 'menu:title'
*
* @return null|MenuItems
*/
public static function groupInvite(\Elgg\Event $event): ?MenuItems {
if (!elgg_in_context('groups')) {
return null;
}

$user = elgg_get_logged_in_user_entity();
if (!$user instanceof \ElggUser) {
return null;
}

/* @var $menu_items MenuItems */
$menu_items = $event->getValue();

$invite_found = false;
$menu_item = $menu_items->get('groups:invite');
if ($menu_item instanceof \ElggMenuItem) {
$invite_found = true;

$invite_friends = elgg_get_plugin_setting('invite_friends', 'group_tools');
$invite = elgg_get_plugin_setting('invite', 'group_tools');
$invite_email = elgg_get_plugin_setting('invite_email', 'group_tools');
$invite_csv = elgg_get_plugin_setting('invite_csv', 'group_tools');

if (in_array('yes', [$invite, $invite_csv, $invite_email])) {
$menu_item->setText(elgg_echo('group_tools:groups:invite'));

$menu_items->add($menu_item);
} elseif ($invite_friends === 'no') {
$menu_items->remove('groups:invite');
}
}

// maybe allow normal users to invite new members
if (!elgg_in_context('group_profile') || $invite_found) {
return $menu_items;
}

// this is only allowed for group members
$entity = $event->getEntityParam();
if (!$entity instanceof \ElggGroup || !$entity->isMember($user)) {
return null;
}

// we're on a group profile page, but haven't found the invite button yet
// so check if it should be here
if (!group_tools_allow_members_invite($entity)) {
return null;
}

// normal users are allowed to invite users
$invite_friends = elgg_get_plugin_setting('invite_friends', 'group_tools');
$invite = elgg_get_plugin_setting('invite', 'group_tools');
$invite_email = elgg_get_plugin_setting('invite_email', 'group_tools');
$invite_csv = elgg_get_plugin_setting('invite_csv', 'group_tools');

if (in_array('yes', [$invite, $invite_csv, $invite_email])) {
$text = elgg_echo('group_tools:groups:invite');
} elseif ($invite_friends !== 'no') {
$text = elgg_echo('groups:invite');
} else {
// not allowed
return null;
}

$menu_items[] = \ElggMenuItem::factory([
'name' => 'groups:invite',
'icon' => 'user-plus',
'href' => elgg_generate_url('invite:group:group', ['guid' => $entity->guid]),
'text' => $text,
'link_class' => 'elgg-button elgg-button-action',
]);

return $menu_items;
}

/**
* Change the text on the group membership status button
*
Expand Down
87 changes: 23 additions & 64 deletions classes/ColdTrick/GroupTools/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Views {
* @return null|array
*/
public static function prepareGroupAll(\Elgg\Event $event): ?array {
if (!empty(get_input('sort_by')) || !empty(get_input('sort'))) {
if (!empty(get_input('sort_by'))) {
return null;
}

Expand All @@ -35,77 +35,36 @@ public static function prepareGroupAll(\Elgg\Event $event): ?array {

$vars = $event->getValue();

// support for 'old' tabs
switch ($filter) {
case 'popular':
set_input('sort', 'popular');
set_input('filter', 'all');
$vars['filter_sorting_selected'] = 'popular';
set_input('filter', $filter);
$sorting = elgg_get_plugin_setting("group_listing_{$filter}_sorting", 'group_tools', 'newest');
switch ($sorting) {
case 'alpha':
set_input('sort_by', [
'property_type' => 'metadata',
'property' => 'name',
'direction' => 'asc',
]);
$vars['filter_sorting_selected'] = 'sort:name:asc';
break;

default:
set_input('filter', $filter);
$sorting = elgg_get_plugin_setting("group_listing_{$filter}_sorting", 'group_tools', 'newest');
switch ($sorting) {
case 'alpha':
set_input('sort_by', [
'property_type' => 'metadata',
'property' => 'name',
'direction' => 'asc',
]);
$vars['filter_sorting_selected'] = 'sort:name:asc';
break;

case 'newest':
set_input('sort_by', [
'property_type' => 'attribute',
'property' => 'time_created',
'direction' => 'desc',
]);
$vars['filter_sorting_selected'] = 'sort:time_created:desc';
break;

case 'popular':
set_input('sort', $sorting);
$vars['filter_sorting_selected'] = 'popular';
break;
}
case 'newest':
set_input('sort_by', [
'property_type' => 'attribute',
'property' => 'time_created',
'direction' => 'desc',
]);
$vars['filter_sorting_selected'] = 'sort:time_created:desc';
break;

case 'popular':
set_input('sort_by', $sorting);
$vars['filter_sorting_selected'] = 'popular';
break;
}

return $vars;
}

/**
* Change some inputs when listing users in livesearch for group invites
*
* @param \Elgg\Event $event 'view_vars', 'page/components/list'
*
* @return null|array
*/
public static function livesearchUserListing(\Elgg\Event $event): ?array {
$group_guid = (int) get_input('group_guid');
$group_invite = (bool) get_input('group_invite');
if ($group_guid < 1 || empty($group_invite)) {
return null;
}

$group = get_entity($group_guid);
if (!$group instanceof \ElggGroup) {
return null;
}

$vars = $event->getValue();
if (elgg_extract('type', $vars) !== 'user') {
return null;
}

$vars['item_view'] = 'group_tools/group_invite/user';
$vars['group'] = $group;

return $vars;
}

/**
* Set correct value to show/hide group owner transfer
*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"issues": "https://github.com/ColdTrick/group_tools/issues"
},
"conflict": {
"elgg/elgg": "<6.0"
"elgg/elgg": "<6.1"
}
}
8 changes: 4 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7ece60f

Please sign in to comment.