Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jan 24, 2020
1 parent afdcab2 commit d6ac7bc
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/components/MeasureComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,20 @@ public function rules()
public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'default_measure_code' => 'Валюта по умолчанию',
'active_measure_codes' => 'Включенные для выбора валюты',
'default_measure_code' => 'Единица по умолчанию',
'active_measure_codes' => 'Валюты по умолчанию',
]);
}

public function attributeHints()
{
return ArrayHelper::merge(parent::attributeHints(), [
'active_measure_codes' => 'Валюты которые показываются первыми при выборе в списке',
]);
}



/**
* @return Measure[]
*/
Expand All @@ -112,7 +114,45 @@ public function getActiveMeasures()
}
}

return $result;
}

public function getDataForSelect()
{
$result = [];

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

$result["По умолчанию"] = $first;

foreach (\Yii::$app->measureClassifier->data as $key => $data)
{
$title1 = ArrayHelper::getValue($data, 'title');
ArrayHelper::remove($data, 'title');

foreach ($data as $subKey => $subData)
{
$title = ArrayHelper::getValue($subData, 'title') . " - " . $title1;
ArrayHelper::remove($subData, 'title');
$tmpArr = [];

foreach ((array) $subData as $measureKey => $measure)
{
if (!in_array(ArrayHelper::getValue($measure, 'code'), $this->active_measure_codes)) {
$tmpArr[ArrayHelper::getValue($measure, 'code')] = ArrayHelper::getValue($measure, 'name') . " (" . ArrayHelper::getValue($measure, 'symbol') . ") " . "[" . ArrayHelper::getValue($measure, 'code') . "]";
}
}

$result[$title] = $tmpArr;
}
}

return $result;
}
}

0 comments on commit d6ac7bc

Please sign in to comment.