Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Dec 4, 2019
1 parent d426258 commit 33d2b7c
Show file tree
Hide file tree
Showing 11 changed files with 234 additions and 5,012 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
}
],
"require": {
"skeeks/cms": "~5.0 || dev-master"
"skeeks/cms": "~5.0 || dev-master",
"skeeks/yii2-measure-classifier": "^1.0.0 || dev-master"
},
"autoload": {
"psr-4": {
Expand Down
96 changes: 93 additions & 3 deletions src/components/MeasureComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
* @copyright 2010 SkeekS (СкикС)
* @date 10.09.2015
*/

namespace skeeks\cms\measure\components;

use skeeks\cms\base\Component;
use skeeks\yii2\form\fields\SelectField;
use skeeks\yii2\measureClassifier\Measure;
use yii\helpers\ArrayHelper;

/**
* Class MeasureComponent
* @package skeeks\cms\measure\components
* @property Measure[] $measures;
*
* @author Semenov Alexander <[email protected]>
*/
class MeasureComponent extends Component
{
Expand All @@ -22,7 +27,92 @@ class MeasureComponent extends Component
static public function descriptorConfig()
{
return array_merge(parent::descriptorConfig(), [
'name' => \Yii::t('skeeks/measure', 'Units of measurement'),
'name' => \Yii::t('skeeks/measure', 'Units of measurement'),
]);
}

public $default_measure_code = "796"; //шт.


public $active_measure_codes = [
"796",

"112",
"163",
"166",

"003",
"006",
];

/*public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
]);
}*/



public function getConfigFormFields()
{
return [
'default_measure_code' => [
'class' => SelectField::class,
'multiple' => false,
'items' => function() {
return \Yii::$app->measureClassifier->getDataForSelect();
}
],
'active_measure_codes' => [
'class' => SelectField::class,
'multiple' => true,
'items' => function() {
return \Yii::$app->measureClassifier->getDataForSelect();
}
],
];
}


public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['default_measure_code'], 'string'],
[['active_measure_codes'], 'safe'],
]);
}

public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'default_measure_code' => 'Валюта по умолчанию',
'active_measure_codes' => 'Включенные для выбора валюты',
]);
}

public function attributeHints()
{
return ArrayHelper::merge(parent::attributeHints(), [
]);
}


/**
* @return Measure[]
*/
public function getActiveMeasures()
{
$result = [];

foreach ((array) $this->active_measure_codes as $key => $code)
{
if ($model = \Yii::$app->measureClassifier->getMeasureByCode($code)) {
$result[$code] = $model;
}
}


return $result;
}
}
92 changes: 33 additions & 59 deletions src/controllers/AdminMeasureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

namespace skeeks\cms\measure\controllers;

use skeeks\cms\backend\BackendAction;
use skeeks\cms\backend\BackendController;
use skeeks\cms\backend\controllers\BackendModelStandartController;
use skeeks\cms\backend\ViewBackendAction;
use skeeks\cms\components\Cms;
use skeeks\cms\grid\BooleanColumn;
use skeeks\cms\helpers\RequestResponse;
use skeeks\cms\kladr\models\KladrLocation;
use skeeks\cms\measure\libs\MeasureClassifier;
use skeeks\cms\measure\models\Measure;
use skeeks\cms\modules\admin\actions\AdminAction;
use skeeks\cms\modules\admin\actions\modelEditor\AdminMultiModelEditAction;
Expand All @@ -26,17 +28,18 @@
* Class AdminKladrLocationController
* @package skeeks\cms\kladr\controllers
*/
class AdminMeasureController extends BackendModelStandartController
class AdminMeasureController extends BackendController
{
use AdminModelEditorStandartControllerTrait;

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->generateAccessActions = false;*/

parent::init();
}
Expand All @@ -47,78 +50,49 @@ public function init()
public function actions()
{
return ArrayHelper::merge(parent::actions(), [
'index' => [
'filters' => [
'visibleFilters' => [
'name',
],
'index' => [
'class' => ViewBackendAction::class
]
/*'index' => [
'filters' => [
'visibleFilters' => [
'name',
],
],
'grid' => [
"visibleColumns" => [
'checkbox',
'actions',

'code',
'name',

'symbol_rus',
'symbol_intl',
'symbol_letter_intl',
'grid' => [
"visibleColumns" => [
'checkbox',
'actions',
'def',
],
'code',
'name',
'columns' => [
'def' => [
'class' => BooleanColumn::class,
/*'falseValue' => 0,
'trueValue' => 1,*/
],
],
'symbol',
'symbol_intl',
'symbol_letter_intl',
],
],
],
"def-multi" => [
'class' => AdminMultiModelEditAction::className(),
"name" => \Yii::t('skeeks/measure', 'Default'),
//"icon" => "glyphicon glyphicon-trash",
"eachCallback" => [$this, 'eachMultiDef'],
"priority" => 0,
],
"create" => [
'fields' => [$this, 'updateFields'],
],
"create" => [
'fields' => [$this, 'updateFields'],
],
"update" => [
'fields' => [$this, 'updateFields'],
],
]
);
"update" => [
'fields' => [$this, 'updateFields'],
],*/
]);
}


/**
* @param $model
* @param $action
* @return bool
*/
public function eachMultiDef($model, $action)
public function updateFields()
{
try {
$model->def = Cms::BOOL_Y;
return $model->save(false);
} catch (\Exception $e) {
return false;
}
}

public function updateFields() {
return [
'code',
'name',
'symbol_rus',
'symbol',
'symbol_intl',
'symbol_letter_intl',
];
Expand Down
39 changes: 0 additions & 39 deletions src/libs/Loc.php

This file was deleted.

Loading

0 comments on commit 33d2b7c

Please sign in to comment.