Mahana Messaging library

The Mahana Messaging Library is something I wrote a few years back to serve as the backend for an internal messaging system. (Please note: This is not an error message library. If you are looking for something like that for Codeigniter, I recommend Adam Jackett's Codeigniter Message library)

Setup is quite simple, but I still get a few questions from time to time, so I thought I'd write out a little more verbose instruction set. First thing, of course, is to get a copy of the files, either from Github or Composer

There are five files:

  • mahana.sql -- run this sql script in your database. Note that these tables are all InnoDB - Mahana uses transactions

  • config/mahana.php -- you will need to set up your existing users table information here, following the sample data style which I'll outline further

  • language/english/mahana_lang.php -- all error and success messages can be changed here, or multilingual support can be added by creating your own language files as needed

  • models/mahana_model.php -- the database model

  • libraries/Mahana_messaging -- the main library file

The sql:

The sql file contains 4 tables, all prefixed with "msg_" (there is currently no way to change this prefix, but it would be a simple enough thing to add). A thread is what binds all the messages & participants together. The subject line is fixed for all messages, and so is stored here.

The messages table links to a thread, and include message body, priority, and who origininated the message (sender). Note that it does NOT include recipients; that is for the participants.

The participants table links the users to the thread. All participants on a message thread are essentially equal - you may refer to the message itself to see who sent it out, vs. recipients. There is one additional field here that is a nice feature of this library - the table also has "cdate", when the participant joined the thread. This allows you to specify if a participant should be included on the entire conversation all the way from the beginning, or only new messages since they join.

The status table links each user to each message to show if they have read or archived it.

The configuration file:

All of the constants used for priorities, statuses & message ids are listed here. Additionally, this is how you link the library to your existing users table.

The library doesn't come with its own users table; it is intended to drop into your existing application or authentication system. Therefore, use the first three configs to list the table name, primary key and how you'd like the names display

The library:

Using the library is quite straightforward. Functions asking for $status_id or $priority should use constants from the config file. Results are returned in the following array:

	$status['err']		1= error, 0 = no error
	$status['code']		a specific code for that return value, found in config/mahana.php
	$status['msg']		a configurable message, found in language/english/mahana_lang.php
	$status['retval']	(optional) returned array of data

This array is consistent across all functions, and so allows you to easily json_encode for ajax applications as well as standard forms.

I'm happy to entertain any pull requests or ideas for enhancements - please use the github issues page at Mahana-Messaging-library-for-CodeIgniter/issues


Contact me