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
|
* Connection function
|
||||||
*
|
*
|
||||||
|
@ -80,19 +80,10 @@ abstract class Abstract_Util {
|
|||||||
// 'constraint' => ...,
|
// 'constraint' => ...,
|
||||||
// 'index' => ...,
|
// 'index' => ...,
|
||||||
// )
|
// )
|
||||||
foreach($fields as $colname => $type)
|
$column_array = \array_zipper(array(
|
||||||
{
|
'type' => $fields,
|
||||||
$column_array[$colname] = array();
|
'constraint' => $constraints
|
||||||
$column_array[$colname]['type'] = ($type !== $colname) ? $type : '';
|
));
|
||||||
}
|
|
||||||
|
|
||||||
if( ! empty($constraints))
|
|
||||||
{
|
|
||||||
foreach($constraints as $col => $const)
|
|
||||||
{
|
|
||||||
$column_array[$col]['constraint'] = $const;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Join column definitions together
|
// Join column definitions together
|
||||||
$columns = array();
|
$columns = array();
|
||||||
|
Loading…
Reference in New Issue
Block a user