Download the PHP package phpfacile/chat-db without Composer
On this page you can find all versions of the php package phpfacile/chat-db. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpfacile/chat-db
More information about phpfacile/chat-db
Files in phpfacile/chat-db
Package chat-db
Short Description Implementation of the phpfacile/chat interface (aimed to provide a chat/messenger service) with a database as storage
License MIT
Homepage https://github.com/phpfacile/chat-db
Informations about the package chat-db
PHPFacile! Chat-Db
This is an implementation of the phpfacile/chat interface using a database as a storage.
Installation
At the root of your project type
Or add "phpfacile/chat-db": "^1.0" to the "require" part of your composer.json file
Your database must contain a table "chat_messages" with (at least) the following fields:
- id: integer auto increment
- msg: string
- user_id: integer or string
- channel_id: integer or string
- insertion_datetime_utc: datetime or string
REM: In the current version table and field names are not configurable
Example of table creation query with SQLite (for test purpose only)
Example of table creation query with MySQL
Usage
Step 1 : Adapter instanciation
Instanciate a Zend Adapter to allow a connexion to a database.
Example with SQLite (for test purpose only)
Example with MySQL
Step 2 : ChatChannelService instanciation
REM: You might have to overwrite the default ChatChannelService so as to control user accesses. (Cf. below)
Step 3 : ChatService instanciation
Step 4 : Post or get messages or messages information
addMessage
You can store add a new message to a chat channel by providing a text, a channel id and a user id to the addMessage() method.
REM: This method will not check whether the $channelId or the $userId (already) exists
getMessages
You can retrieve all the messages (and its metadata) from a chat channel by providing a channel id and a user id to the getMessages() method.
This will return an array of StdClass containing both the text and associated data of the messages.
getLastUserMessageDateTimeUTC
You can also retrieve the date/time (in UTC) of the last message posted by a user in a chat channel by providing a channel id and a user id to the getLastUserMessageDateTimeUTC() method.
This will return a date in string format (Y-m-d H:i:s) like '2018-12-25 22:30:10' or null if no message was posted.
Advanced feature
You're invited to overwrite the default ChatChannelService (or have you own ChatChannelServiceInterface implementation) so as to write your own user access rights management.
If ever you want you can store additionnal data with the posted message by providing an associative array as a 4th parameter of addMessage(). The array keys must match (existing) table field names.