diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index cefd54fed3..ad50bce3fb 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -188,66 +188,63 @@ function PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause } /** - * Show function fields in data edit view in pma + * Show type information or function selectors in Insert/Edit * - * @param array $url_params containing url parameters - * @param boolean $showFuncFields whether to show function field + * @param string $which function|type + * @param array $url_params containing url parameters + * @param boolean $is_show whether to show the element in $which * - * @return string an html snippet + * @return string an HTML snippet */ -function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields) +function PMA_showTypeOrFunction($which, $url_params, $is_show) { $params = array(); - if (! $showFuncFields) { - $params['ShowFunctionFields'] = 1; - } else { - $params['ShowFunctionFields'] = 0; + + switch($which) { + case 'function': + $params['ShowFunctionFields'] = ($is_show ? 0 : 1); + $params['ShowFieldTypesInDataEditView'] + = $GLOBALS['cfg']['ShowFieldTypesInDataEditView']; + break; + case 'type': + $params['ShowFieldTypesInDataEditView'] = ($is_show ? 0 : 1); + $params['ShowFunctionFields'] + = $GLOBALS['cfg']['ShowFunctionFields']; + break; } - $params['ShowFieldTypesInDataEditView'] - = $GLOBALS['cfg']['ShowFieldTypesInDataEditView']; + $params['goto'] = 'sql.php'; $this_url_params = array_merge($url_params, $params); - if (! $showFuncFields) { + + if (! $is_show) { return ' : ' - . __('Function') - . '' . "\n"; + . PMA_showTypeOrFunctionLabel($which) + . ''; } - return '' - . __('Function') - . '' . "\n"; + . PMA_showTypeOrFunctionLabel($which) + . ''; } /** - * Show field types in data edit view in pma + * Show type information or function selectors labels in Insert/Edit * - * @param array $url_params containing url parameters - * @param boolean $showColumnType whether to show column type + * @param string $which function|type * - * @return string an html snippet + * @return string an HTML snippet */ -function PMA_showColumnTypesInDataEditView($url_params, $showColumnType) +function PMA_showTypeOrFunctionLabel($which) { - $params = array(); - if (! $showColumnType) { - $params['ShowFieldTypesInDataEditView'] = 1; - } else { - $params['ShowFieldTypesInDataEditView'] = 0; + switch($which) { + case 'function': + return __('Function'); + case 'type': + return __('Type'); } - $params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields']; - $params['goto'] = 'sql.php'; - $this_other_url_params = array_merge($url_params, $params); - if (! $showColumnType) { - return ' : ' - . __('Type') . '' . "\n"; - } - return '' . __('Type') . '' . "\n"; - + return $html; } /** @@ -1575,10 +1572,10 @@ function PMA_getHeadAndFootOfInsertRowTable($url_params) . '' . __('Column') . ''; if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) { - $html_output .= PMA_showColumnTypesInDataEditView($url_params, true); + $html_output .= PMA_showTypeOrFunction('type', $url_params, true); } if ($GLOBALS['cfg']['ShowFunctionFields']) { - $html_output .= PMA_showFunctionFieldsInEditMode($url_params, true); + $html_output .= PMA_showTypeOrFunction('function', $url_params, true); } $html_output .= '' . __('Null') . '' diff --git a/tbl_change.php b/tbl_change.php index e3f4a433e2..67472fa9a1 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -159,11 +159,11 @@ if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) { } if (! $cfg['ShowFunctionFields']) { - $html_output .= PMA_showFunctionFieldsInEditMode($url_params, false); + $html_output .= PMA_showTypeOrFunction('function', $url_params, false); } if (! $cfg['ShowFieldTypesInDataEditView']) { - $html_output .= PMA_showColumnTypesInDataEditView($url_params, false); + $html_output .= PMA_showTypeOrFunction('type', $url_params, false); } $GLOBALS['plugin_scripts'] = array(); diff --git a/test/libraries/PMA_insert_edit_test.php b/test/libraries/PMA_insert_edit_test.php index 1240eef2bb..2cb9e81a93 100644 --- a/test/libraries/PMA_insert_edit_test.php +++ b/test/libraries/PMA_insert_edit_test.php @@ -283,64 +283,52 @@ class PMA_InsertEditTest extends PHPUnit_Framework_TestCase } /** - * Test for PMA_showFunctionFieldsInEditMode + * Test for PMA_showTypeOrFunction * * @return void */ - public function testShowFunctionFieldsInEditMode() + public function testShowTypeOrFunction() { $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true; $GLOBALS['cfg']['ServerDefault'] = 1; $url_params = array('ShowFunctionFields' => 2); - $result = PMA_showFunctionFieldsInEditMode($url_params, false); + $result = PMA_showTypeOrFunction('function', $url_params, false); $this->assertEquals( ' : ' - . 'Function' . "\n", + . 'Function', $result ); // case 2 - $result = PMA_showFunctionFieldsInEditMode($url_params, true); + $result = PMA_showTypeOrFunction('function', $url_params, true); $this->assertEquals( 'Function' . "\n", + . '"Hide">Function', $result ); - } - /** - * Test for PMA_showColumnTypesInDataEditView - * - * @return void - */ - public function testShowColumnTypesInDataEditView() - { - $GLOBALS['cfg']['ShowFieldTypesInDataEditView'] = true; - $GLOBALS['cfg']['ShowFunctionFields'] = true; - $GLOBALS['cfg']['ServerDefault'] = 1; - $url_params = array('ShowFunctionFields' => 2); - - $result = PMA_showColumnTypesInDataEditView($url_params, false); + // case 3 + $result = PMA_showTypeOrFunction('type', $url_params, false); $this->assertEquals( ' : ' - . 'Type' . "\n", + . 'Type', $result ); - // case 2 - $result = PMA_showColumnTypesInDataEditView($url_params, true); + // case 4 + $result = PMA_showTypeOrFunction('type', $url_params, true); $this->assertEquals( 'Type' . "\n", + . '"Hide">Type', $result ); }