#1067 - Функция коппи блоков страниц

parent d2403a38
......@@ -22,6 +22,7 @@ class BlockAdminController extends AdminController
'Manage' => 'Управление блоками',
'Create' => 'Добавление блока',
'Update' => 'Редактирование блока',
'Copy' => 'Копирование блока',
'Delete' => 'Удаление блока',
'View' => 'Просмотр блока',
];
......@@ -156,6 +157,47 @@ class BlockAdminController extends AdminController
]);
}
public function actionCopy($id)
{
$model = $this->findModel($id);
$model->name = $model->title = null;
Yii::$app->controller->page_title = 'Копировать блок';
Yii::$app->controller->breadcrumbs = [
['Управление блоками' => \yii\helpers\Url::toRoute('manage')],
'Копировать блок',
];
if (Yii::$app->request->isPost)
{
$transaction = Yii::$app->db->beginTransaction();
try
{
$model = new CoBlocks;
$model->attributes = Yii::$app->request->post('CoBlocks');
if($model->save())
{
$transaction->commit();
return $this->redirect(['manage']);
}
}
catch (\Exception $e)
{
$transaction->rollBack();
throw $e;
}
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing CoBlocks model.
* If deletion is successful, the browser will be redirected to the 'index' page.
......
......@@ -178,56 +178,41 @@ class ContentAdminController extends AdminController
{
$model = $this->findModel($id);
$transaction = Yii::$app->db->beginTransaction();
$model->url = null;
try
{
$copy = new CoContent();
Yii::$app->controller->page_title = 'Копирование страницы';
$data = $model->attributes;
unset($data['id']);
$copy->setAttributes($data);
$copy->save(false);
Yii::$app->controller->breadcrumbs = [
['Управление контентом' => \yii\helpers\Url::toRoute('manage')],
$model->url,
];
if($model->metaTags)
{
foreach ($model->metaTags as $mt)
if (Yii::$app->request->isPost)
{
$mtn = new \common\models\MetaTags;
$data = $mt->attributes;
unset($data['id']);
$mtn->setAttributes($data);
$mtn->object_id = $copy->id;
$mtn->save(false);
}
}
$transaction = Yii::$app->db->beginTransaction();
if($model->langs)
{
foreach ($model->langs as $lang)
try
{
$lng = new CoContentLang;
$model = new CoContent;
$data = $lang->attributes;
unset($data['id']);
$lng->setAttributes($data);
$lng->name .= ' (Копия)';
$lng->content_id = $copy->id;
$lng->save(false);
}
}
$model->attributes = Yii::$app->request->post('CoContent');
if($model->save())
{
$transaction->commit();
return $this->redirect(['manage']);
}
catch (Exception $e)
}
catch (\Exception $e)
{
$transaction->rollBack();
throw $e;
}
}
$this->redirect(['manage']);
return $this->render('update', [
'model' => $model,
]);
}
/**
......
......@@ -43,7 +43,7 @@ class CoBlocks extends \common\components\ActiveRecordModel
'class' => 'common\modules\languages\components\LanguageHelperBehavior',
'field' => 'block_id',
'langClass' => 'common\modules\content\models\CoBlocksLang',
'actions' => ['create', 'update']
'actions' => ['create', 'update', 'copy']
],
];
}
......@@ -55,6 +55,7 @@ class CoBlocks extends \common\components\ActiveRecordModel
{
return [
[['title', 'name'], 'required'],
[['title'], 'unique'],
[['category_id'], 'safe'],
[['title'], 'string', 'max' => 250],
[['name'], 'string', 'max' => 50],
......
......@@ -32,6 +32,8 @@ class CoContent extends \common\components\ActiveRecordModel
const CUSTOM_DARK = 'dark';
const CUSTOM_WHITE = 'white';
public $copyLangs;
public static $cutom_list = [
self::CUSTOM_DARK => 'Темный',
self::CUSTOM_WHITE => 'Светлый',
......@@ -53,13 +55,13 @@ class CoContent 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' => 'content_id',
'langClass' => 'common\modules\content\models\CoContentLang',
'actions' => ['create', 'update']
'actions' => ['create', 'update', 'copy']
],
'file' => [
'class' => 'common\components\activeRecordBehaviors\FileUploadBehavior',
......
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use \yii\helpers\ArrayHelper;
use \common\modules\content\models\CoCategory;
/* @var $this yii\web\View */
......@@ -44,9 +45,17 @@ use \common\modules\content\models\CoCategory;
[
'class' => 'common\components\ColorActionColumn',
'template' => '{update} {delete}',
]
,
'template' => '{copy} {update} {delete}',
'buttons' => [
'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>';
},
],
],
],
]); ?>
......
......@@ -133,7 +133,7 @@ class LanguageHelperBehavior extends Behavior
public function Delete($event)
{
if($this->owner->langs)
if(isset($this->owner->langs))
{
foreach ($this->owner->langs as $lang)
{
......
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