Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Apr 28, 2020
1 parent dff1567 commit daa945d
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 199 deletions.
19 changes: 18 additions & 1 deletion src/controllers/AdminCmsContentElementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use skeeks\cms\queryfilters\filters\modes\FilterModeEq;
use skeeks\cms\queryfilters\filters\NumberFilterField;
use skeeks\cms\queryfilters\QueryFiltersEvent;
use skeeks\cms\shop\models\ShopCmsContentElement;
use skeeks\yii2\form\fields\BoolField;
use skeeks\yii2\form\fields\SelectField;
use skeeks\yii2\form\fields\TextField;
Expand All @@ -42,6 +43,7 @@
use yii\bootstrap\Alert;
use yii\caching\TagDependency;
use yii\db\ActiveQuery;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
Expand Down Expand Up @@ -214,13 +216,28 @@ public function actions()
//$query->joinWith("childrenContentElements as child");
//$query->joinWith("childrenContentElements.parentContentElement as parent");

$q = CmsContentElement::find()
->select(['parent_id' => 'parent_content_element_id'])
->where([
'or',
['like', CmsContentElement::tableName().'.id', $e->field->value],
['like', CmsContentElement::tableName().'.name', $e->field->value],
['like', CmsContentElement::tableName().'.description_short', $e->field->value],
['like', CmsContentElement::tableName().'.description_full', $e->field->value],
['like', CmsContentElement::tableName().'.external_id', $e->field->value],
])
;

$query->leftJoin(['p' => $q], ['p.parent_id' => new Expression(CmsContentElement::tableName().".id")]);

$query->andWhere([
'or',
['like', CmsContentElement::tableName().'.id', $e->field->value],
['like', CmsContentElement::tableName().'.name', $e->field->value],
['like', CmsContentElement::tableName().'.description_short', $e->field->value],
['like', CmsContentElement::tableName().'.description_full', $e->field->value],
//['like', 'child.name', $e->field->value],
['like', CmsContentElement::tableName().'.external_id', $e->field->value],
['is not', 'p.parent_id', null],
]);
}
},
Expand Down
24 changes: 24 additions & 0 deletions src/migrations/m200428_091000__alter_table__cms_content.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 28.08.2015
*/

use yii\db\Migration;

class m200428_091000__alter_table__cms_content extends Migration
{
public function safeUp()
{
$tableName = "cms_content";
$this->addColumn($tableName, "editable_fields", $this->text());
}

public function safeDown()
{
echo "m200410_121000__alter_table__cms_tree cannot be reverted.\n";
return false;
}
}
196 changes: 122 additions & 74 deletions src/models/CmsContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,59 @@

namespace skeeks\cms\models;

use skeeks\cms\components\Cms;
use skeeks\cms\models\behaviors\HasJsonFieldsBehavior;
use Yii;
use yii\helpers\ArrayHelper;

/**
* This is the model class for table "{{%cms_content}}".
*
* @property integer $id
* @property integer|null $created_by
* @property integer|null $updated_by
* @property integer|null $created_at
* @property integer|null $updated_at
* @property string $name
* @property string $code
* @property integer $priority
* @property string $description
* @property string $content_type
* @property string $index_for_search
* @property string $tree_chooser
* @property string $list_mode
* @property string $name_meny
* @property string $name_one
* @property integer $default_tree_id
* @property integer $is_allow_change_tree
* @property integer $is_active
* @property integer $is_count_views
* @property integer $root_tree_id
* @property string $view_file
* @property integer $is_access_check_element
* @property integer $id
* @property integer|null $created_by
* @property integer|null $updated_by
* @property integer|null $created_at
* @property integer|null $updated_at
* @property string $name
* @property string $code
* @property integer $priority
* @property string $description
* @property string $content_type
* @property string $index_for_search
* @property string $tree_chooser
* @property string $list_mode
* @property string $name_meny
* @property string $name_one
* @property integer $default_tree_id
* @property integer $is_allow_change_tree
* @property integer $is_active
* @property integer $is_count_views
* @property integer $root_tree_id
* @property string $view_file
* @property integer $is_access_check_element
* @property array $editable_fields
*
* @property string $meta_title_template
* @property string $meta_description_template
* @property string $meta_keywords_template
* @property string $meta_title_template
* @property string $meta_description_template
* @property string $meta_keywords_template
*
* @property integer $parent_content_id
* @property integer $is_visible
* @property string $parent_content_on_delete
* @property integer $is_parent_content_required
* @property integer $is_have_page
* @property integer $parent_content_id
* @property integer $is_visible
* @property string $parent_content_on_delete
* @property integer $is_parent_content_required
* @property integer $is_have_page
*
* ***
*
* @property string $adminPermissionName
* @property string $adminPermissionName
*
* @property CmsTree $rootTree
* @property CmsTree $defaultTree
* @property CmsContentType $contentType
* @property CmsContentElement[] $cmsContentElements
* @property CmsTree $rootTree
* @property CmsTree $defaultTree
* @property CmsContentType $contentType
* @property CmsContentElement[] $cmsContentElements
* @property CmsContentProperty[] $cmsContentProperties
*
* @property CmsContent $parentContent
* @property CmsContent[] $childrenContents
* @property CmsContent $parentContent
* @property CmsContent[] $childrenContents
*/
class CmsContent extends Core
{
Expand All @@ -74,10 +75,10 @@ class CmsContent extends Core
public static function getOnDeleteOptions()
{
return [
self::CASCADE => "CASCADE (" . \Yii::t('skeeks/cms', 'Remove all items of that content') . ")",
self::RESTRICT => "RESTRICT (" . \Yii::t('skeeks/cms',
'Deny delete parent is not removed, these elements') . ")",
self::SET_NULL => "SET NULL (" . \Yii::t('skeeks/cms', 'Remove the connection to a remote parent') . ")",
self::CASCADE => "CASCADE (".\Yii::t('skeeks/cms', 'Remove all items of that content').")",
self::RESTRICT => "RESTRICT (".\Yii::t('skeeks/cms',
'Deny delete parent is not removed, these elements').")",
self::SET_NULL => "SET NULL (".\Yii::t('skeeks/cms', 'Remove the connection to a remote parent').")",
];
}

Expand All @@ -89,47 +90,74 @@ public static function tableName()
return '{{%cms_content}}';
}

public function behaviors()
{
return array_merge(parent::behaviors(), [

HasJsonFieldsBehavior::className() => [
'class' => HasJsonFieldsBehavior::className(),
'fields' => ['editable_fields'],
],
]);
}

/**
* @inheritdoc
*/
public function attributeHints()
{
return array_merge(parent::attributeHints(), [
'is_have_page' => Yii::t('skeeks/cms', 'Если эта опция включена, то показываются настройки SEO и URL'),
'code' => Yii::t('skeeks/cms', 'The name of the template to draw the elements of this type will be the same as the name of the code.'),
'view_file' => Yii::t('skeeks/cms', 'The path to the template. If not specified, the pattern will be the same code.'),
'root_tree_id' => Yii::t('skeeks/cms', 'If it is set to the root partition, the elements can be tied to him and his sub.'),
'editable_fields' => Yii::t('skeeks/cms', 'Поля которые отображаются при редактировании. Если ничего не выбрано, то показываются все!'),
]);
}

/**
* @return array
*/
public function attributeLabels()
{
return array_merge(parent::attributeLabels(), [
'id' => Yii::t('skeeks/cms', 'ID'),
'created_by' => Yii::t('skeeks/cms', 'Created By'),
'updated_by' => Yii::t('skeeks/cms', 'Updated By'),
'created_at' => Yii::t('skeeks/cms', 'Created At'),
'updated_at' => Yii::t('skeeks/cms', 'Updated At'),
'name' => Yii::t('skeeks/cms', 'Name'),
'code' => Yii::t('skeeks/cms', 'Code'),
'is_active' => Yii::t('skeeks/cms', 'Active'),
'priority' => Yii::t('skeeks/cms', 'Priority'),
'description' => Yii::t('skeeks/cms', 'Description'),
'content_type' => Yii::t('skeeks/cms', 'Content Type'),
'id' => Yii::t('skeeks/cms', 'ID'),
'created_by' => Yii::t('skeeks/cms', 'Created By'),
'updated_by' => Yii::t('skeeks/cms', 'Updated By'),
'created_at' => Yii::t('skeeks/cms', 'Created At'),
'updated_at' => Yii::t('skeeks/cms', 'Updated At'),
'name' => Yii::t('skeeks/cms', 'Name'),
'code' => Yii::t('skeeks/cms', 'Code'),
'is_active' => Yii::t('skeeks/cms', 'Active'),
'priority' => Yii::t('skeeks/cms', 'Priority'),
'description' => Yii::t('skeeks/cms', 'Description'),
'content_type' => Yii::t('skeeks/cms', 'Content Type'),
'index_for_search' => Yii::t('skeeks/cms', 'To index for search module'),
'tree_chooser' => Yii::t('skeeks/cms', 'The Interface Binding Element to Sections'),
'list_mode' => Yii::t('skeeks/cms', 'View Mode Sections And Elements'),
'name_meny' => Yii::t('skeeks/cms', 'The Name Of The Elements (Plural)'),
'name_one' => Yii::t('skeeks/cms', 'The Name One Element'),
'tree_chooser' => Yii::t('skeeks/cms', 'The Interface Binding Element to Sections'),
'list_mode' => Yii::t('skeeks/cms', 'View Mode Sections And Elements'),
'name_meny' => Yii::t('skeeks/cms', 'The Name Of The Elements (Plural)'),
'name_one' => Yii::t('skeeks/cms', 'The Name One Element'),

'default_tree_id' => Yii::t('skeeks/cms', 'Default Section'),
'default_tree_id' => Yii::t('skeeks/cms', 'Default Section'),
'is_allow_change_tree' => Yii::t('skeeks/cms', 'Is Allow Change Default Section'),
'is_count_views' => Yii::t('skeeks/cms', 'Считать количество просмотров?'),
'root_tree_id' => Yii::t('skeeks/cms', 'Root Section'),
'view_file' => Yii::t('skeeks/cms', 'Template'),
'is_count_views' => Yii::t('skeeks/cms', 'Считать количество просмотров?'),
'root_tree_id' => Yii::t('skeeks/cms', 'Root Section'),
'view_file' => Yii::t('skeeks/cms', 'Template'),

'meta_title_template' => Yii::t('skeeks/cms', 'Шаблон META TITLE'),
'meta_title_template' => Yii::t('skeeks/cms', 'Шаблон META TITLE'),
'meta_description_template' => Yii::t('skeeks/cms', 'Шаблон META KEYWORDS'),
'meta_keywords_template' => Yii::t('skeeks/cms', 'Шаблон META DESCRIPTION'),
'meta_keywords_template' => Yii::t('skeeks/cms', 'Шаблон META DESCRIPTION'),

'is_access_check_element' => Yii::t('skeeks/cms', 'Включить управление доступом к элементам'),
'parent_content_id' => Yii::t('skeeks/cms', 'Parent content'),
'parent_content_id' => Yii::t('skeeks/cms', 'Parent content'),

'is_visible' => Yii::t('skeeks/cms', 'Show in menu'),
'parent_content_on_delete' => Yii::t('skeeks/cms', 'At the time of removal of the parent element'),
'is_visible' => Yii::t('skeeks/cms', 'Show in menu'),
'parent_content_on_delete' => Yii::t('skeeks/cms', 'At the time of removal of the parent element'),
'is_parent_content_required' => Yii::t('skeeks/cms', 'Parent element is required to be filled'),

'is_have_page' => Yii::t('skeeks/cms', 'У элементов есть страница на сайте.'),

'editable_fields' => Yii::t('skeeks/cms', 'Редактируемые поля'),
]);
}

Expand All @@ -141,7 +169,7 @@ public function rules()
return array_merge(parent::rules(), [
[
['created_by', 'updated_by', 'created_at', 'updated_at', 'priority', 'default_tree_id', 'root_tree_id', 'is_count_views', 'is_allow_change_tree', 'is_active'],
'integer'
'integer',
],
[['is_visible'], 'integer'],
[['is_parent_content_required'], 'integer'],
Expand Down Expand Up @@ -177,10 +205,15 @@ public function rules()
[
'code',
'default',
'value' => function($model, $attribute) {
return "sxauto" . md5(rand(1, 10) . time());
}
'value' => function ($model, $attribute) {
return "sxauto".md5(rand(1, 10).time());
},
],

[['editable_fields'], 'safe'],
//[['editable_fields'], 'default', 'value' => null],


]);
}

Expand Down Expand Up @@ -286,8 +319,7 @@ public function getCmsContentProperties()
['id' => 'cms_content_property_id'])
->via('cmsContentProperty2contents')
//->viaTable('cms_content_property2content', ['cms_content_id' => 'id'])
->orderBy('priority')
;
->orderBy('priority');
}


Expand All @@ -296,7 +328,7 @@ public function getCmsContentProperties()
*/
public function getAdminPermissionName()
{
return 'cms/admin-cms-content-element__' . $this->id;
return 'cms/admin-cms-content-element__'.$this->id;
}


Expand All @@ -322,7 +354,23 @@ public function getChildrenContents()
public function createElement()
{
return new CmsContentElement([
'content_id' => $this->id
'content_id' => $this->id,
]);
}


/**
* Разрешено редактировать поле?
*
* @param $code
* @return bool
*/
public function isAllowEdit($code)
{
if (!$this->editable_fields) {
return true;
}

return (bool) in_array((string) $code, (array) $this->editable_fields);
}
}
6 changes: 4 additions & 2 deletions src/models/CmsContentElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use skeeks\cms\components\Cms;
use skeeks\cms\components\urlRules\UrlRuleContentElement;
use skeeks\cms\models\behaviors\HasJsonFieldsBehavior;
use skeeks\cms\models\behaviors\HasMultiLangAndSiteFields;
use skeeks\cms\models\behaviors\HasRelatedProperties;
use skeeks\cms\models\behaviors\HasStatus;
Expand Down Expand Up @@ -232,7 +233,7 @@ public function attributeLabels()
'parent_content_element_id' => Yii::t('skeeks/cms', 'Parent element'),
'show_counter' => Yii::t('skeeks/cms', 'Number of views'),
'seo_h1' => Yii::t('skeeks/cms', 'SEO заголовок h1'),
'external_id' => Yii::t('skeeks/cms', 'Идентификатор внешней системы'),
'external_id' => Yii::t('skeeks/cms', 'Уникальный код'),
]);
}
/**
Expand Down Expand Up @@ -328,6 +329,7 @@ public function rules()
'minSize' => 256,
],
[['imageIds', 'fileIds'], 'safe'],

[
['imageIds'],
\skeeks\cms\validators\FileValidator::class,
Expand Down Expand Up @@ -384,7 +386,7 @@ function ($attribute) {
}
}
}
]
],
]);
}
/**
Expand Down

0 comments on commit daa945d

Please sign in to comment.