Message

The messages are stored in the database and the Message object will display them. It will fully format the HTML around it and can also be merge with an array of data, like with the email template.

The closing of the Messages is recorded in the message_user. They have an expiration date in the closed_until variable. Passed that date the message will display again. The close duration from from the message and its the “interval” format from the date_add in mysql. This mean the message.close_duration can be: 1 month, 2 week, 5 day, 20 year….. (yes, its singulare don't ask).

Message uses $GLOBALS['cfg_lang'] to display the message in the current language. If no message in that language is found it will fall back to en_US.

Variables

Message

Main table that store all the messages.

+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| idmessage      | int(10)      | NO   | PRI | NULL    | auto_increment | 
| key_name       | varchar(150) | NO   |     |         |                | 
| content        | mediumtext   | NO   |     |         |                | 
| language       | varchar(50)  | NO   |     |         |                | 
| context        | varchar(60)  | NO   |     |         |                | 
| can_close      | varchar(3)   | NO   |     | yes     |                | 
| close_duration | varchar(20)  | NO   |     | 1 month |                | 
| plan           | varchar(10)  | YES  |     | all     |                | 
+----------------+--------------+------+-----+---------+----------------+

message_user

Record per user if the user as closed a message.

+----------------+--------------+------+-----+---------+----------------+
| Field          | Type         | Null | Key | Default | Extra          |
+----------------+--------------+------+-----+---------+----------------+
| idmessage_user | int(10)      | NO   | PRI | NULL    | auto_increment | 
| key_name       | varchar(150) | NO   | MUL |         |                | 
| iduser         | int(10)      | NO   |     |         |                | 
| closed_until   | datetime     | YES  |     | NULL    |                | 
+----------------+--------------+------+-----+---------+----------------+

few Methods

To display messages you can use either: getFormatedMessage() or displayMessage();

getFormatedMessage()

Will return a string with the HTML to display the message.

displayMessage()

Will directly echo the HTML returned by getFormatedMessage();

Examples

Simple example

   $message = new Message();
   $message->getMessage("welcome");
   $message->displayMessage();

Fecth the message welcome and display it.

Example without database entry

   $message = new Message();
   $message->setContent(_("Display this important message"));
   $message->displayMessage();

We use here the gettext _( ) function to make sure the message will be translated.

Message with Merge data

This example will show how to display messages with dynamic or calculated data. We use fieldname in [] to define variables that will be replaced with data when the message is displayed.

Message object stored in the database table:

    idmessage: 3
    key_name: welcome client portal
    content: [user_firstname] [user_lastname] has opened you an access to [user_company] portal and would like to share files and messages with you.
             Bookmark this page so you can come back to it anytime you need to send a message or upload a file for [user_firstname]
    language: en_US
    context: 
    can_close: no
    close_duration: 1 month

To display this message:

    $msg = new Message();
    $msg->setData(Array("user_firstname" => $_SESSION['do_User']->firstname, 
			"user_lastname" => $_SESSION['do_user']->lastname,
			"user_company" => $_SESSION['do_user']->company));
    if ($msg->getMessage("welcome client portal")) {
        echo $msg->getFormatedMessage() ;
    }

The example will personalize the message with the currently sign-in user information and display it.

When the variable message→can_close = 'yes' the message will display a little close link & icon. if set to 'no' then the message cannot be closed.

Message in context

A usefull feature is the context feature. You can group messages on context and display them in multiple places. All messages with the same context will display randomly. When a message as been close if there is an other message for that context it will only display the next time the user logs in.

Example of message by context:

    $msg = new Message(); 
    if ($msg->getMessageFromContext("project tasks")) {
        $msg->displayMessage();
    }

This will pick a message with the Context set as project tasks that is not already closed by the user.

 
ofuzobject/message.txt · Last modified: 2010/09/04 10:20 by philippe
 
Copyright © SQLFusion LLC all rights reserved