Commit 8d391c91 authored by andre's avatar andre

копирование страниц faq

parent 713367e3
...@@ -24,11 +24,12 @@ class FaqAdminController extends AdminController ...@@ -24,11 +24,12 @@ class FaqAdminController extends AdminController
{ {
public static function actionsTitles(){ public static function actionsTitles(){
return [ return [
'Manage' => 'Управление записями', 'Manage' => 'Список страниц',
'Create' => 'Добавление записи', 'Create' => 'Добавление страницы',
'Update' => 'Редактирование записи', 'Copy' => 'Копирование страницы',
'Delete' => 'Удаление записи', 'Update' => 'Редактирование страницы',
'View' => 'Просмотр записи', 'Delete' => 'Удаление страницы',
'View' => 'Просмотр страницы',
'Autocomplete' => 'Автокомплит для поля тегов' 'Autocomplete' => 'Автокомплит для поля тегов'
]; ];
} }
...@@ -111,6 +112,41 @@ class FaqAdminController extends AdminController ...@@ -111,6 +112,41 @@ class FaqAdminController extends AdminController
]); ]);
} }
public function actionCopy($id)
{
if (!Yii::$app->request->isPost)
{
$model = $this->findModel($id);
$model->url = null;
}
else
{
$transaction = Yii::$app->db->beginTransaction();
try
{
$model = new Faq;
$model->attributes = Yii::$app->request->post('Faq');
if($model->save())
{
$transaction->commit();
return $this->redirect(['manage']);
}
}
catch (\Exception $e)
{
$transaction->rollBack();
throw $e;
}
}
return $this->render('update', [
'model' => $model,
]);
}
/** /**
* Updates an existing Post model. * Updates an existing Post model.
* If update is successful, the browser will be redirected to the 'view' page. * If update is successful, the browser will be redirected to the 'view' page.
...@@ -148,6 +184,8 @@ class FaqAdminController extends AdminController ...@@ -148,6 +184,8 @@ class FaqAdminController extends AdminController
]); ]);
} }
/** /**
* Deletes an existing Post model. * Deletes an existing Post model.
* If deletion is successful, the browser will be redirected to the 'index' page. * If deletion is successful, the browser will be redirected to the 'index' page.
...@@ -158,7 +196,7 @@ class FaqAdminController extends AdminController ...@@ -158,7 +196,7 @@ class FaqAdminController extends AdminController
{ {
$this->findModel($id)->delete(); $this->findModel($id)->delete();
return $this->redirect(['index']); return $this->redirect(['manage']);
} }
......
...@@ -83,13 +83,13 @@ class Faq extends \common\components\ActiveRecordModel ...@@ -83,13 +83,13 @@ class Faq extends \common\components\ActiveRecordModel
return [ return [
'meta' => [ 'meta' => [
'class' => 'common\components\activeRecordBehaviors\MetaTagBehavior', 'class' => 'common\components\activeRecordBehaviors\MetaTagBehavior',
'actions' => ['create', 'update'] 'actions' => ['create', 'update', 'copy']
], ],
'langs' => [ 'langs' => [
'class' => 'common\modules\languages\components\LanguageHelperBehavior', 'class' => 'common\modules\languages\components\LanguageHelperBehavior',
'field' => 'faq_id', 'field' => 'faq_id',
'langClass' => 'common\modules\faq\models\FaqContentLang', 'langClass' => 'common\modules\faq\models\FaqContentLang',
'actions' => ['create', 'update'] 'actions' => ['create', 'update', 'copy']
], ],
// 'tags' => [ // 'tags' => [
// 'class' => 'common\modules\blog\components\TagBehavior', // 'class' => 'common\modules\blog\components\TagBehavior',
......
...@@ -13,8 +13,10 @@ use common\modules\faq\assets\AdminGeneratorAsset; ...@@ -13,8 +13,10 @@ use common\modules\faq\assets\AdminGeneratorAsset;
AdminGeneratorAsset::register($this); AdminGeneratorAsset::register($this);
//print_r($model->getLangsHelper());die;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $model common\modules\blog\models\Post */ /* @var $model common\modules\faq\models */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
?> ?>
...@@ -48,7 +50,7 @@ AdminGeneratorAsset::register($this); ...@@ -48,7 +50,7 @@ AdminGeneratorAsset::register($this);
<?php $c = 0; foreach ($model->getLangsHelper() as $i => $content) : $c++; ?> <?php $c = 0; foreach ($model->getLangsHelper() as $i => $content) : $c++; ?>
<li class="<?=($c==1?'active':'')?>"><a href="#lang-<?=$content->lang->url?>" data-toggle="tab"><?=$content->lang->name?></a></li> <li class="<?=($c==1?'active':'')?>"><a href="#lang-<?=$content->lang->url?>" data-toggle="tab"><?=$content->lang->name?></a></li>
<?php endforeach; ?> <?php endforeach; ?>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<?php $c = 0; foreach ($model->getLangsHelper() as $content) : $c++; <?php $c = 0; foreach ($model->getLangsHelper() as $content) : $c++;
......
...@@ -58,7 +58,7 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -58,7 +58,7 @@ $this->params['breadcrumbs'][] = $this->title;
[ [
'class' => 'common\components\ColorActionColumn', 'class' => 'common\components\ColorActionColumn',
'template' => '{statistics} {update} {delete}', 'template' => '{statistics} {copy} {update} {delete}',
'buttons' => [ 'buttons' => [
'statistics' => function ($url, $model, $key) { 'statistics' => function ($url, $model, $key) {
return '<a href="'.Url::toRoute(['/blog/statistics-admin/manage', 'id' => $model->id]).'">'.Html::beginTag('i', [ return '<a href="'.Url::toRoute(['/blog/statistics-admin/manage', 'id' => $model->id]).'">'.Html::beginTag('i', [
...@@ -67,6 +67,13 @@ $this->params['breadcrumbs'][] = $this->title; ...@@ -67,6 +67,13 @@ $this->params['breadcrumbs'][] = $this->title;
'class' => 'fa fa-area-chart fa-lg' 'class' => 'fa fa-area-chart fa-lg'
]) . Html::endTag('i') . '</a>'; ]) . Html::endTag('i') . '</a>';
}, },
'copy' => function ($url, $model, $key) {
return '<a href="'.Url::toRoute(['copy', 'id' => $model->id]).'">'.Html::beginTag('i', [
'title' => "Копировать страницу",
'data-toggle' => 'tooltip',
'class' => 'fa fa-copy fa-lg'
]) . Html::endTag('i') . '</a>';
},
], ],
], ],
], ],
......
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