Commit 9b54409d authored by Shakarim Sapa's avatar Shakarim Sapa

Merge remote-tracking branch 'origin/master'

parents 593155e4 3f08e2f2
......@@ -12,7 +12,7 @@ class MetaTagBehavior extends Behavior
return [
ActiveRecord::EVENT_AFTER_UPDATE => 'Save',
ActiveRecord::EVENT_AFTER_INSERT => 'Insert',
ActiveRecord::EVENT_AFTER_DELETE => 'Delete',
ActiveRecord::EVENT_BEFORE_DELETE => 'Delete',
];
}
......@@ -69,11 +69,14 @@ class MetaTagBehavior extends Behavior
public function Delete($event)
{
MetaTags::deleteAll([
'object_id' => $this->owner->id,
'model_id' => get_class($this->owner)
]);
if($this->owner->metaTags)
{
foreach ($this->owner->metaTags as $meta)
{
$meta->delete();
}
}
return true;
}
}
......@@ -13,7 +13,7 @@ class CoBlocksLangBehavior extends Behavior
return [
ActiveRecord::EVENT_AFTER_UPDATE => 'Save',
ActiveRecord::EVENT_AFTER_INSERT => 'Insert',
ActiveRecord::EVENT_AFTER_DELETE => 'Delete',
ActiveRecord::EVENT_BEFORE_DELETE => 'Delete',
];
}
......@@ -67,9 +67,13 @@ class CoBlocksLangBehavior extends Behavior
public function Delete($event)
{
CoBlocksLang::deleteAll([
'block_id' => $this->owner->id
]);
if($this->owner->langs)
{
foreach ($this->owner->langs as $lang)
{
$lang->delete();
}
}
return true;
}
......
......@@ -13,7 +13,7 @@ class CoContentLangBehavior extends Behavior
return [
ActiveRecord::EVENT_AFTER_UPDATE => 'Save',
ActiveRecord::EVENT_AFTER_INSERT => 'Insert',
ActiveRecord::EVENT_AFTER_DELETE => 'Delete',
ActiveRecord::EVENT_BEFORE_DELETE => 'Delete',
];
}
......@@ -67,9 +67,13 @@ class CoContentLangBehavior extends Behavior
public function Delete($event)
{
CoContentLang::deleteAll([
'content_id' => $this->owner->id
]);
if($this->owner->langs)
{
foreach ($this->owner->langs as $lang)
{
$lang->delete();
}
}
return true;
}
......
......@@ -28,7 +28,7 @@ class ContentAdminController extends AdminController
'Update' => 'Редактирование контента',
'Delete' => 'Удаление контента',
'View' => 'Просмотр контента',
// 'Copy' => '',
'Copy' => 'Копирование страниц',
];
}
......@@ -44,23 +44,6 @@ class ContentAdminController extends AdminController
];
}
// public function actionCopy($id)
// {
// $model = $this->findModel($id);
// $meta = $model->metaTags->attributes;
// \Yii::$app->request->setBodyParams(['MetaTags' => $meta]);
// $newPage = new CoContent();
// $data = $model->attributes;
// unset($data['id']);
// $data['url'] = '';
// $newPage->setAttributes($data);
// $newPage->name .= ' (Копия)';
// $newPage->save(false);
// $this->redirect(['manage']);
// }
/**
* Lists all CoContent models.
* @return mixed
......@@ -256,6 +239,62 @@ class ContentAdminController extends AdminController
return $this->redirect(['manage']);
}
public function actionCopy($id)
{
$model = $this->findModel($id);
$transaction = Yii::$app->db->beginTransaction();
try
{
$copy = new CoContent();
$data = $model->attributes;
unset($data['id']);
$copy->setAttributes($data);
$copy->save(false);
if($model->metaTags)
{
foreach ($model->metaTags as $mt)
{
$mtn = new \common\models\MetaTags;
$data = $mt->attributes;
unset($data['id']);
$mtn->setAttributes($data);
$mtn->object_id = $copy->id;
$mtn->save(false);
}
}
if($model->langs)
{
foreach ($model->langs as $lang)
{
$lng = new CoContentLang;
$data = $lang->attributes;
unset($data['id']);
$lng->setAttributes($data);
$lng->name .= ' (Копия)';
$lng->content_id = $copy->id;
$lng->save(false);
}
}
$transaction->commit();
}
catch (Exception $e)
{
$transaction->rollBack();
throw $e;
}
$this->redirect(['manage']);
}
/**
* Finds the CoContent model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
......
......@@ -125,7 +125,7 @@ class CoContent extends \common\components\ActiveRecordModel
*/
public function getMetaTags($lang_id = null)
{
$query = $this->hasOne(MetaTags::className(), ['object_id' => 'id'])->where(['model_id' => get_class($this)]);
$query = $this->hasMany(MetaTags::className(), ['object_id' => 'id'])->where(['model_id' => get_class($this)]);
if($lang_id)
{
......
......@@ -43,15 +43,15 @@ 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>';
// },
'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