Reduce complexity of create_table method
This commit is contained in:
parent
0baf624e8b
commit
1f744088f2
30
common.php
30
common.php
@ -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
|
||||
*
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user