Yii 1.1: private-messaging

This Yii Framework module allows you to add quickly private messaging into your application
54 followers

Messages

This Yii Framework module allows you to add quickly private messaging into your application.

GitHub - https://github.com/weavora/yii-messages

Features included:

  • basic private messaging functionality,
  • autosuggest,
  • custom themes support,
  • simple integration

Requirements

This module was tested with 1.1.8 but should work with any version.

MessageModule requires a couple of methods to be defined in your User model (see below):

If you want to use modules' default layout make sure that it is defined via double slash ("//"). Usually default layout is defined in basic controller class.

// class Controller
public $layout='//layouts/column1';

Configuration

Create necessary tables using SQL file - data/message.sql

There are config settings of modules section below:

return array(
    'modules' => array(
        'message' => array(
            'userModel' => 'User',
            'getNameMethod' => 'getFullName',
            'getSuggestMethod' => 'getSuggest',
        ),
    ),
);

In order to use module you should specify User model that is used in the application MessageModule::userModel.

If necessary, specify relations for Sender and Receiver MessageModule::senderRelation and MessageModule::receiverRelation.

'receiverRelation' => array(
    CActiveRecord::BELONGS_TO, 
    'MyUserModel',
    '',
    'on' => 'MyUserModel.my_custom_id = receiver_id'
 )

If you do not use Yii assets build-in functionality you will need to connect jQuery and jQuery UI(with styles) libraries. You can find them in modules folder.

Insert items into zii.widgets.CMenu array (protected/views/layouts/main.php)

array(
    'url' => Yii::app()->getModule('message')->inboxUrl,
    'label' => 'Messages' .
        (Yii::app()->getModule('message')->getCountUnreadedMessages(Yii::app()->user->getId()) ?
            ' (' . Yii::app()->getModule('message')->getCountUnreadedMessages(Yii::app()->user->getId()) . ')' : ''),
    'visible' => !Yii::app()->user->isGuest),

Examples

// config
return array(
'modules' => array(
    'message' => array(
        'userModel' => 'User',
        'getNameMethod' => 'getFullName',
        'getSuggestMethod' => 'getSuggest',
        ),
    ),
);

// class User
public function getFullName() {
    return $this->username;
}

public function getSuggest($q) {
    $c = new CDbCriteria();
    $c->addSearchCondition('username', $q, true, 'OR');
    $c->addSearchCondition('email', $q, true, 'OR');
    return $this->findAll($c);
}

Custom Views

If you are not satisfied with the standard views you can easily replace them with your own just linking path to their folder through MessageModule::viewPath.

//config
return array(
    'modules' => array(
        'message' => array(
            ...
            // for app/protected/views/messagesModuleCustom
            'viewPath' => '//messagesModuleCustom',
        ),
    ),
);

// app/protected/views/messagesModuleCustom directory listing
..
compose.php
inbox.php
sent.php
view.php

Direct messages

It is possible to determine each recipient by URL (for example, under user profile page). To do this, you should add his id at the end of URL.

http://example.com/message/compose/1

In this case recipients' name will be automatically inserted in the form.

Total 18 comments

#17282 report it
VictorG at 2014/05/19 11:07am
Translate Messages

In case anyone is still wondering how to translate the messages:

  1. Create a directory called "messages" within the module's directory.
  2. Create a directory with the name of the language you want to translate to, in my case "es" (spanish).
  3. Create in this last directory a file named message.php.
  4. Put in that file the messages to be translated.

Here is the content of my "message.php" file:

return array(
    'Body'=>'Cuerpo',
    'compose'=>'redactar',
    'Compose'=>'Redactar',
    'Compose New Message'=>'Redactar Nuevo Mensaje',
    'Date'=>'Fecha',
    'Deleted By'=>'Eliminado Por',
    'Delete Selected'=>'Eliminar Seleccionados',
    'Fields with <span class="required">*</span> are required.'=>'Campos con <span class="required">*</span> son obligatorios.',
    'From'=>'De',
    'inbox'=>'entrada',
    'Inbox'=>'Entrada',
    'Messages'=>'Mensajes',
    'Receiver'=>'Destinatario',
    'Send'=>'Enviar',
    'Sender'=>'Remitente',
    'sent'=>'enviados',
    'Sent'=>'Enviados',
    'Subject'=>'Asunto',
    'To'=>'A',
);
#16771 report it
chandu mohan at 2014/03/26 10:30am
Awsome..

saved a lot of time for me.. Thanks Weavora...

#16555 report it
darioo at 2014/03/05 10:28am
how to use MessageModule::t

I'm using it to translate my messages, but not sure how to use it, where to put my translated messages?

#14513 report it
darioo at 2013/08/19 02:13pm
[SOLVED] auto suggest doesn't work

Auto suggestion wasn't working for me, but I fixed it. I went to jQuery UI website and downloaded their newest version of UI (http://jqueryui.com/)

Then I altered

protected/view/layouts/main.php

and between "head" tags just included that donwloaded jQueryUI javascript file.

Then i want to

\protected\modules\message\views\message\default\_suggest.php

and I commented this line

$cs->registerScriptFile($baseUrl.'/js/jquery-ui-1.8.16.custom.min.js');
#12923 report it
Supercharged at 2013/04/20 07:41pm
Trouble using autocomplete (Like user below)

Autocomplete issue update: message/controllers/SuggestController.php

Line6: $q = Yii::app()->request->getParam('name_startsWith');

When I change to $q = Yii::app()->request->getParam('');

I get a popup list in the top left corner of my browser (firefox and chromium) with the username fields from my database. (not filtered by receiver text) but when i select a value it inputs the corresponding receiver_id value and the form submits properly.

#12922 report it
Supercharged at 2013/04/20 07:22pm
Trouble using autocomplete (Like user below)

First of all, I would like to say that this is a great extension that is going to save me many hours :) I appreciate the contribution. Hoping for a little help here.

I am using the Yii User module (yii-user)

Everything is working, and the direct URL eg: ...message/compose/1 which prepopulates the receiver wtih value admin from user.username. I am able to send a message this way.

However, when typing in the receiver name 'admin' and sending, I get validation error: receiver name must be specified.

Also, while typing in the receiver field, the spining icon spins but does not lookup and find the value. Can you help. I am wondering if i need to configure the relations? But Everything else seems to work so I'm stuck.

Can someone help us out? Thanks!

#12495 report it
cappadochian at 2013/03/23 07:19pm
autosuggest not working

hi!

very nice extension, my only problem is, that autosuggest is not working. firebug says the data is found, in json it's there, but it doesn't show up, the small loading icon keeps turning around. I'm also using bootstrap, can it be the problem? is there a workaround for this?

thanks a lot! c

#12494 report it
cappadochian at 2013/03/23 04:00pm
autosuggest not working

hi!

very nice extension, my only problem is, that autosuggest is not working. firebug says the data is found, in json it's there, but it doesn't show up, the small loading icon keeps turning around. I'm also using bootstrap, can it be the problem? is there a workaround for this?

thanks a lot! c

#11747 report it
DenizB at 2013/01/31 02:20pm
Direct message

Hi everybody.

I couldn't send direct message through "/message/compose/1" method. Is there any other way to send direct message ?

#11286 report it
Aneesh Asokan at 2013/01/03 01:55pm
Implementation steps

Please specify the configuration and examples in details..?

#11197 report it
SilvQ at 2012/12/25 02:47pm
Receiver username

I have a bug with Receiver username then i try to send a message i wrote into Receiver field that user i whant to send message bu i got error, Receiver cannot be blank.

<?php echo CHtml::textField('receiver', $receiverName,array('size'=>35,'maxlength'=>128, 'class'=>'ui-autocomplete-input')) ?>
<?php echo $form->hiddenField($model,'receiver_id'); ?>
<?php echo $form->error($model,'receiver_id'); ?>

There is bug?

#10917 report it
basem at 2012/12/03 04:27am
Cool Extension

hi,

I like the private messaging extension, it's been done in a standard way.... but I wish if you could improve it to be AJAX-based and facebook alike :)

take care!

#10272 report it
kamankily at 2012/10/16 09:33pm
Cool

Cool extension, thanks

#7789 report it
jiaming at 2012/04/18 02:33pm
Nice but a small error.

Each time I send the message to myself. I will be not able to open the sent page then. It appears:

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Users.id' in 'where clause'. The SQL statement executed was: SELECT receiver.id AS t1_c0, receiver.username AS t1_c1, receiver.password AS t1_c2, receiver.email AS t1_c3, receiver.activkey AS t1_c4, receiver.createtime AS t1_c5, receiver.lastvisit AS t1_c6, receiver.superuser AS t1_c7, receiver.status AS t1_c8, receiver.fb_uid AS t1_c9 FROM tbl_users receiver WHERE (Users.id = receiver_id)

Any ideas?

#7386 report it
Sampa at 2012/03/19 04:20pm
Example view design.

I must say, now when I have gone thrue it some more, this is just pure quality.

Simple,yet effective and yes, just nice.

Keep doing extentions,weovora!:)

Here Is how I did the layout: http://dc104.2shared.com/download/1NophlQX/message-compose.png?tsid=20120319-201651-1025a150

Sharing just to give inspiration

#7384 report it
Sampa at 2012/03/19 07:34am
Testing it:)

This one is cool, It worked flawless right away, adding a table prefix was no problem either.

The fancy bootstrap view files was a huge win! BUT together with the Yii-Bootstrap extention some of my bootstraped contents (that I had before adding this module) got bugged. So currently I'm testing without the bootstrap css file included in the fancy view folder.

And well, all looks okey:) So, thank you very much for this. If I notice something more I will add another comment.

#5945 report it
Weavora Team at 2011/11/28 12:14am
Thanks.

Hi perochak, Thanks for feedback. Did you find it useful for your project? Any ideas on how to improve it?

Regards, Mike

#5938 report it
PeRoChAk at 2011/11/27 12:42pm
Thanks

Thanks - Nice work

Leave a comment

Please to leave your comment.

Create extension