Commit 8d391c91 authored by andre's avatar andre

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

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