diff --git a/src/config/web.php b/src/config/web.php index 2ea2ace..a6ade66 100644 --- a/src/config/web.php +++ b/src/config/web.php @@ -11,29 +11,28 @@ 'menu' => [ 'data' => [ - 'other' => [ + 'settings' => [ 'items' => [ [ - "name" => ['skeeks/measure', 'Units of measurement'], - "image" => ['\skeeks\cms\measure\assets\Asset', 'icons/misc.png'], + "name" => ['skeeks/measure', 'Units of measurement'], + "image" => ['\skeeks\cms\measure\assets\Asset', 'icons/misc.png'], - 'items' => + 'items' => [ [ - [ - "name" => ['skeeks/measure', 'Units of measurement'], - "url" => ["measure/admin-measure"], - "image" => ['\skeeks\cms\measure\assets\Asset', 'icons/misc.png'], - ], + "name" => ['skeeks/measure', 'Units of measurement'], + "url" => ["cms-measure/admin-measure"], + "image" => ['\skeeks\cms\measure\assets\Asset', 'icons/misc.png'], + ], - [ - "name" => ['skeeks/measure', 'Settings'], - "url" => ["cms/admin-settings", "component" => 'skeeks\cms\measure\components\MeasureComponent'], - "image" => ['skeeks\cms\assets\CmsAsset', 'images/icons/settings.png'], - "activeCallback" => function ($adminMenuItem) { - return (bool)(\Yii::$app->request->getUrl() == $adminMenuItem->getUrl()); - }, - ], + [ + "name" => ['skeeks/measure', 'Settings'], + "url" => ["cms/admin-settings", "component" => 'skeeks\cms\measure\components\MeasureComponent'], + "image" => ['skeeks\cms\assets\CmsAsset', 'images/icons/settings.png'], + "activeCallback" => function ($adminMenuItem) { + return (bool)(\Yii::$app->request->getUrl() == $adminMenuItem->getUrl()); + }, ], + ], ], ], ], @@ -43,7 +42,7 @@ ], ], 'modules' => [ - 'measure' => [ + 'cms-measure' => [ 'class' => 'skeeks\cms\measure\Module', ], ], diff --git a/src/controllers/AdminMeasureController.php b/src/controllers/AdminMeasureController.php index 3b398b8..e26fef3 100644 --- a/src/controllers/AdminMeasureController.php +++ b/src/controllers/AdminMeasureController.php @@ -8,25 +8,28 @@ namespace skeeks\cms\measure\controllers; -use skeeks\cms\backend\BackendController; +use skeeks\cms\backend\controllers\BackendModelStandartController; +use skeeks\cms\backend\grid\DefaultActionColumn; use skeeks\cms\backend\ViewBackendAction; use skeeks\cms\kladr\models\KladrLocation; -use skeeks\cms\measure\models\Measure; +use skeeks\cms\measure\models\CmsMeasure; +use skeeks\yii2\form\fields\FieldSet; +use skeeks\yii2\form\fields\NumberField; use yii\helpers\ArrayHelper; /** * @author Semenov Alexander */ -class AdminMeasureController extends BackendController +class AdminMeasureController extends BackendModelStandartController { public function init() { $this->name = \Yii::t('skeeks/measure', 'Units of measurement'); - /*$this->name = \Yii::t('skeeks/measure', 'Units of measurement'); - $this->modelShowAttribute = "code"; - $this->modelClassName = Measure::className(); - $this->generateAccessActions = false;*/ + $this->modelShowAttribute = "asText"; + $this->modelClassName = CmsMeasure::class; + + $this->generateAccessActions = false; parent::init(); } @@ -37,28 +40,38 @@ public function init() public function actions() { return ArrayHelper::merge(parent::actions(), [ - 'index' => [ + 'classifier' => [ 'class' => ViewBackendAction::class, - ] - /*'index' => [ + 'name' => 'Классификатор', + 'icon' => 'fa fa-list' + ], + 'index' => [ 'filters' => [ 'visibleFilters' => [ + 'code', 'name', ], ], - 'grid' => [ + 'defaultOrder' => [ + //'def' => SORT_DESC, + 'priority' => SORT_ASC + ], "visibleColumns" => [ 'checkbox', 'actions', - 'code', - 'name', + 'customName', - 'symbol', - 'symbol_intl', - 'symbol_letter_intl', + 'priority', ], + 'columns' => [ + 'customName' => [ + 'attribute' => 'name', + 'class' => DefaultActionColumn::class, + 'viewAttribute' => 'asText' + ] + ] ], ], @@ -69,7 +82,7 @@ public function actions() "update" => [ 'fields' => [$this, 'updateFields'], - ],*/ + ], ]); } @@ -77,11 +90,27 @@ public function actions() public function updateFields() { return [ - 'code', - 'name', - 'symbol', - 'symbol_intl', - 'symbol_letter_intl', + 'main' => [ + 'class' => FieldSet::class, + 'name' => 'Основные данные', + 'fields' => [ + 'code', + 'name', + 'symbol', + ] + ], + 'second' => [ + 'class' => FieldSet::class, + 'elementOptions' => ['isOpen' => false], + 'name' => 'Дополнительно', + 'fields' => [ + 'symbol_intl', + 'symbol_letter_intl', + 'priority' => [ + 'class' => NumberField::class + ] + ] + ], ]; } diff --git a/src/migrations/m200307_090601_create_table__cms_measure.php b/src/migrations/m200307_090601_create_table__cms_measure.php new file mode 100644 index 0000000..faa33b7 --- /dev/null +++ b/src/migrations/m200307_090601_create_table__cms_measure.php @@ -0,0 +1,78 @@ + + * @link http://skeeks.com/ + * @copyright 2010 SkeekS (СкикС) + * @date 28.08.2015 + */ +use yii\db\Migration; + +class m200307_090601_create_table__cms_measure extends Migration +{ + public function safeUp() + { + $tableExist = $this->db->getTableSchema("{{%cms_measure}}", true); + if ($tableExist) { + return true; + } + + $tableOptions = null; + if ($this->db->driverName === 'mysql') { + $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=InnoDB'; + } + + $this->createTable("{{%cms_measure}}", [ + + 'id' => $this->primaryKey(), + + 'created_by' => $this->integer(), + 'updated_by' => $this->integer(), + + 'created_at' => $this->integer(), + 'updated_at' => $this->integer(), + + 'code' => $this->string(20)->notNull()->unique(), + 'name' => $this->string(128)->notNull(), + + 'symbol' => $this->string(20), + + 'symbol_intl' => $this->string(20), + 'symbol_letter_intl' => $this->string(20), + + 'priority' => $this->integer()->notNull()->defaultValue(500), + + ], $tableOptions); + + + $this->createIndex('cms_measure__updated_by', '{{%cms_measure}}', 'updated_by'); + $this->createIndex('cms_measure__created_by', '{{%cms_measure}}', 'created_by'); + $this->createIndex('cms_measure__created_at', '{{%cms_measure}}', 'created_at'); + $this->createIndex('cms_measure__updated_at', '{{%cms_measure}}', 'updated_at'); + + $this->createIndex('cms_measure__name', '{{%cms_measure}}', 'name'); + + $this->createIndex('cms_measure__code', '{{%cms_measure}}', 'code'); + $this->createIndex('cms_measure__symbol', '{{%cms_measure}}', 'symbol'); + $this->createIndex('cms_measure__symbol_intl', '{{%cms_measure}}', 'symbol_intl'); + $this->createIndex('cms_measure__symbol_letter_intl', '{{%cms_measure}}', 'symbol_letter_intl'); + $this->createIndex('cms_measure__priority', '{{%cms_measure}}', 'priority'); + + $this->addForeignKey( + 'cms_measure_created_by', "{{%cms_measure}}", + 'created_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL' + ); + + $this->addForeignKey( + 'cms_measure_updated_by', "{{%cms_measure}}", + 'updated_by', '{{%cms_user}}', 'id', 'SET NULL', 'SET NULL' + ); + + + } + + public function safeDown() + { + echo "m191204_180601_alter_table__measure cannot be reverted.\n"; + return false; + } +} \ No newline at end of file diff --git a/src/migrations/m200307_090602_append_data_table__cms_measure.php b/src/migrations/m200307_090602_append_data_table__cms_measure.php new file mode 100644 index 0000000..0142ad8 --- /dev/null +++ b/src/migrations/m200307_090602_append_data_table__cms_measure.php @@ -0,0 +1,104 @@ + + * @link http://skeeks.com/ + * @copyright 2010 SkeekS (СкикС) + * @date 28.08.2015 + */ +use yii\db\Migration; + +class m200307_090602_append_data_table__cms_measure extends Migration +{ + public function safeUp() + { + $this->insert('{{%cms_measure}}', [ + 'code' => '796', + 'name' => 'Штука', + 'symbol' => 'шт', + 'symbol_intl' => 'pc. 1', + 'symbol_letter_intl' => 'PCE. NMB', + 'priority' => 100, + ]); + + + $this->insert('{{%cms_measure}}', [ + 'code' => '778', + 'name' => 'Упаковка', + 'symbol' => 'упак', + 'symbol_letter_intl' => 'NMP', + 'priority' => 200, + + ]); + + + $this->insert('{{%cms_measure}}', [ + 'code' => '003', + 'name' => 'Миллиметр', + 'symbol' => 'мм', + 'symbol_intl' => 'mm', + 'symbol_letter_intl' => 'MMT', + 'priority' => 300, + ]); + + $this->insert('{{%cms_measure}}', [ + 'code' => '006', + 'name' => 'Метр', + 'symbol' => 'м', + 'symbol_intl' => 'm', + 'symbol_letter_intl' => 'MTR', + 'priority' => 310, + ]); + + + $this->insert('{{%cms_measure}}', [ + 'code' => '163', + 'name' => 'Грамм', + 'symbol' => 'г', + 'symbol_intl' => 'g', + 'symbol_letter_intl' => 'GRM', + 'priority' => 320, + ]); + + $this->insert('{{%cms_measure}}', [ + 'code' => '166', + 'name' => 'Килограмм', + 'symbol' => 'кг', + 'symbol_intl' => 'kg', + 'symbol_letter_intl' => 'KGM', + 'priority' => 330, + ]); + + + $this->insert('{{%cms_measure}}', [ + 'code' => '112', + 'name' => 'Литр', + 'symbol' => 'л', + 'symbol_intl' => 'l', + 'symbol_letter_intl' => 'LTR', + 'priority' => 340, + ]); + + + $this->insert('{{%cms_measure}}', [ + 'code' => '055', + 'name' => 'Квадратный метр', + 'symbol' => 'м2', + 'symbol_intl' => 'm2', + 'symbol_letter_intl' => 'MTK', + 'priority' => 350, + ]); + + $this->insert('{{%cms_measure}}', [ + 'code' => '383', + 'name' => 'Рубль', + 'symbol' => 'руб', + ]); + + } + + public function safeDown() + { + echo "m191204_180601_alter_table__measure cannot be reverted.\n"; + return false; + } +} \ No newline at end of file diff --git a/src/models/CmsMeasure.php b/src/models/CmsMeasure.php new file mode 100644 index 0000000..9eeded8 --- /dev/null +++ b/src/models/CmsMeasure.php @@ -0,0 +1,107 @@ + + */ +namespace skeeks\cms\measure\models; + +use skeeks\cms\base\ActiveRecord; +use Yii; +use yii\helpers\ArrayHelper; + +/** + * This is the model class for table "cms_measure". + * + * @property int $id + * @property int|null $created_by + * @property int|null $updated_by + * @property int|null $created_at + * @property int|null $updated_at + * @property string $code + * @property string $name + * @property string|null $symbol + * @property string|null $symbol_intl + * @property string|null $symbol_letter_intl + * @property int $priority + * + * @property string $asShortText + */ +class CmsMeasure extends ActiveRecord +{ + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'cms_measure'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return ArrayHelper::merge(parent::rules(), [ + [['created_by', 'updated_by', 'created_at', 'updated_at', 'priority'], 'integer'], + [['code', 'name'], 'required'], + [['name'], 'string', 'max' => 128], + [['code'], 'string', 'max' => 20], + [['symbol', 'symbol_intl', 'symbol_letter_intl'], 'string', 'max' => 20], + [['code'], 'unique'], + ]); + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return ArrayHelper::merge(parent::attributeLabels(), [ + 'code' => 'Код', + 'name' => 'Наименование', + 'symbol' => 'Условное обозначение', + 'symbol_intl' => 'Условное обозначение международное', + 'symbol_letter_intl' => 'Кодовое буквенное обозначение международное', + 'priority' => 'Сортировка', + ]); + } + + /** + * {@inheritdoc} + */ + public function attributeHints() + { + return ArrayHelper::merge(parent::attributeLabels(), [ + 'code' => 'Уникальный код единицы измерения, обычно берется из классификатора', + 'symbol' => 'Короткое обозначение единицы измерения. Например шт. упак и т.д.', + ]); + } + + /** + * @return string + */ + public function asText() + { + $result = "#" . $this->code . "#" . $this->name; + + if ($this->symbol) { + $result = $result . " ($this->symbol)"; + } + + return $result; + } + + /** + * @return string + */ + public function getAsShortText() + { + if ($this->symbol) { + return $this->symbol; + } + + return $this->name; + } +} \ No newline at end of file diff --git a/src/views/admin-measure/index.php b/src/views/admin-measure/classifier.php similarity index 100% rename from src/views/admin-measure/index.php rename to src/views/admin-measure/classifier.php