You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
1.9 KiB

6 years ago
<?php
namespace common\modules\forms;
use common\modules\forms\entities\Form;
use common\modules\forms\entities\FormMessage;
6 years ago
use core\components\modules\ModuleInterface;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
6 years ago
/**
* blog module definition class
*/
class FormsModule extends \yii\base\Module implements ModuleInterface
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'common\modules\forms\controllers';
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
public function bootstrap($app)
{
// prepare rules
6 years ago
$app->getUrlManager()->addRules([
'forms/manage/form/view/<id:\d+>' => 'forms/manage/form/view',
]);
// add languages
$app->getI18n()->translations = ArrayHelper::merge($app->getI18n()->translations, [
'form' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@common/modules/forms/messages',
],
]);
// add menu items
if (basename($app->getBasePath()) === 'backend') {
$app->params['adminMenu'][] = [
'label' => \Yii::t( 'form', 'Forms' ),
'icon' => 'address-card-o',
'items' => [
[
'label' => \Yii::t( 'form', 'Forms' ),
'icon' => 'caret-right',
'url' => [ '/forms/manage/form/index' ]
],
[
'label' => \Yii::t( 'form', 'Messages' ),
'icon' => 'caret-right',
'url' => [ '/forms/manage/form-message/index' ]
],
],
'visible' => \Yii::$app->user->can( 'admin' ) || \Yii::$app->user->can( 'FormsManagement' ),
];
}
// prepare notifications
$new_messages_count = FormMessage::find()->unread()->count();
if ($new_messages_count > 0) {
$app->params['notifications'][] = [
'icon' => 'address-card-o',
'color' => 'yellow',
'message' => 'New forms messages: {count}',
'message_file' => 'form',
'url' => '/forms/manage/form-message/index',
'count' => $new_messages_count,
];
}
6 years ago
}
}