oveleon / contao-member-notification
Contao的会员通知扩展。
1.0.11
2023-05-16 12:21 UTC
Requires
- php: >=7.1
- contao/core-bundle: ^4.9
Requires (Dev)
- contao/manager-plugin: ^2.0
Conflicts
- contao/core: *
- contao/core-bundle: 4.4.1
- contao/manager-plugin: <2.0 || >=3.0
README
此扩展允许添加通知以告知成员有关某些活动的信息。
添加通知
您可以直接通过成员区域的新铃铛图标(🔔)从后端添加通知。
为了能够对某些活动做出反应,也可以通过PHP创建通知。
use Oveleon\ContaoMemberNotification\MemberNotificationModel; MemberNotificationModel::add(int $memberId, string $title, string $teaser, string $jumpTo);
列出通知
为了输出通知,提供了一个模块,该模块可以在三种不同模式下输出通知
read
:仅显示已读通知
unread
:仅显示尚未阅读的通知
all
:显示所有通知
在“未读”模式下,还显示一个额外的按钮以标记消息为“已读”。
样式和定制
动态列表
动态列表定义了一个列表,当点击通知时,通知将从列表中移除(通常是未读模式)。这种情况通常发生在成员可以通过铃铛或类似的方式将通知标记为已读时。
在模板 mod_memberNotification.html5
中可以影响通知项目在点击后是否被移除。为了不应用此行为,必须删除HTML属性 data-mnc-delete-on-mark
。
删除此HTML属性后,项目将不再被移除,而是在点击后添加类 read
。
显示“无新消息”项
自版本 1.0.4
以来,该项目始终显示。结合动态列表,可以按照以下方式样式化该项目,以仅在没有任何新消息时显示它
.notifications .message{ display: none; } .notifications .message:only-child{ display: block; }
如果应删除HTML属性 data-mnc-delete-on-mark
,则可以在模板中使用以下查询来影响消息的输出
<?php if($this->hasNotifications): ?> <div class="message"> <?=$this->message?> </div> <?php endif; ?>
高级使用
可以通过事件 mnc-count
捕获更多特殊之处。此事件在通知被标记为已读时始终触发。
window.addEventListener('mnc-count', function (e) { console.log(e.detail); // Output: // { // element: DOMElement, // counter: DOMElement, // currentCount: Number // } }, false);
钩子
// Hook: beforeParseMemberNotification (Can be used to manipulate the data query) public function onBeforeParseMemberNotification(int $read, ModuleMemberNotification $module): ?MemberNotificationModel { // Custom logic }
// Hook: parseMemberNotification (Can be used to change the template output) public function onParseMemberNotification(MemberNotificationModel $objNotifications, ModuleMemberNotification $module): void { // Custom logic }