Skip to content

Commit

Permalink
Yupe Message Module
Browse files Browse the repository at this point in the history
Private Messaging module for Yupe CMS
  • Loading branch information
quot;brussens committed Feb 1, 2014
1 parent 5a30e2a commit 3e58c94
Show file tree
Hide file tree
Showing 17 changed files with 1,150 additions and 0 deletions.
117 changes: 117 additions & 0 deletions MessageModule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php
/**
* MessageModule основной класс модуля message
*
* @author BrusSENS <[email protected]>
* @link http://yupe.ru
* @copyright 2014 BrusSENS
* @package yupe.modules.message
* @since 0.6-beta
*
*/


use yupe\components\WebModule;

class MessageModule extends WebModule
{
// название модуля
public function getName()
{
return Yii::t('MessageModule.client', 'Приватные сообщения');
}

// описание модуля
public function getDescription()
{
return Yii::t('MessageModule.client', 'Модуль для организации приватных сообщений между пользователями');
}

// автор модуля (Ваше Имя, название студии и т.п.)
public function getAuthor()
{
return Yii::t('MessageModule.client', 'Дмитрий Брусенский (BrusSENS)');
}

// контактный email автора
public function getAuthorEmail()
{
return Yii::t('MessageModule.client', '[email protected]');
}

// сайт автора или страничка модуля
public function getUrl()
{
return Yii::t('MessageModule.client', 'http://hoswac.com');
}

public function getCategory()
{
return Yii::t('MessageModule.client', 'Сервисы');
}

public function getIsInstallDefault()
{
return false;
}

public function getIsNoDisable()
{
return false;
}

public function getVersion()
{
return Yii::t('MessageModule.user', '0.1-alpha');
}

public function getIcon()
{
return 'envelope';
}

public function getDependencies()
{
return array('user');
}

public function init()
{
// 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 getAdminPageLink()
{
return '/message/messageBackend/index';
}

public function getNavigation()
{
return array(
array('label' => Yii::t('MessageModule.user', 'Users')),
array('icon' => 'list-alt', 'label' => Yii::t('MessageModule.user', 'Manage users'), 'url' => array('/user/userBackend/index')),
array('icon' => 'plus-sign', 'label' => Yii::t('MessageModule.user', 'Create user'), 'url' => array('/user/userBackend/create')),
array('label' => Yii::t('MessageModule.user', 'Tokens')),
array('icon' => 'list-alt', 'label' => Yii::t('MessageModule.user', 'Token list'), 'url' => array('/user/tokensBackend/index')),
);
}

public function beforeControllerAction($controller, $action)
{
if(parent::beforeControllerAction($controller, $action))
{
// this method is called before any module controller action is performed
// you may place customized code here
return true;
}
else
return false;
}
}
18 changes: 18 additions & 0 deletions controllers/MessageBackendController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Создано Hoswac ltd.
* Пользователь: BrusSENS
* Дата: 26.01.14
* Время: 4:49
* Описание:
*/

class MessageBackendController extends yupe\components\controllers\BackController
{
public function actionIndex() {
$this->render('index');
}
public function spam() {
$this->render('spam');
}
}
71 changes: 71 additions & 0 deletions controllers/MessageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

class MessageController extends yupe\components\controllers\FrontController
{
public function init() {
Yii::app()->clientScript->registerCssFile(
Yii::app()->assetManager->publish(
Yii::getPathOfAlias('application.modules.message.views.assets.css').'/messageModule.css'
)
);
return parent::init();
}
public function actionInbox()
{
$dataProvider= Message::model()->inbox;
$this->render('index', array('dataProvider'=>$dataProvider));
}
public function actionOutbox()
{
$dataProvider= Message::model()->outbox;
$this->render('index', array('dataProvider'=>$dataProvider));
}
public function actionView() {
$stat= Message::model()->countMessages();
$model = Message::model()->messageView($_GET['message_id']);
if (!$model) {
throw new CHttpException(404, Yii::t('MessageModule.message', 'This message does not exist'));
}
$this->render('show',array('model'=>$model, 'stat'=>$stat));
}
public function actionCreate()
{
$model=new Message;
$user=new User;
// uncomment the following code to enable ajax-based validation

if(isset($_POST['ajax']) && $_POST['ajax']==='message-CreateMessage-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}

if(isset($_POST['Message']))
{
$model->attributes=$_POST['Message'];
if($model->validate())
{
if($model->save()) {
Yii::app()->user->setFlash(
YFlashMessages::SUCCESS_MESSAGE,
Yii::t('MessageModule.message', 'Message sent successfully!')
);
}
}
}
$this->render('create',array('model'=>$model, 'user'=>$user->findAll()));
}
public function toCut($str,$len=30,$div=" "){
//Обрезка Строки до заданной максимальной длинны, с округлением до посленего символа - разделителя (в меньшую сторону)
//например toCut('Мама мыла раму',14," ") вернет "Мама мыла"
if (strlen($str)<=$len){
return $str;
}
else{
$str=substr($str,0,$len);
$pos=strrpos($str,$div);
$str=substr($str,0,$pos);
return $str.' ...';
}
}
}
27 changes: 27 additions & 0 deletions install/message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* Файл конфигурации модуля message
*
* @author BrusSENS <[email protected]>
* @link http://yupe.ru
* @copyright 2014 BrusSENS
* @package yupe.modules.message
* @since 0.6-beta
*
*/
return array(
'module' => array(
'class' => 'application.modules.message.MessageModule',
),
'import' => array(
'application.modules.message.models.*',
),
'component' => array(),

'rules' => array(
'/messages'=> 'message/message/inbox',
'/messages/outbox'=> 'message/message/outbox',
'/message/create'=> 'message/message/create',
'/message/view/<message_id>'=> 'message/message/view',
),
);
53 changes: 53 additions & 0 deletions install/migrations/m140201_133405_message_message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Message install migration
* Класс миграций для модуля Message:
*
* @category YupeMigration
* @package yupe.modules.message.install.migrations
* @author BrusSENS <[email protected]>
* @license BSD https://raw.github.com/yupe/yupe/master/LICENSE
* @link http://yupe.ru
**/
class m140201_133405_message_message extends yupe\components\DbMigration
{
/**
* Функция настройки и создания таблицы:
*
* @return null
**/
public function safeUp()
{
$this->createTable(
'{{message_message}}',
array(
'id' => 'pk',
'subject' => 'varchar(150)',
'body' => 'text NOT NULL',
'send_date' => 'datetime NOT NULL',
'sender_id' => 'INT(11) NOT NULL',
'recipient_id' => 'INT(11) NOT NULL',
'is_spam' => "BIT(1) NOT NULL DEFAULT b'0'",
'is_read' => "BIT(1) NOT NULL DEFAULT b'0'",
'sender_del' => "BIT(1) NOT NULL DEFAULT b'0'",
'recipient_del' => "BIT(1) NOT NULL DEFAULT b'0'",
),
$this->getOptions()
);

//ix
$this->addForeignKey('fk_recipient', '{{message_message}}', 'recipient_id',
'{{user_user}}', 'id', 'CASCADE', 'CASCADE');
$this->addForeignKey('fk_sender', '{{message_message}}', 'sender_id',
'{{user_user}}', 'id', 'CASCADE', 'CASCADE');
}
/**
* Функция удаления таблицы:
*
* @return null
**/
public function safeDown()
{
$this->dropTableWithForeignKeys('{{message_message}}');
}
}
46 changes: 46 additions & 0 deletions messages/en/message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yiic message' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE, this file must be saved in UTF-8 encoding.
*/
return array (
'Spam' => '',
'Removed' => '',
'Submitted' => '',
'Inbox' => '',
'Write' => '',
'Cancel' => '',
'Send' => '',
'This is spam!' => '',
'Remove' => '',
'This user does not exist' => '',
'You can not send messages to yourself' => '',
'Subject' => '',
'Content' => '',
'Dispatch date' => '',
'Sender ID' => '',
'Recipient nickname' => '',
'Recipient ID' => '',
'Marked by the recipient as "Spam"' => '',
'Read by the recipient' => '',
'Deleted sender' => '',
'Deleted recipient' => '',
'Message sent successfully!' => '',
'This message does not exist' => '',
'Fields with <span class="required">*</span> are required' => '',
'Yesterday at' => '',
'Today at' => '',
);
46 changes: 46 additions & 0 deletions messages/ru/message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yiic message' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE, this file must be saved in UTF-8 encoding.
*/
return array (
'Spam' => 'Спам',
'Removed' => 'Удалённые',
'Submitted' => 'Отправленные',
'Inbox' => 'Входящие',
'Write' => 'Написать',
'Cancel' => 'Отмена',
'Send' => 'Отправить',
'This is spam!' => 'Это спам!',
'Remove' => 'Удалить',
'This user does not exist' => 'Такого пользователя не существует',
'You can not send messages to yourself' => 'Нельзя отправлять сообщения самому себе',
'Subject' => 'Тема',
'Content' => 'Содержание',
'Dispatch date' => 'Дата отправки',
'Sender ID' => 'ID отправителя',
'Recipient nickname' => 'Никнейм получателя',
'Recipient ID' => 'ID получателя',
'Marked by the recipient as "Spam"' => 'Помечено получателем, как "Спам"',
'Read by the recipient' => 'Прочтено получателем',
'Deleted sender' => 'Удалено отправителем',
'Deleted recipient' => 'Удалено получателем',
'Message sent successfully!' => 'Сообщение успешно отправлено!',
'This message does not exist' => 'Такого сообщения не существует',
'Fields with <span class="required">*</span> are required' => 'Поля, помеченные <span class="required">*</span> обязательны для заполнения',
'Yesterday at' => 'Вчера в',
'Today at' => 'Сегодня в',
);
Loading

0 comments on commit 3e58c94

Please sign in to comment.