Skip to content

Commit 9a07dc3

Browse files
committed
changed: added sorting capabilities to top pages for group owners
1 parent 3270f3a commit 9a07dc3

9 files changed

Lines changed: 198 additions & 25 deletions

File tree

actions/static/edit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
$entity->owner_guid = $owner->guid;
7979
$entity->container_guid = $owner->guid;
8080

81-
// new static pages should go on top
82-
$entity->order = -time();
81+
// new child static pages should go on top, root pages are last
82+
$entity->order = $parent ? -time() : time();
8383

8484
$saved = elgg_call(ELGG_IGNORE_ACCESS, function () use (&$entity) {
8585
return $entity->save();

actions/static/sort.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
use Elgg\Exceptions\Http\EntityNotFoundException;
4+
use Elgg\Exceptions\Http\EntityPermissionsException;
5+
6+
$group = get_entity((int) get_input('container_guid'));
7+
if (!$group instanceof \ElggGroup) {
8+
throw new EntityNotFoundException();
9+
}
10+
11+
if (!$group->canEdit() || !$group->canWriteToContainer(0, 'object', \StaticPage::SUBTYPE)) {
12+
throw new EntityPermissionsException();
13+
}
14+
15+
$guids = get_input('guids');
16+
if (empty($guids)) {
17+
throw new EntityNotFoundException();
18+
}
19+
20+
$order = 1;
21+
foreach ($guids as $guid) {
22+
$entity = get_entity((int) $guid);
23+
if (!$entity instanceof \StaticPage) {
24+
continue;
25+
}
26+
27+
if ($entity->container_guid !== $group->guid) {
28+
continue;
29+
}
30+
31+
if ($entity->parent_guid !== 0) {
32+
continue;
33+
}
34+
35+
$entity->order = $order;
36+
37+
$order++;
38+
}
39+
40+
return elgg_ok_response();

elgg-plugin.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
'actions' => [
3737
'static/edit' => [],
3838
'static/reorder' => [],
39+
'static/sort' => [],
3940
'static/mark_not_out_of_date' => [],
4041
],
4142
'routes' => [
@@ -302,9 +303,13 @@
302303
'elgg.css' => [
303304
'static/site.css' => [],
304305
],
306+
'groups/edit/settings' => [
307+
'static/groups/settings' => [],
308+
],
305309
],
306310
'view_options' => [
307311
'static/ajax/menu_static_edit' => ['ajax' => true],
312+
'forms/static/sort' => ['ajax' => true],
308313
],
309314
'notifications' => [
310315
'user' => [

languages/en.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
'static:groups:title' => "Manage group static pages",
3232
'static:groups:owner_block' => "Group static pages",
33+
'static:groups:edit:enable_manual_sorting' => "Enable manual sorting of static toppages",
3334
'groups:tool:static' => "Enable static pages",
3435
'groups:tool:static:description' => "Create static pages for the group. These can only be managed by the group owners/admins.",
3536

languages/nl.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22
/**
3-
* This file was created by Translation Editor v14.0
4-
* On 2024-08-13 12:09
3+
* This file was created by Translation Editor v14.0.4
4+
* On 2025-12-15 15:09
55
*/
66

77
return array (
8+
'static:groups:edit:enable_manual_sorting' => 'Sta handmatige sortering toe van hoofdpagina\'s',
89
'static:menu:filter:trashed' => 'Recent verwijderd',
910
'static:trashed:no_parent' => 'Deze pagina kon niet worden hersteld vanwege het ontbreken van een bovenliggende pagina.',
1011
'static:trashed:restore_parent' => 'Deze pagina kan niet worden hersteld totdat de bovenliggende pagina %s is hersteld.',
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
use Elgg\Exceptions\Http\EntityNotFoundException;
4+
use Elgg\Exceptions\Http\EntityPermissionsException;
5+
6+
elgg_ajax_gatekeeper();
7+
8+
$group = get_entity((int) elgg_extract('container_guid', $vars));
9+
if (!$group instanceof \ElggGroup) {
10+
throw new EntityNotFoundException();
11+
}
12+
13+
if (!$group->canEdit() || !$group->canWriteToContainer(0, 'object', \StaticPage::SUBTYPE)) {
14+
throw new EntityPermissionsException();
15+
}
16+
17+
$entities = elgg_get_entities([
18+
'type' => 'object',
19+
'subtype' => \StaticPage::SUBTYPE,
20+
'metadata_name_value_pairs' => [
21+
'parent_guid' => 0,
22+
],
23+
'container_guid' => $group->guid,
24+
'limit' => false,
25+
'sort_by' => [
26+
'property' => 'order',
27+
'direction' => 'asc',
28+
'join_type' => 'left',
29+
'signed' => true,
30+
],
31+
'batch' => true,
32+
]);
33+
34+
echo elgg_view_field([
35+
'#type' => 'hidden',
36+
'name' => 'container_guid',
37+
'value' => $group->guid,
38+
]);
39+
40+
$lis = '';
41+
foreach ($entities as $entity) {
42+
$input = elgg_view_field([
43+
'#type' => 'hidden',
44+
'name' => 'guids[]',
45+
'value' => $entity->guid,
46+
]);
47+
48+
$lis .= elgg_format_element('li', [], elgg_view_image_block(elgg_view_icon('arrows'), $input . $entity->getDisplayName()));
49+
}
50+
51+
if (empty($lis)) {
52+
echo elgg_echo('static:admin:empty');
53+
return;
54+
}
55+
56+
echo elgg_format_element('ul', ['class' => ['static-order-group-list', 'mbm']], $lis);
57+
58+
?>
59+
<script type='module'>
60+
import 'jquery';
61+
import 'jquery-ui';
62+
63+
$('.static-order-group-list').sortable({
64+
items: 'li',
65+
containment: 'parent',
66+
tolerance: 'pointer'
67+
});
68+
</script>
69+
<?php
70+
71+
echo elgg_view_field(['#type' => 'submit', 'value' => elgg_echo('save')]);

views/default/resources/static/group.php

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,42 @@
88
/* @var $group \ElggGroup */
99
$group = elgg_get_page_owner_entity();
1010

11+
$manual_sorting_enabled = (bool) $group->getPluginSetting('static', 'enable_manual_sorting', false);
12+
1113
elgg_push_collection_breadcrumbs('object', \StaticPage::SUBTYPE, $group);
1214

1315
$can_write = $group->canWriteToContainer(0, 'object', \StaticPage::SUBTYPE);
1416
if ($can_write) {
1517
elgg_register_title_button('add', 'object', \StaticPage::SUBTYPE);
18+
19+
if ($manual_sorting_enabled) {
20+
$count = elgg_count_entities([
21+
'type' => 'object',
22+
'subtype' => \StaticPage::SUBTYPE,
23+
'metadata_name_value_pairs' => [
24+
'parent_guid' => 0,
25+
],
26+
'container_guid' => $group->guid,
27+
]);
28+
29+
if ($count > 1) {
30+
elgg_register_menu_item('title', [
31+
'name' => 'sort_pages',
32+
'text' => elgg_echo('sort'),
33+
'icon' => 'sort',
34+
'href' => elgg_http_add_url_query_elements('ajax/form/static/sort', [
35+
'container_guid' => $group->guid,
36+
]),
37+
'class' => ['elgg-button', 'elgg-button-action', 'elgg-lightbox'],
38+
]);
39+
}
40+
}
1641
}
1742

1843
$ignore_access = $can_write ? ELGG_IGNORE_ACCESS : 0;
1944

20-
$body = elgg_call($ignore_access, function() use ($group) {
21-
return elgg_list_entities([
45+
$body = elgg_call($ignore_access, function() use ($group, $manual_sorting_enabled) {
46+
$options = [
2247
'type' => 'object',
2348
'subtype' => \StaticPage::SUBTYPE,
2449
'metadata_name_value_pairs' => [
@@ -30,7 +55,18 @@
3055
'direction' => 'asc',
3156
],
3257
'no_results' => elgg_echo('static:admin:empty'),
33-
]);
58+
];
59+
60+
if ($manual_sorting_enabled) {
61+
$options['sort_by'] = [
62+
'property' => 'order',
63+
'direction' => 'asc',
64+
'join_type' => 'left',
65+
'signed' => true,
66+
];
67+
}
68+
69+
return elgg_list_entities($options);
3470
});
3571

3672
echo elgg_view_page(elgg_echo('static:groups:title'), [
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
/**
3+
* Configure group specific static settings
4+
*/
5+
6+
$group = elgg_extract('entity', $vars);
7+
8+
$checked = false;
9+
$help = null;
10+
if ($group instanceof \ElggGroup) {
11+
$checked = (bool) $group->getPluginSetting('static', 'enable_manual_sorting', false);
12+
$help = elgg_view_url(elgg_generate_url('collection:object:static:group', ['guid' => $group->guid]), elgg_echo('static:groups:title'));
13+
}
14+
15+
$content = elgg_view_field([
16+
'#type' => 'switch',
17+
'#label' => elgg_echo('static:groups:edit:enable_manual_sorting'),
18+
'#help' => $help,
19+
'name' => 'settings[static][enable_manual_sorting]',
20+
'value' => $checked,
21+
]);
22+
23+
echo elgg_view_module('info', elgg_echo('collection:object:static'), $content);

views/default/widgets/static_groups/content.php

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313

1414
$ignore_access = $group->canWriteToContainer(0, 'object', \StaticPage::SUBTYPE) ? ELGG_IGNORE_ACCESS : 0;
1515
echo elgg_call($ignore_access, function () use ($group) {
16-
17-
$entities = elgg_get_entities([
16+
$options = [
1817
'type' => 'object',
1918
'subtype' => \StaticPage::SUBTYPE,
2019
'metadata_name_value_pairs' => [
@@ -26,22 +25,19 @@
2625
'property' => 'title',
2726
'direction' => 'asc',
2827
],
29-
]);
30-
31-
if (empty($entities)) {
32-
return elgg_echo('static:admin:empty');
33-
}
34-
35-
$ordered_entities = [];
36-
foreach ($entities as $index => $entity) {
37-
$order = $entity->order;
38-
if (empty($order)) {
39-
$order = (1000000 + $index);
40-
}
41-
42-
$ordered_entities[$order] = elgg_view('object/static/widget', ['entity' => $entity]);
28+
'item_view' => 'object/static/widget',
29+
'no_results' => elgg_echo('static:admin:empty'),
30+
];
31+
32+
$manual_sorting_enabled = (bool) $group->getPluginSetting('static', 'enable_manual_sorting', false);
33+
if ($manual_sorting_enabled) {
34+
$options['sort_by'] = [
35+
'property' => 'order',
36+
'direction' => 'asc',
37+
'join_type' => 'left',
38+
'signed' => true,
39+
];
4340
}
4441

45-
ksort($ordered_entities);
46-
return implode($ordered_entities);
42+
return elgg_list_entities($options);
4743
});

0 commit comments

Comments
 (0)