Created
November 8, 2016 08:55
-
-
Save mikekamornikov/026319193bd53e6b5ae6947659eb58da to your computer and use it in GitHub Desktop.
$dictionary to Ext parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dictionary_to_extensions() | |
{ | |
global $dictionary; | |
$keySeparator = '~'; | |
$iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($dictionary)); | |
$paths = []; | |
foreach ($iterator as $key => $value) { | |
for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) { | |
$key = $iterator->getSubIterator($i)->key() . $keySeparator . $key; | |
} | |
$paths[] = $key; | |
} | |
$parsedArray = array_map(function($keyPath) use ($dictionary, $keySeparator) { | |
$keys = explode($keySeparator, $keyPath); | |
$path = '[\'' . implode('\'][\'', $keys) . '\']'; | |
$value = $dictionary; | |
foreach ($keys as $key) { | |
$value = $value[$key]; | |
} | |
if (is_bool($value)) { | |
$value = $value ? 'true' : 'false'; | |
} elseif (!is_numeric($value)) { | |
$value = "'$value'"; | |
} | |
return '$dictionary' . $path . ' = ' . $value . ';'; | |
}, $paths); | |
echo implode(PHP_EOL, $parsedArray), PHP_EOL; | |
} | |
$dictionary['Account']['fields']['global_buying_group_name'] = [ | |
'name' => 'global_buying_group_name', | |
'vname' => 'LBL_GB_BUYING_HIERARCHY_LINK_NAME', | |
'type' => 'text', | |
'source'=>'non-db', | |
'len' => 36, | |
]; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search'] = [ | |
'type' => 'enum_values', | |
'enabled' => true, | |
'searchable' => true, | |
'aggregations' => [ | |
'agg_global_buying_group_name' => [ | |
'type' => 'Terms', | |
// TODO: implement UI part (label, ui_type) | |
'label' => 'LBL_FACET_GLOBAL_BUYING_GROUP', | |
'ui_type' => 'select', | |
'options' => [ | |
'field' => 'global_buying_group_name', | |
], | |
], | |
], | |
]; | |
dictionary_to_extensions(); | |
/* | |
$dictionary['Account']['fields']['global_buying_group_name']['name'] = 'global_buying_group_name'; | |
$dictionary['Account']['fields']['global_buying_group_name']['vname'] = 'LBL_GB_BUYING_HIERARCHY_LINK_NAME'; | |
$dictionary['Account']['fields']['global_buying_group_name']['type'] = 'text'; | |
$dictionary['Account']['fields']['global_buying_group_name']['source'] = 'non-db'; | |
$dictionary['Account']['fields']['global_buying_group_name']['len'] = 36; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['type'] = 'enum_values'; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['enabled'] = true; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['searchable'] = true; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['aggregations']['agg_global_buying_group_name']['type'] = 'Terms'; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['aggregations']['agg_global_buying_group_name']['label'] = 'LBL_FACET_GLOBAL_BUYING_GROUP'; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['aggregations']['agg_global_buying_group_name']['ui_type'] = 'select'; | |
$dictionary['Account']['fields']['global_buying_group_name']['full_text_search']['aggregations']['agg_global_buying_group_name']['options']['field'] = 'global_buying_group_name'; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment