public function actionCompose($id = null) { $message = new Message(); if (Yii::app()->request->getPost('Message')) { $receiverName = Yii::app()->request->getPost('receiver'); $message->attributes = Yii::app()->request->getPost('Message'); $message->sender_id = Yii::app()->user->getId(); if ($message->save()) { Yii::app()->user->setFlash('messageModule', MessageModule::t('Message has been sent')); $this->redirect($this->createUrl('inbox/')); } else { if ($message->hasErrors('receiver_id')) { $message->receiver_id = null; $receiverName = ''; } } } else { if ($id) { $receiver = call_user_func(array(call_user_func(array(Yii::app()->getModule('message')->userModel, 'model')), 'findByPk'), $id); if ($receiver) { $receiverName = call_user_func(array($receiver, Yii::app()->getModule('message')->getNameMethod)); $message->receiver_id = $receiver->id; } } } $this->render(Yii::app()->getModule('message')->viewPath . '/compose', array('model' => $message, 'receiverName' => isset($receiverName) ? $receiverName : null)); }
public function actionDelete($id = null) { if (!$id) { $messagesData = Yii::app()->request->getParam('Message'); $counter = 0; if ($messagesData) { foreach ($messagesData as $messageData) { if (isset($messageData['selected'])) { $message = Message::model()->findByPk($messageData['id']); if ($message->deleteByUser(Yii::app()->user->getId())) { $counter++; } } } } if ($counter) { Yii::app()->user->setFlash('messageModule', MessageModule::t('{count} message' . ($counter > 1 ? 's' : '') . ' has been deleted', array('{count}' => $counter))); } $this->redirect(Yii::app()->request->getUrlReferrer()); } else { $message = Message::model()->findByPk($id); if (!$message) { throw new CHttpException(404, MessageModule::t('Message not found')); } $folder = $message->receiver_id == Yii::app()->user->getId() ? 'inbox/' : 'sent/'; if ($message->deleteByUser(Yii::app()->user->getId())) { Yii::app()->user->setFlash('messageModule', MessageModule::t('Message has been deleted')); } $this->redirect($this->createUrl($folder)); } }
public function init() { if (!class_exists($this->userModel)) { throw new Exception(MessageModule::t("Class {userModel} not defined", array('{userModel}' => $this->userModel))); } foreach (array('getNameMethod', 'getSuggestMethod') as $methodName) { if (!$this->{$methodName}) { throw new Exception(MessageModule::t("Property MessageModule::{methodName} not defined", array('{methodName}' => $methodName))); } if (!method_exists($this->userModel, $this->{$methodName})) { throw new Exception(MessageModule::t("Method {userModel}::{methodName} not defined", array('{userModel}' => $this->userModel, '{methodName}' => $this->{$methodName}))); } } // this method is called when the module is being created // you may place code here to customize the module or the application // import the module-level models and components $this->setImport(array('message.models.*', 'message.components.*')); }
public function actionView() { $messageId = (int) Yii::app()->request->getParam('message_id'); $viewedMessage = Message::model()->findByPk($messageId); if (!$viewedMessage) { throw new CHttpException(404, MessageModule::t('Message not found')); } $userId = Yii::app()->user->getId(); if ($viewedMessage->sender_id != $userId && $viewedMessage->receiver_id != $userId) { throw new CHttpException(403, MessageModule::t('You can not view this message')); } if ($viewedMessage->sender_id == $userId && $viewedMessage->deleted_by == Message::DELETED_BY_SENDER || $viewedMessage->receiver_id == $userId && $viewedMessage->deleted_by == Message::DELETED_BY_RECEIVER) { throw new CHttpException(404, MessageModule::t('Message not found')); } $message = new Message(); $isIncomeMessage = $viewedMessage->receiver_id == $userId; if ($isIncomeMessage) { $message->subject = preg_match('/^Re:/', $viewedMessage->subject) ? $viewedMessage->subject : 'Re: ' . $viewedMessage->subject; $message->receiver_id = $viewedMessage->sender_id; } else { $message->receiver_id = $viewedMessage->receiver_id; } if (Yii::app()->request->getPost('Message')) { $message->attributes = Yii::app()->request->getPost('Message'); $message->sender_id = $userId; if ($message->save()) { Yii::app()->user->setFlash('success', MessageModule::t('Message has been sent')); if ($isIncomeMessage) { $this->redirect($this->createUrl('inbox/')); } else { $this->redirect($this->createUrl('sent/')); } } } if ($isIncomeMessage) { $viewedMessage->markAsRead(); } $this->render(Yii::app()->getModule('message')->viewPath . '/view', array('viewedMessage' => $viewedMessage, 'message' => $message)); }
<?php echo $form->error($model, 'subject'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'body'); ?> <?php echo $form->textArea($model, 'body'); ?> <?php echo $form->error($model, 'body'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton(MessageModule::t("Send")); ?> </div> <?php $this->endWidget(); ?> </div> <?php $this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_suggest');
<div class="row"> <?php echo $form->labelEx($model, Yii::t('messages', 'Message')); ?> <?php echo $form->textArea($model, 'body', array('class' => 'txtarea')); ?> <?php echo $form->error($model, 'body'); ?> </div> <div style="margin:10px 0 0 0px"> <?php echo CHtml::submitButton(MessageModule::t("Send"), array('class' => 'formbut')); ?> </div> <?php $this->endWidget(); ?> </div> <?php $this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_suggest'); ?> </div> </div></td>
<?php echo $form->textField($message, 'subject'); ?> <?php echo $form->error($message, 'subject'); ?> </div> <div class="row"> <?php echo $form->labelEx($message, 'body'); ?> <?php echo $form->textArea($message, 'body'); ?> <?php echo $form->error($message, 'body'); ?> </div> <div class="row buttons"> <?php echo CHtml::submitButton(MessageModule::t("Reply")); ?> </div> <?php $this->endWidget(); ?> </div>
</td> <td><a href="<?php echo $this->createUrl('view/', array('message_id' => $message->id)); ?> "><?php echo $message->subject; ?> </a></td> <td><span class="date"><?php echo date(Yii::app()->getModule('message')->dateFormat, strtotime($message->created_at)); ?> </span></td> </tr> <?php } ?> </table> <div class="row buttons"> <?php echo CHtml::submitButton(MessageModule::t("Delete Selected")); ?> </div> <?php $this->endWidget(); ?> <?php $this->widget('CLinkPager', array('pages' => $messagesAdapter->getPagination())); }
<?php echo $form->error($message, 'subject'); ?> </div> <?php echo $form->labelEx($message, 'body'); ?> <div class="input"> <?php echo $form->textArea($message, 'body'); ?> <?php echo $form->error($message, 'body'); ?> </div> <div class="buttons"> <button class="btn primary"><?php echo MessageModule::t("Reply"); ?> </button> </div> <?php $this->endWidget(); ?> </div> </div> </div>
</div> <?php echo $form->labelEx($model, 'body'); ?> <div class="input"> <?php echo $form->textArea($model, 'body'); ?> <?php echo $form->error($model, 'body'); ?> </div> <div class="buttons"> <button class="btn primary"><?php echo MessageModule::t("Send"); ?> </button> </div> <?php $this->endWidget(); ?> </div> </div> </div> <?php $this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_suggest');
echo $message->subject; ?> </a></td> <td><span class="date"><?php echo date(Yii::app()->getModule('message')->dateFormat, strtotime($message->created_at)); ?> </span></td> </tr> <?php } ?> </table> <div> <button class="btn danger"><?php echo MessageModule::t("Delete Selected"); ?> </button> </div> <?php $this->endWidget(); ?> <div class="pagination"> <?php $this->widget('CLinkPager', array('header' => '', 'pages' => $messagesAdapter->getPagination(), 'htmlOptions' => array('class' => 'pager'))); ?> </div> <?php } ?>
public function getAccessMessage() { if (Yii::app()->user->message) { return true; } else { throw new CHttpException(401, MessageModule::t('ACCESS_DENIED_USER')); } }
<?php echo $form->labelEx($message, 'body'); ?> <div class="input"> <?php echo $form->textArea($message, 'body'); ?> <?php echo $form->error($message, 'body'); ?> </div> <div class="buttons"> <button class="btn btn-primary"><i class="icon-white icon-repeat"></i> <?php echo MessageModule::t("Reply"); ?> </button> <button class="btn btn-danger"><i class="icon-white icon-remove"></i> <?php echo MessageModule::t("Delete"); ?> </button> </div> <?php $this->endWidget(); ?> </div> </div> </div>