Reduce complexity of create_table method

This commit is contained in:
Timothy Warren 2014-04-24 13:08:26 -04:00
parent 0baf624e8b
commit 1f744088f2
2 changed files with 34 additions and 13 deletions

View File

@ -74,6 +74,36 @@ function db_filter($array, $index)
// --------------------------------------------------------------------------
/**
* Zip a set of arrays together on common keys
*
* The $zipper_input array is an array of arrays indexed by their place in the output
* array.
*
* @param array $zipper_input
* @return array
*/
function array_zipper(Array $zipper_input)
{
$output = array();
foreach($zipper_input as $append_key => $values)
{
foreach($values as $index => $value)
{
if ( ! isset($output[$index]))
{
$output[$index] = array();
}
$output[$index][$append_key] = $value;
}
}
return $output;
}
// --------------------------------------------------------------------------
/**
* Connection function
*

View File

@ -80,19 +80,10 @@ abstract class Abstract_Util {
// 'constraint' => ...,
// 'index' => ...,
// )
foreach($fields as $colname => $type)
{
$column_array[$colname] = array();
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
}
if( ! empty($constraints))
{
foreach($constraints as $col => $const)
{
$column_array[$col]['constraint'] = $const;
}
}
$column_array = \array_zipper(array(
'type' => $fields,
'constraint' => $constraints
));
// Join column definitions together
$columns = array();