Skip to content

Commit

Permalink
Turn the internal codes table into a lookup table
Browse files Browse the repository at this point in the history
Toward #98.
  • Loading branch information
waldoj committed Sep 28, 2019
1 parent 79a2b0f commit 8a17449
Show file tree
Hide file tree
Showing 2 changed files with 2,964 additions and 2,934 deletions.
30 changes: 30 additions & 0 deletions includes/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,33 @@ function get_content($url)
$api_url .= '://';
$api_url .= $_SERVER['SERVER_NAME'];
define('API_URL', $api_url);

/*
* Fetch the conversion table
*/
$tables_json = file_get_contents('includes/tables.json');

/*
* Convert to an array
*/
$tables = json_decode($tables_json, TRUE);

$lookup_table = array();

/*
* Reduce and pivot the table into a nested key/value lookup
*/
foreach ($tables as $entry)
{
unset($entry['TableID']);
$entry['TableContents'] = strtolower($entry['TableContents']);
$entry['TableContents'] = preg_replace('/[\&\.\/]/', '', $entry['TableContents']);
$entry['TableContents'] = preg_replace('/\W+/', '-', $entry['TableContents']);

if (!isset($lookup_table[$entry{'TableContents'}]))
{
$lookup_table[$entry{'TableContents'}] = array();
}

$lookup_table[$entry{'TableContents'}][$entry{'ColumnValue'}] = $entry['Description'];
}
Loading

0 comments on commit 8a17449

Please sign in to comment.