Skip to content

Commit 5c79a4a

Browse files
Связи публикаций и товаров
1 parent 97fed19 commit 5c79a4a

12 files changed

Lines changed: 482 additions & 13 deletions

src/components/urlRules/UrlRuleTree.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ public function createUrl($manager, $route, $params)
7474
return $url;
7575
}
7676
}
77+
//Указан редиррект на другой раздел
78+
/*if ($tree->redirect_saved_filter_id) {
79+
return $tree->redirectSavedFilter->getUrl(false, $defaultParams);
80+
$paramsNew = ArrayHelper::merge($defaultParams, ['model' => $tree->redirectSavedFilter]);
81+
$url = $this->createUrl($manager, "cms/saved-filter/view", $paramsNew);
82+
return $url;
83+
}*/
7784

7885
//Стандартно берем dir раздела
7986
if ($tree->dir) {

src/console/controllers/ImageController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace skeeks\cms\console\controllers;
1010

11+
use skeeks\cms\Skeeks;
1112
use skeeks\imagine\Image;
1213
use skeeks\cms\models\CmsStorageFile;
1314
use yii\base\Exception;
@@ -123,6 +124,8 @@ public function actionResizeOriginalImagesVertical($maxHeight = 1600, $maxFileSi
123124
*/
124125
public function actionResizeOriginalImages($maxWidth = 1920, $maxHeight = 1200, $quantity = 100)
125126
{
127+
Skeeks::unlimited();
128+
126129
$query = CmsStorageFile::find()
127130
->andWhere(['>', 'image_height', $maxHeight])
128131
->andWhere(['>', 'image_width', $maxWidth])

src/controllers/AdminCmsContentElementController.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,31 @@ public function actions()
671671
},
672672
],
673673

674+
"element-joins" => [
675+
'class' => BackendModelAction::class,
676+
'name' => "Связи",
677+
'icon' => 'fa fa-list',
678+
'priority' => 190,
679+
'defaultView' => "@skeeks/cms/views/admin-cms-content-element/element-joins",
680+
681+
/*'accessCallback' => function (BackendModelAction $action) {
682+
683+
684+
$model = $action->model;
685+
686+
if (!$model) {
687+
return false;
688+
}
689+
690+
691+
692+
$site = $model->cmsSite;
693+
694+
return \Yii::$app->user->can($this->permissionName."/join", ['model' => $model]);
695+
696+
},*/
697+
],
698+
674699
'stat' => [
675700
//'generateAccess' => true,
676701
'class' => ViewBackendAction::class,
@@ -891,6 +916,57 @@ public function actions()
891916
}
892917

893918

919+
/**
920+
* @return RequestResponse
921+
* @throws \Throwable
922+
* @throws \yii\db\StaleObjectException
923+
*/
924+
public function actionElementJoinsDettach()
925+
{
926+
$rr = new RequestResponse();
927+
if ($rr->isRequestAjaxPost()) {
928+
$product_id = (int)\Yii::$app->request->post('product_id');
929+
930+
if ($product_id) {
931+
$sp = CmsContentElement::findOne($product_id);
932+
$spModel = $sp->cmsContentModel;
933+
if (!$spModel) {
934+
return $rr;
935+
}
936+
937+
$t = \Yii::$app->db->beginTransaction();
938+
939+
try {
940+
941+
$sp->cms_content_model_id = null;
942+
if (!$sp->save(false, ['cms_content_model_id'])) {
943+
throw new \yii\base\Exception(print_r($sp->errors, true));
944+
}
945+
946+
if ($spModel->getCmsContentElements()->count() <= 1) {
947+
$spModel->delete();
948+
}
949+
950+
951+
952+
$t->commit();
953+
954+
$rr->success = true;
955+
956+
} catch (\Exception $exception) {
957+
$t->rollBack();
958+
throw $exception;
959+
}
960+
961+
962+
}
963+
964+
}
965+
966+
return $rr;
967+
}
968+
969+
894970
public function initGridColumns($grid, $content)
895971
{
896972
return [];
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 28.08.2015
7+
*/
8+
use yii\db\Migration;
9+
10+
class m260319_163220_create_table__cms_content_model extends Migration
11+
{
12+
public function safeUp()
13+
{
14+
$tableName = 'cms_content_model';
15+
$tableExist = $this->db->getTableSchema($tableName, true);
16+
if ($tableExist) {
17+
return true;
18+
}
19+
20+
$tableOptions = null;
21+
if ($this->db->driverName === 'mysql') {
22+
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB';
23+
}
24+
25+
$this->createTable($tableName, [
26+
'id' => $this->primaryKey(),
27+
28+
'created_at' => $this->integer(),
29+
30+
], $tableOptions);
31+
32+
$this->createIndex($tableName.'__created_at', $tableName, 'created_at');
33+
}
34+
35+
public function safeDown()
36+
{}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 28.08.2015
7+
*/
8+
9+
use yii\db\Migration;
10+
11+
class m260319_163221_alter_table__cms_content_element extends Migration
12+
{
13+
public function safeUp()
14+
{
15+
$tableName = 'cms_content_element';
16+
17+
$this->addColumn($tableName, "cms_content_model_id", $this->integer()->null()->comment("Связь с моделью"));
18+
19+
$this->createIndex("{$tableName}__cms_content_model_id", $tableName, "cms_content_model_id");
20+
21+
$this->addForeignKey(
22+
"{$tableName}__cms_content_model_id", $tableName,
23+
'cms_content_model_id', '{{%cms_content_model}}', 'id', 'SET NULL', 'SET NULL'
24+
);
25+
}
26+
27+
public function safeDown()
28+
{
29+
echo "m240411_142301__alter_table__shop_store cannot be reverted.\n";
30+
return false;
31+
}
32+
}

src/models/CmsContent.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
* @property CmsContent[] $childrenContents
7777
* @property CmsTreeType $savedFilterTreeType
7878
* @property CmsTreeType $cmsTreeType
79+
* @property bool $isProducts
7980
*/
8081
class CmsContent extends Core
8182
{
@@ -492,6 +493,11 @@ public function isAllowEdit($code)
492493
return (bool)in_array((string)$code, (array)$this->editable_fields);
493494
}
494495

496+
public function getIsProducts()
497+
{
498+
return (bool) ($this->base_role == 'products');
499+
}
500+
495501
/**
496502
* @return CmsContentQuery
497503
*/

src/models/CmsContentElement.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
* @property string $meta_keywords
6060
* @property string $seo_h1
6161
* @property integer|null $cms_site_id
62-
*
62+
* @property integer|null $cms_content_model_id
63+
*
6364
* @property string|null $external_id
6465
* @property integer|null $main_cce_id
6566
* @property integer|null $main_cce_at
@@ -115,6 +116,7 @@
115116
* @property string $seoName
116117
*
117118
* @property CmsContentElement $mainCmsContentElement
119+
* @property CmsContentModel $cmsContentModel
118120
*
119121
*/
120122
class CmsContentElement extends RelatedElementModel
@@ -342,6 +344,7 @@ public function rules()
342344
'main_cce_by',
343345
'is_adult',
344346
'sx_id',
347+
'cms_content_model_id',
345348
],
346349
'integer',
347350
],
@@ -355,6 +358,7 @@ public function rules()
355358
[['external_id'], 'trim'],
356359
[['external_id'], 'string', 'max' => 255],
357360
[['external_id'], 'default', 'value' => null],
361+
[['cms_content_model_id'], 'default', 'value' => null],
358362
/*[
359363
['content_id', 'code'],
360364
'unique',
@@ -521,6 +525,16 @@ function ($attribute) {
521525

522526
]);
523527
}
528+
529+
/**
530+
* @return CmsContentModel
531+
*/
532+
public function getCmsContentModel()
533+
{
534+
return $this->hasOne(CmsContentModel::class, ['id' => 'cms_content_model_id'])->from(['cmsContentModel' => CmsContentModel::tableName()]);
535+
536+
}
537+
524538
/**
525539
* Валидация родительского элемента
526540
*
@@ -1119,6 +1133,48 @@ public static function find()
11191133
return new CmsContentElementActiveQuery(get_called_class(), ['is_active' => false]);
11201134
}
11211135

1136+
1137+
1138+
public function joinToModel(array $element_ids = [])
1139+
{
1140+
if ($element_ids) {
1141+
1142+
$t = \Yii::$app->db->beginTransaction();
1143+
1144+
try {
1145+
if (!$this->cms_content_model_id) {
1146+
$spModel = new CmsContentModel();
1147+
if (!$spModel->save()) {
1148+
throw new Exception(print_r($spModel->errors, true));
1149+
}
1150+
1151+
$this->cms_content_model_id = $spModel->id;
1152+
$this->update(false, ['cms_content_model_id']);
1153+
} else {
1154+
$spModel = $this->cmsContentModel;
1155+
}
1156+
1157+
1158+
foreach ($element_ids as $product_id) {
1159+
if ($product_id) {
1160+
1161+
if ($sp = CmsContentElement::findOne($product_id)) {
1162+
$sp->cms_content_model_id = $spModel->id;
1163+
$sp->update(false, ['cms_content_model_id']);
1164+
}
1165+
1166+
}
1167+
1168+
}
1169+
1170+
$t->commit();
1171+
} catch (\Exception $exception) {
1172+
$t->rollBack();
1173+
throw $exception;
1174+
}
1175+
1176+
}
1177+
}
11221178
}
11231179

11241180

src/models/CmsContentModel.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* @author Semenov Alexander <[email protected]>
4+
* @link http://skeeks.com/
5+
* @copyright 2010 SkeekS (СкикС)
6+
* @date 14.09.2015
7+
*/
8+
9+
namespace skeeks\cms\models;
10+
11+
use skeeks\cms\base\ActiveRecord;
12+
13+
/**
14+
*
15+
* @property integer $id
16+
* @property integer $created_at
17+
*
18+
* @property CmsContentElement[] $cmsContentElements
19+
*/
20+
class CmsContentModel extends ActiveRecord
21+
{
22+
/**
23+
* @inheritdoc
24+
*/
25+
public static function tableName()
26+
{
27+
return '{{%cms_content_model}}';
28+
}
29+
30+
31+
/**
32+
* @return \yii\db\ActiveQuery
33+
*/
34+
public function getCmsContentElements()
35+
{
36+
return $this->hasMany(CmsContentElement::class, ['cms_content_model_id' => 'id']);
37+
}
38+
39+
}

0 commit comments

Comments
 (0)