Yii Framework Forum: [EXTENSION]: private-messaging - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION]: private-messaging This Yii Framework module allows you to add quickly private messaging Rate Topic: ***** 1 Votes

#1 User is offline   Weavora Team 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 141
  • Joined: 06-December 10

Posted 24 November 2011 - 05:44 AM

http://www.yiiframew...vate-messaging/

Guys, hope you'll find it useful.
0

#2 User is offline   Cade 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 04-July 12

Posted 04 July 2012 - 05:26 AM

Hi,
I'm fairly new to Yii but have years of PHP experience so I'm not finding it too tricky to run with it and implement some of the addons people have created.

I am however confused on how to implement the private-messaging module, which is a shame as it looks really cool from what I've read/seen.

Do you have any additional information not available here on Github.

Ideally a more step-by-step process on adding it to an existing Yii Project or even an example project running this module.

Thanks in advance for your time.

Cade


View PostWeavora Team, on 24 November 2011 - 05:44 AM, said:

http://www.yiiframew...vate-messaging/

Guys, hope you'll find it useful.

Regards,
Cade

Current Projects
You Do It List: http://youdoitlist.com.au
0

#3 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 04 July 2012 - 05:46 AM

View PostCade, on 04 July 2012 - 05:26 AM, said:

Hi,
I'm fairly new to Yii but have years of PHP experience so I'm not finding it too tricky to run with it and implement some of the addons people have created.

I am however confused on how to implement the private-messaging module, which is a shame as it looks really cool from what I've read/seen.

Do you have any additional information not available here on Github.

Ideally a more step-by-step process on adding it to an existing Yii Project or even an example project running this module.

Thanks in advance for your time.

Cade


I use this extension by following the instructions on the extension page, so they re complete and on step by step basis. But could you perhaps tell us where things goes wrong? any errors?any part you dont understand what It means?
0

#4 User is offline   Cade 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 04-July 12

Posted 04 July 2012 - 07:45 AM

View PostSampa, on 04 July 2012 - 05:46 AM, said:

I use this extension by following the instructions on the extension page, so they re complete and on step by step basis. But could you perhaps tell us where things goes wrong? any errors?any part you dont understand what It means?


Hi Sampa,
I loaded all of the files into my project/protected directory however I wasn't sure where the file "MessageModule.php" was meant to be loaded.

When trying to open one of the Controllers, say Inbox I got the following error:

Trying to get property of non-object 
$this->userModel = Yii::app()->getModule('message')->userModel;



This appears to relate to the calling of the MessageModule.php file and specifically userModel variable, which appears to get assigned during the construct of the class and I assume I need to use something like the following mentioned in the Extension:
return array(
    'modules' => array(
        'message' => array(
            'userModel' => 'User',
            'getNameMethod' => 'getFullName',
            'getSuggestMethod' => 'getSuggest',
        ),
    ),
);



My problem is I'm not sure where to store MessageModule.php or how to load it. I thought maybe it needs to be put into the /config/main.php, but I'm really not sure.


I would really appreciate any information you can give me on this and any corrections to any of my observations I have mentioned above.
Regards,
Cade

Current Projects
You Do It List: http://youdoitlist.com.au
0

#5 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 04 July 2012 - 11:45 AM

The MessageModule.phpare suppossed to be in protected/modules/message/MessageModule.php (the module "root")
There you also put the view/controller/models/data folders.

'modules'=>array(
....
'message' => array(
'userModel' => 'User', //make sure this is the same as the user model you use
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
),
....
),
0

#6 User is offline   Cade 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 04-July 12

Posted 05 July 2012 - 05:31 AM

View PostSampa, on 04 July 2012 - 11:45 AM, said:

The MessageModule.phpare suppossed to be in protected/modules/message/MessageModule.php (the module "root")
There you also put the view/controller/models/data folders.

'modules'=>array(
....
'message' => array(
'userModel' => 'User', //make sure this is the same as the user model you use
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
),
....
),


Yep, that did the trick.

Thanks for all your help


Just to recap for anyone else who is very new to Yii and wants to use this.

Step 1
Extract the contents of the ZIP to /protected/modules/message/
NOTE: the MessageModule.php file should be directly under this directory

Step 2
Modify the protected/config/main.php file and add the following in 'modules' (same location as 'gii'=>array):
		'message' => array(
			'userModel' => 'User',
			'getNameMethod' => 'getFullName',
			'getSuggestMethod' => 'getSuggest',
			'viewPath' => '/message/fancy',
		),

NOTE: The viewPath line at the end is optional and uses the fancy style rather than default

Step 3
Create the database as per the /protected/modules/message/data/message.sql

Step 4
Update your User module (or what module you specify in step 2 to include a getFullName and getSuggest module
examples for this are in the Private Messaging Extension

Step 5
Access the module via: ..../index.php/message
The above will depend on your URL structure


Issues
I did get 1 issue at step 5 where it complained it couldn't find the database {{messages}}.
I had to edit the protected/modules/message/models/Message.php and change the line:
return '{{messages}}';
To
return 'messages';
Regards,
Cade

Current Projects
You Do It List: http://youdoitlist.com.au
0

#7 User is offline   Sampa 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 18-December 11
  • Location:Stockholm,Sweden

Posted 05 July 2012 - 04:48 PM

View PostCade, on 05 July 2012 - 05:31 AM, said:

Yep, that did the trick.

Thanks for all your help


Just to recap for anyone else who is very new to Yii and wants to use this.
.........


wow, I'm glad it solved it for you and amazing you wrote that "How-to". Thats the spirit.
I think you can have helped some beginners.
0

#8 User is offline   DenizB 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 11-May 12

Posted 25 July 2012 - 04:17 PM

Step 1
Extract the contents of the ZIP to /protected/modules/message/
NOTE: the MessageModule.php file should be directly under this directory

Step 2
Modify the protected/config/main.php file and add the following in 'modules' (same location as 'gii'=>array):
		'message' => array(
			'userModel' => 'User',
			'getNameMethod' => 'getFullName',
			'getSuggestMethod' => 'getSuggest',
			'viewPath' => '/message/fancy',
		),

...

It is real step-by-step explanation.Thank you Cade.
0

#9 User is offline   sanguina 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 42
  • Joined: 22-July 12

Posted 28 February 2013 - 02:33 PM

Hi

thanks for this extension. worked out of box :)

can you suggest how to customize name-suggestions feature to show names near the text-field rather than at the top corner of the page ?

thanks again.
until I become certain that there is no certainty.
0

#10 User is offline   BaliWeb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-May 13

Posted 20 June 2013 - 03:25 AM

For anyone (like me) having problems with the suggest function, I would like to share how I did it (requires to change the SuggestController and compose view (I've also added filter and accessrules functions as I am using the Rights module for authentication):

SuggestController.php Controller
<?php

class SuggestController extends Controller {
	/**
	 * @return array action filters
	 */
	public function filters()
	{
		return CMap::mergeArray(parent::filters(),array(
			'accessControl', // perform access control for CRUD operations
		));
	}
	/**
	 * Specifies the access control rules.
	 * This method is used by the 'accessControl' filter.
	 * @return array access control rules
	 */
	public function accessRules()
	{
		return array(
			array('allow',  // allow all users to perform 'index' and 'view' actions
				'actions'=>array('user'),
				'users'=>array('@'),
			),
			array('deny',  // deny all users
				'users'=>array('*'),
			),
		);
	}
        
        public function actionUser() {
                $res =array();

                if (isset($_GET['term'])) {
                        $q = Yii::app()->request->getParam('term');
                        $userModels = (array) call_user_func(array(
                                CActiveRecord::model(Yii::app()->getModule('message')->userModel),
                                Yii::app()->getModule('message')->getSuggestMethod
                        ), $q);                        
                        
                        if ($userModels) {
                            foreach ($userModels as $userModel) {
                                $fullName=call_user_func(array(
                                        $userModel, $this->getModule()->getNameMethod
                                ));
                                $users[] = array(
                                    'label' => $fullName,
                                    'value' => $fullName,
                                    'id' => $userModel->getPrimaryKey(),
                                );
                            }
                        }
                }

		header('Cache-Control: no-store');
		header('Pragma: no-store');
		header("Content-type: application/json");
                echo CJSON::encode($users);
                Yii::app()->end();
        }
}


Compose.php View
<?php $this->pageTitle=Yii::app()->name . ' - '.RE_t("Compose PMessages"); ?>
<?php
	$this->breadcrumbs=array(
		RE_t('Messages')=>array('#'),
		RE_t("Compose"),
	);
?>

<?php $this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_navigation'); ?>

<h2><?php echo RE_t('Compose New PMessages'); ?></h2>

<div class="form">
	<?php $form = $this->beginWidget('CActiveForm', array(
		'id'=>'message-form',
		'enableAjaxValidation'=>false,
	)); ?>

	<p class="note"><?php echo RE_t('Fields with <span class="required">*</span> are required.'); ?></p>

	<?php echo $form->errorSummary($model); ?>

	<div class="row">                
                <?php echo $form->labelEx($model,'receiver_id'); ?>
                <?php
                    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                            'name'=>'receiver',
                            'model'=>$model,
                            'value'=>"$receiverName",
                            'source'=>$this->createUrl('suggest/user'),
                            // additional javascript options for the autocomplete plugin
                            'options'=>array(
                                'showAnim'=>'fold',
                                'select'=>"js: function(event, ui) {
                                         console.log(ui.item);
                                         $('#PMessages_receiver_id').val(ui.item['id']);
                                }"
                            ),
                    ));                
                ?>
                <?php echo $form->hiddenField($model,'receiver_id'); ?>
		<?php echo $form->error($model,'receiver_id'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'subject'); ?>
		<?php echo $form->textField($model,'subject'); ?>
		<?php echo $form->error($model,'subject'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'body'); ?>
		<?php echo $form->textArea($model,'body',array('style'=>'width: 400px; height: 100px;','maxlength' => 500)); ?>
		<?php echo $form->error($model,'body'); ?>
	</div>

	<div class="buttons">
		<?php echo CHtml::submitButton(RE_t("Send"),array('class'=>'btn btn-primary')); ?>
	</div>

	<?php $this->endWidget(); ?>

</div>

<?php 
//TODO we are not using this jquery functions because Yii provides a better widget for autocompletion
//and it is part of the standard FrameWork: zii.widgets.jui.CJuiAutoComplete

//$this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_suggest');


I hope this helps!
0

#11 User is offline   hv91 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 23-October 12

Posted 13 July 2013 - 11:58 PM

I follow the instructions of http://www.yiiframew...vate-messaging/ and @Cade but I see error as follows

"Active record "Message" has an invalid configuration for relation "receiver". It must specify the relation type, the related active record class and the foreign key."

My config/main.php:
'message' => array(
                        'userModel' => 'User',
                        'getNameMethod' => 'getFullName',
                        'getSuggestMethod' => 'getSuggest',
                        //'viewPath' => '/message/fancy',
                        
                        'receiverRelation' => array(
                        		CActiveRecord::BELONGS_TO,
                        		'User',
                        		'on' => 'User.id = receiver_id'
                        ),

                        
						)

                        'senderRelation' => array(
                        		CActiveRecord::BELONGS_TO,
                        		'User',
                        		'on' => 'User.id = sender_id'
                        ),

                		
        ),


Please help me !!!!
0

#12 User is offline   hv91 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 23-October 12

Posted 14 July 2013 - 05:44 AM

This is my post, it have error "Active record "Message" has an invalid configuration for relation "receiver"."

https://www.dropbox....6mo/message.rar
https://www.dropbox....6mo/message.rar
0

#13 User is offline   marianux 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 03-September 13

Posted 03 September 2013 - 01:21 PM

Hi, id like to know if it's possible use this extension with CRUGE.
If anyone has done it, Could you explain how-to?

PD. i have integrated everything with CRUGE but it seems that doesnt work:

- For example, doesnt find any user in suggest
- I have inserted a message directly in table via phpmyadmin and then in menu it shows correctly that there's a new message but when i go to inbox i get an error (it seems that try to get the sender username) :

Missing argument 2 for CrugeUser::__construct(), called in C:\wamp\www\yii\framework\db\ar\CActiveRecord.php on line 395 and defined 


public function __construct($username, $password, $authmode = 'default')
68     {
69         $this-&gt;username = $username;
70         $this-&gt;password = $password;
71         $this-&gt;authmode = $authmode;
72         $this-&gt;storeduser = null;
73 
74         Yii::log(__METHOD__ . &quot;\n&quot;, &quot;info&quot;);
75     }

0

#14 User is offline   roy90 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 09-November 13

Posted 20 November 2013 - 11:55 PM

I have got this error Message and its behaviors do not have a method or closure named "getCountUnreaded". how to solve this error?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users