Commit 3d016405 authored by Олег Гиммельшпах's avatar Олег Гиммельшпах

Merge branch 'master' of git.task-on.com:ktask/task-on.com

parents 2c644ab3 84965e22
......@@ -27,6 +27,7 @@ return [
'triggers' => ['class' => 'common\modules\triggers\Module'],
'school' => ['class' => 'common\modules\school\Module'],
'rbac' => ['class' => 'common\modules\rbac\rbac'],
'message-template' => ['class' => 'common\modules\messageTemplate\Module'],
],
'components' => [
'session' => [
......
<?php
namespace common\modules\messageTemplate;
/**
* MessageTemplate module definition class
*/
class Module extends \common\components\WebModule
{
/**
* @inheritdoc
*/
public $controllerNamespace = 'common\modules\messageTemplate\controllers';
public static $active = true;
public $menu_icons = 'fa fa-message';
/**
* @inheritdoc
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
public static function name()
{
return 'Управление шаблонами';
}
public static function description()
{
return 'Управление шаблонами';
}
public static function version()
{
return '1.0';
}
public static function adminMenu()
{
return [
'Управление шаблонами' => '/message-template/template-admin/manage'
];
}
}
<?php
namespace common\modules\messageTemplate\controllers;
use yii\web\Controller;
/**
* Default controller for the `MessageTemplate` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}
<?php
/**
* Created by PhpStorm.
* User: PHOENIX
* Date: 16.02.16
* Time: 20:42
*/
namespace common\modules\messageTemplate\controllers;
use Yii;
use common\components\AdminController;
use common\modules\messageTemplate\models\MessageTemplate;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
use common\modules\messageTemplate\components\Templates;
class TemplateAdminController extends AdminController {
/**
* @return array|void
*/
public static function actionsTitles(){
return [
'Manage' => 'Управление шаблонами',
'Create' => 'Добавление шаблона',
'Update' => 'Редактирование шаблона',
'Delete' => 'Удаление шаблона',
'Testing' => 'Test'
];
}
public function actionTesting(){
$object=new Templates(2);
echo $object->getTemplate();
}
/**
* @return string
*/
public function actionManage(){
$dataProvider = new ActiveDataProvider([
'query' => MessageTemplate::find()
]);
return $this->render(
'manage',
[
'dataProvider' => $dataProvider
]
);
}
/**
* @return string|\yii\web\Response
*/
public function actionCreate(){
$model = new MessageTemplate();
if ($model->load(Yii::$app->request->post())) {
if ($model->save())
return $this->redirect(
[
'manage'
]
);
}
$form = new \common\components\BaseForm('/common/modules/messageTemplate/forms/TemplateForm', $model);
return $this->render(
'create',
[
'model' => $model,
'form' => $form
]
);
}
/**
* @param $id
* @return string|\yii\web\Response
*/
public function actionUpdate($id){
/** @var MessageTemplate $model */
$model = MessageTemplate::findOne($id);
if ($model->load(Yii::$app->request->post())) {
if ($model->save())
return $this->redirect(
[
'manage'
]
);
}
$form = new \common\components\BaseForm('/common/modules/messageTemplate/forms/TemplateForm', $model);
return $this->render(
'update',
[
'model' => $model,
'form' => $form
]
);
}
/**
* @param $id
* @return \yii\web\Response
*/
public function actionDelete($id){
$this->findModel($id)->delete();
return $this->redirect(['manage']);
}
/**
* @param $id
* @return null|MessageTemplate
* @throws \yii\web\NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = MessageTemplate::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
\ No newline at end of file
<?php
return [
'activeForm' => [
'id' => 'template-form'
],
'elements' => [
'name' => [
'type' => 'text'
],
'template' => [
'type' => 'textarea'
]
],
'buttons' => [
'submit' => ['type' => 'submit', 'value' => 'Cохранить']
]
];
\ No newline at end of file
<?php
namespace common\modules\messageTemplate\models;
use Yii;
/**
* This is the model class for table "message_template".
*
* @property integer $id
* @property string $name
* @property string $template
* @property string $created_at
*/
class MessageTemplate extends \common\components\ActiveRecordModel
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'message_template';
}
public function name()
{
return 'Шаблоны писем';
}
public function beforeSave($insert){
if (!parent::beforeSave($insert))
return false;
if ($insert && $this->created_at==null) {
$datetime = new \DateTime();
$this->created_at = $datetime->format('Y-m-d H:i:s');
}
return true;
}
public function behaviors(){
return [];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['name', 'template'], 'required'],
[['template'], 'string'],
[['created_at'], 'safe'],
[['name'], 'string', 'max' => 255],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'name' => 'Название',
'template' => 'Шаблон',
'created_at' => 'Дата создания',
];
}
}
<div class="MessageTemplate-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>
<?php
/**
* @var $form common\components\BaseForm
*/
echo $form->out;
\ No newline at end of file
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
?>
<div class="trigger-trigger-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Добавить шаблон', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'id',
'name',
'template:html',
'created_at:datetime',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}',
],
],
]); ?>
</div>
\ No newline at end of file
<?php
/**
* @var $form common\components\BaseForm
*/
echo $form->out;
\ No newline at end of file
<?php
use yii\db\Migration;
class m160216_145545_add_message_templates_table extends Migration
{
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
$this->createTable(
'message_template',
[
'id' => $this->primaryKey(),
'name' => $this->string(255)->notNull(),
'template' => $this->text()->notNull(),
'created_at' => $this->dateTime()->notNull()
]
);
}
public function safeDown()
{
$this->dropTable(
'message_template'
);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment