grcs / internal-messages-bundle
GrcsInternalMessages - 为您的Symfony 2应用程序提供的内部消息系统
Requires
- php: >=5.3.0
- symfony/framework-bundle: >=2.1.0
This package is auto-updated.
Last update: 2024-09-29 04:21:19 UTC
README
受FOSMessageBundle (http://github.com/FriendsOfSymfony/FOSMessageBundle)启发
许可证
see LICENSE
安装
- 将InternalMessagesBundle添加到您的vendor/目录
通过composer
"require": {
...
"grcs/internal-messages-bundle": "dev-master"
...
}
-
将InternalMessagesBundle添加到您的应用程序内核
// app/AppKernel.php
public function registerBundles() { return array( // ... new Grcs\InternalMessagesBundle\GrcsInternalMessagesBundle(), // ... ); }
-
配置您的项目
app/config/config.yml
grcs_internal_messages: entity: message_class: 'Grcs\FrontendBundle\Entity\InternalMessages' user_class: 'Grcs\SecurityBundle\Entity\User' view: date_format: 'Y/m/d H:i' #format for createdAt DateTime truncate_len: 50 #(int|false) truncate text body in the list sort_by_created: 'desc' #(asc|desc|false) sort_by_is_read: false #(asc|desc|false) knp_pagination_enable: true #(true|false) enable knp pagination on the page knp_pagination_limit_per_page: 30 #(int|null) knp pagination limit per page templates: layout: 'GrcsInternalMessagesBundle::layout.html.twig' view: 'GrcsInternalMessagesBundle::view.html.twig' create: 'GrcsInternalMessagesBundle::create.html.twig' reply: 'GrcsInternalMessagesBundle::reply.html.twig' inbox: 'GrcsInternalMessagesBundle::inbox.html.twig' outbox: 'GrcsInternalMessagesBundle::outbox.html.twig' forms: new_message_form: factory: 'grcs.internal_messages.new_message_form.factory' type: 'grcs.internal_messages.new_message_form.type' handler: 'grcs.internal_messages.new_message_form.handler' name: 'message' reply_form: factory: 'grcs.internal_messages.reply_form.factory' type: 'grcs.internal_messages.reply_form.type' handler: 'grcs.internal_messages.reply_form.handler' name: 'reply'
-
更改您的'user_class'
// 例如 (!) src/Grcs/SecurityBundle/Entity/User.php use Grcs\InternalMessagesBundle\Model\ParticipantInterface; class User implements ParticipantInterface { // ... public function isCanSendMessageToUser(ParticipantInterface $user) { // 你可以在这里设置 '可以发送消息' 的逻辑 return true; }}
public function isCanReceiveMessageFromUser(ParticipantInterface $user) { // you can set 'can receive message' logic here return true; }
// ... }
-
创建/修改您的'message_class'。您可以在模型类中添加其他字段或方法。
// src/Your/Bundle/Entity/YourMessages.php // ... use Grcs\InternalMessagesBundle\Entity\Message as BaseMessages; // ... class YourMessages extends BaseMessages { // ... 并实现所有父方法 // ... }
或者
Copy Entity from vendor/grcs/internal-messages-bundle/Grcs/InternalMessagesBundle/Entity/YourMessage.php
to your Entity folder (src/Your/Bundle/Entity/YourMessages.php).
Change namespace Your\EntityNamespace\Entity and class name.
Change User targetEntity for $sender and $recipient. (Your\EntityNamespace\Entity\User)
Change Message targetEntity for $parentMessage. (Your\EntityNamespace\Entity\YourMessage)
- 注册路由
您可能希望包含内置的路由。
在YAML中
# app/config/routing.yml
internal_messages:
resource: '@GrcsInternalMessagesBundle/Resources/config/routing.xml'
prefix: /optional_routing_prefix
或者如果您更喜欢XML:
# app/config/routing.xml
<import resource="@GrcsInternalMessagesBundle/Resources/config/routing.xml"/>
模板
InternalMessagesBundle提供了一些twig函数:
{# template.html.twig #}
{# Get the number of new messages for the authenticated user #}
You have {{ grcs_internal_message_unread_count() }} new messages
{# Get the number of total messages in the inbox for the authenticated user #}
You have {{ grcs_internal_message_inbox_count() }} messages it the inbox
{# Get the number of total messages in the outbox for the authenticated user #}
You have {{ grcs_internal_message_outbox_count() }} messages it the outbox
{# Get allowed actions list for the message of this authenticated user #}
{% for action, value in grcs_internal_message_allowed_actions(message) %}
<a href="{{ path('grcs_internal_messages_' ~ action, { 'message_id' : message.id }) }}">
{{ action|trans() }}
</a>
{% endfor %}