panlatent/element-messages

Element Messages for CraftCMS

0.1.1 2019-07-02 03:39 UTC

This package is auto-updated.

Last update: 2024-11-10 17:43:53 UTC


README

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License Craft CMS Yii2

Element messages help your Craft application create messages between two elements and use any one element as the message content. It makes it easy to build relationships between three elements and provides a powerful way to query.We can customize the types of rich and flexible messages by sender element type, target element type and content element type. This relationship is stored in another database table, which helps reduce the data size of the Craft element relationship table. This should be a better solution for sending the same content multiple times (e.g. group sending).

Requirements

This plugin requires Craft CMS 3.1 or later.

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require panlatent/element-messages
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Element Messages.

Usages

Create a message

<?php

use panlatent\elementmessages\Plugin;

$messages = Plugin::getInstance()->getMessages();

$message = $messages->createMessage([
   'senderId' => 1,
   'targetId' => 2,
   'contentId' => 3,
]);

$messages->saveMessage($message);

Messages Query

<?php

use panlatent\elementmessages\Plugin;

$messages = Plugin::getInstance()->getMessages();

$results = $messages->findMessages([
    'senderId' => 1
]);


$total = $messages->getTotalMessages([
    'senderId' => 1,
    'targetId' => 2,
]);

For more query conditions, please refer to panlatent\elementmessages\models\MessageCriteria.

Documentation

License

The Element Messages is open-sourced software licensed under the MIT license.