Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 3, 2024
1 parent 74169bc commit 6918130
Show file tree
Hide file tree
Showing 22 changed files with 106 additions and 109 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Site announcements
==================

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/site_announcements/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/site_announcements/v/stable.svg)](https://packagist.org/packages/coldtrick/site_announcements)
[![License](https://poser.pugx.org/coldtrick/site_announcements/license.svg)](https://packagist.org/packages/coldtrick/site_announcements)
Expand Down
1 change: 0 additions & 1 deletion classes/ColdTrick/SiteAnnouncements/Access.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Access {
* @return null|array
*/
public static function userWriteCollections(\Elgg\Event $event): ?array {

$input_params = $event->getParam('input_params');
if (empty($input_params) || !is_array($input_params)) {
return null;
Expand Down
8 changes: 5 additions & 3 deletions classes/ColdTrick/SiteAnnouncements/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace ColdTrick\SiteAnnouncements;

use Elgg\I18n\DateTime;

/**
* Cron listener
*/
Expand All @@ -15,21 +17,21 @@ class Cron {
* @return void
*/
public static function cleanupExpiredAnnouncements(\Elgg\Event $event): void {

$archive_cleanup = (int) elgg_get_plugin_setting('archive_cleanup', 'site_announcements');
if ($archive_cleanup < 1) {
return;
}

$time = (int) $event->getParam('time', time());
/* @var $dt DateTime */
$dt = $event->getParam('dt', new \DateTime());

$options = [
'type' => 'object',
'subtype' => \SiteAnnouncement::SUBTYPE,
'limit' => false,
'metadata_name_value_pairs' => [
'name' => 'enddate',
'value' => $time - ($archive_cleanup * 24 * 60 * 60),
'value' => $dt->modify("-{$archive_cleanup} days")->getTimestamp(),
'operand' => '<',
'type' => ELGG_VALUE_INTEGER,
],
Expand Down
2 changes: 1 addition & 1 deletion classes/ColdTrick/SiteAnnouncements/Gatekeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __invoke(Request $request): void {
/**
* Check if a user is an editor
*
* @param \ElggUser $user (optional) the user to check, defaults to loggedin user
* @param null|\ElggUser $user (optional) the user to check, defaults to logged-in user
*
* @return bool
*/
Expand Down
1 change: 0 additions & 1 deletion classes/ColdTrick/SiteAnnouncements/Menus/AdminHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public static function register(\Elgg\Event $event): ?MenuItems {
'name' => 'site_announcements',
'text' => elgg_echo('site_announcements'),
'href' => elgg_generate_url('collection:object:site_announcement:all'),
'is_trusted' => true,
'parent_name' => 'administer',
]);

Expand Down
5 changes: 0 additions & 5 deletions classes/ColdTrick/SiteAnnouncements/Menus/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Filter {
* @return null|MenuItems
*/
public static function register(\Elgg\Event $event): ?MenuItems {

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

Expand All @@ -27,7 +26,6 @@ public static function register(\Elgg\Event $event): ?MenuItems {
'text' => elgg_echo('site_announcements:filter:active'),
'href' => elgg_generate_url('collection:object:site_announcement:all'),
'priority' => 100,
'is_trusted' => true,
'selected' => $event->getParam('filter_value') === 'all',
]);

Expand All @@ -36,7 +34,6 @@ public static function register(\Elgg\Event $event): ?MenuItems {
'text' => elgg_echo('site_announcements:filter:archive'),
'href' => elgg_generate_url('collection:object:site_announcement:archive'),
'priority' => 200,
'is_trusted' => true,
]);

if (Gatekeeper::isEditor()) {
Expand All @@ -45,15 +42,13 @@ public static function register(\Elgg\Event $event): ?MenuItems {
'text' => elgg_echo('site_announcements:filter:scheduled'),
'href' => elgg_generate_url('collection:object:site_announcement:scheduled'),
'priority' => 300,
'is_trusted' => true,
]);

$returnvalue[] = \ElggMenuItem::factory([
'name' => 'editors',
'text' => elgg_echo('site_announcements:filter:editors'),
'href' => elgg_generate_url('collection:object:site_announcement:editors'),
'priority' => 400,
'is_trusted' => true,
]);
}

Expand Down
1 change: 0 additions & 1 deletion classes/ColdTrick/SiteAnnouncements/Menus/Footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public static function register(\Elgg\Event $event): ?MenuItems {
'icon' => 'bullhorn',
'text' => elgg_echo('site_announcements'),
'href' => elgg_generate_url('collection:object:site_announcement:all'),
'is_trusted' => true,
]);

return $returnvalue;
Expand Down
1 change: 0 additions & 1 deletion classes/ColdTrick/SiteAnnouncements/Menus/UserHover.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class UserHover {
* @return null|MenuItems
*/
public static function register(\Elgg\Event $event): ?MenuItems {

if (!elgg_is_admin_logged_in()) {
return null;
}
Expand Down
1 change: 1 addition & 0 deletions classes/ColdTrick/SiteAnnouncements/Seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function seed() {

// undo some seeding stuff
unset($entity->title);
unset($entity->tags);

$this->advance();
}
Expand Down
3 changes: 1 addition & 2 deletions classes/SiteAnnouncement.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ public function markAsRead(): bool {
*
* @return string
*/
public function getMessageTypeIconName() {

public function getMessageTypeIconName(): string {
switch ($this->announcement_type) {
case 'attention':
return 'exclamation-triangle';
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/site_announcements/issues"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
}
}
2 changes: 1 addition & 1 deletion composer.lock

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

92 changes: 48 additions & 44 deletions views/default/forms/site_announcements/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,57 @@
'value' => elgg_extract('description', $vars),
]);

echo '<div>';
echo '<label for="startdate">' . elgg_echo('site_announcements:edit:startdate') . '</label>';
echo elgg_view('input/date', [
'name' => 'startdate',
'value' => elgg_extract('startdate', $vars),
'timestamp' => true,
'class' => 'mhs elgg-col-1of5',
]);
echo '@';
echo elgg_view('input/select', [
'name' => 'starthour',
'value' => elgg_extract('starthour', $vars),
'options' => $hour_options,
'class' => 'mhs',
]);
echo ':';
echo elgg_view('input/select', [
'name' => 'startmins',
'value' => elgg_extract('startmins', $vars),
'options' => $mins_options,
'class' => 'mls',
echo elgg_view_field([
'#type' => 'fieldset',
'#label' => elgg_echo('site_announcements:edit:startdate'),
'align' => 'horizontal',
'fields' => [
[
'#type' => 'date',
'name' => 'startdate',
'value' => elgg_extract('startdate', $vars),
'timestamp' => true,
],
[
'#type' => 'select',
'name' => 'starthour',
'value' => elgg_extract('starthour', $vars),
'options' => $hour_options,
],
[
'#type' => 'select',
'name' => 'startmins',
'value' => elgg_extract('startmins', $vars),
'options' => $mins_options,
],
],
]);
echo '</div>';

echo '<div>';
echo '<label for="enddate">' . elgg_echo('site_announcements:edit:enddate') . '</label>';
echo elgg_view('input/date', [
'name' => 'enddate',
'value' => elgg_extract('enddate', $vars),
'timestamp' => true,
'class' => 'mhs elgg-col-1of5',
]);
echo '@';
echo elgg_view('input/select', [
'name' => 'endhour',
'value' => elgg_extract('endhour', $vars),
'options' => $hour_options,
'class' => 'mhs',
]);
echo ':';
echo elgg_view('input/select', [
'name' => 'endmins',
'value' => elgg_extract('endmins', $vars),
'options' => $mins_options,
'class' => 'mls',
echo elgg_view_field([
'#type' => 'fieldset',
'#label' => elgg_echo('site_announcements:edit:enddate'),
'align' => 'horizontal',
'fields' => [
[
'#type' => 'date',
'name' => 'enddate',
'value' => elgg_extract('enddate', $vars),
'timestamp' => true,
],
[
'#type' => 'select',
'name' => 'endhour',
'value' => elgg_extract('endhour', $vars),
'options' => $hour_options,
],
[
'#type' => 'select',
'name' => 'endmins',
'value' => elgg_extract('endmins', $vars),
'options' => $mins_options,
],
],
]);
echo '</div>';

echo elgg_view_field([
'#type' => 'select',
Expand Down
19 changes: 0 additions & 19 deletions views/default/js/site_announcements/announcement.js

This file was deleted.

16 changes: 7 additions & 9 deletions views/default/object/site_announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
'class' => [
"site-announcement-{$announcement_type}",
],
'link' => elgg_view('output/url', [
'icon' => 'delete',
'text' => false,
'title' => elgg_echo('site_announcements:menu:entity:mark'),
'href' => elgg_generate_action_url('site_announcements/mark', ['guid' => $entity->guid]),
'class' => 'site-announcements-mark',
]),
];

// error, success, warning, help, notice
Expand All @@ -39,15 +46,6 @@
break;
}

$mark = elgg_view('output/url', [
'icon' => 'delete',
'text' => false,
'title' => elgg_echo('site_announcements:menu:entity:mark'),
'href' => elgg_generate_action_url('site_announcements/mark', ['guid' => $entity->guid]),
'class' => 'site-announcements-mark',
]);
$content = elgg_view_image_block('', $content, ['image_alt' => $mark]);

echo elgg_view_message($message_type, $content, $message_options);
} else {
$imprint = [
Expand Down
3 changes: 1 addition & 2 deletions views/default/plugins/site_announcements/settings.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

/* @var $plugin ElggPlugin */
/* @var $plugin \ElggPlugin */
$plugin = elgg_extract('entity', $vars);

echo elgg_view_field([
Expand All @@ -10,5 +10,4 @@
'name' => 'params[archive_cleanup]',
'value' => $plugin->archive_cleanup,
'min' => 0,
'max' => 9999,
]);
3 changes: 2 additions & 1 deletion views/default/resources/site_announcements/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

// get entity
$guid = (int) elgg_extract('guid', $vars);
elgg_entity_gatekeeper($guid, 'object', \SiteAnnouncement::SUBTYPE);
elgg_entity_gatekeeper($guid, 'object', \SiteAnnouncement::SUBTYPE, true);

/* @var $entity \SiteAnnouncement */
$entity = get_entity($guid);

// breadcrumb
Expand Down
2 changes: 0 additions & 2 deletions views/default/resources/site_announcements/editors.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* List all announcement editors
*/

use Elgg\Database\QueryBuilder;

// breadcrumb
elgg_push_collection_breadcrumbs('object', \SiteAnnouncement::SUBTYPE);

Expand Down
17 changes: 17 additions & 0 deletions views/default/site_announcements/announcement.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'jquery';
import Ajax from 'elgg/Ajax';

$(document).on('click', '.site-announcements-mark', function(event) {
event.preventDefault();

var ajax = new Ajax(false);

var $message = $(this).closest('.elgg-message');
$message.slideToggle();

ajax.action($(this).attr('href'), {
success: function() {
$message.remove();
}
});
});
Loading

0 comments on commit 6918130

Please sign in to comment.