Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Mar 7, 2020
1 parent d78d276 commit d36ef88
Show file tree
Hide file tree
Showing 6 changed files with 357 additions and 40 deletions.
35 changes: 17 additions & 18 deletions src/config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
},
],
],
],
],
],
Expand All @@ -43,7 +42,7 @@
],
],
'modules' => [
'measure' => [
'cms-measure' => [
'class' => 'skeeks\cms\measure\Module',
],
],
Expand Down
73 changes: 51 additions & 22 deletions src/controllers/AdminMeasureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
*/
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();
}
Expand All @@ -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'
]
]
],
],

Expand All @@ -69,19 +82,35 @@ public function actions()

"update" => [
'fields' => [$this, 'updateFields'],
],*/
],
]);
}


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
]
]
],
];
}

Expand Down
78 changes: 78 additions & 0 deletions src/migrations/m200307_090601_create_table__cms_measure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @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;
}
}
104 changes: 104 additions & 0 deletions src/migrations/m200307_090602_append_data_table__cms_measure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/**
* @author Semenov Alexander <[email protected]>
* @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;
}
}
Loading

0 comments on commit d36ef88

Please sign in to comment.