Skip to content

Commit

Permalink
Use templating
Browse files Browse the repository at this point in the history
Signed-off-by: Madhura Jayaratne <madhura.cj@gmail.com>
  • Loading branch information
madhuracj committed Nov 27, 2015
1 parent 2692af3 commit 090a7e4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 68 deletions.
78 changes: 10 additions & 68 deletions libraries/controllers/server/ServerCollationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace PMA\libraries\controllers\server;

use PMA\libraries\controllers\Controller;
use PMA\libraries\Template;

/**
* Handles viewing character sets and collations
Expand Down Expand Up @@ -60,73 +61,14 @@ public function indexAction()
function _getHtmlForCharsets($mysqlCharsets, $mysqlCollations,
$mysqlCharsetsDesc, $mysqlDftCollations, $mysqlCollAvailable
) {
/**
* Outputs the result
*/
$html = '<div id="div_mysql_charset_collations">' . "\n"
. '<table class="data noclick">' . "\n"
. '<tr><th id="collationHeader">' . __('Collation') . '</th>' . "\n"
. ' <th>' . __('Description') . '</th>' . "\n"
. '</tr>' . "\n";

$table_row_count = count($mysqlCharsets) + count($mysqlCollations);

foreach ($mysqlCharsets as $current_charset) {

$html .= '<tr><th colspan="2" class="right">' . "\n"
. ' ' . htmlspecialchars($current_charset) . "\n"
. (empty($mysqlCharsetsDesc[$current_charset])
? ''
: ' (<i>' . htmlspecialchars(
$mysqlCharsetsDesc[$current_charset]
) . '</i>)' . "\n")
. ' </th>' . "\n"
. '</tr>' . "\n";

$html .= $this->_getHtmlForCollationCurrentCharset(
$current_charset,
$mysqlCollations,
$mysqlDftCollations,
$mysqlCollAvailable
);

}

$html .= '</table>' . "\n"
. '</div>' . "\n";

return $html;
}

/**
* Returns the html for Collations of Current Charset.
*
* @param string $currCharset Current Charset
* @param array $mysqlColl Collations list
* @param array $mysqlDefaultColl Default Collations list
* @param array $mysqlCollAvailable Available Collations list
*
* @return string
*/
function _getHtmlForCollationCurrentCharset(
$currCharset, $mysqlColl, $mysqlDefaultColl, $mysqlCollAvailable
) {
$odd_row = true;
$html = '';
foreach ($mysqlColl[$currCharset] as $current_collation) {

$html .= '<tr class="'
. ($odd_row ? 'odd' : 'even')
. ($mysqlDefaultColl[$currCharset] == $current_collation
? ' marked'
: '')
. ($mysqlCollAvailable[$current_collation] ? '' : ' disabled')
. '">' . "\n"
. ' <td>' . htmlspecialchars($current_collation) . '</td>' . "\n"
. ' <td>' . PMA_getCollationDescr($current_collation) . '</td>' . "\n"
. '</tr>' . "\n";
$odd_row = !$odd_row;
}
return $html;
return Template::get('server/collations/charsets')->render(
array(
'mysqlCharsets' => $mysqlCharsets,
'mysqlCollations' => $mysqlCollations,
'mysqlCharsetsDesc' => $mysqlCharsetsDesc,
'mysqlDftCollations' => $mysqlDftCollations,
'mysqlCollAvailable' => $mysqlCollAvailable,
)
);
}
}
30 changes: 30 additions & 0 deletions templates/server/collations/charsets.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div id="div_mysql_charset_collations">
<table class="data noclick">
<tr>
<th id="collationHeader"><?php echo __('Collation'); ?></th>
<th><?php echo __('Description'); ?></th>
</tr>
<?php foreach ($mysqlCharsets as $current_charset): ?>
<tr>
<th colspan="2" class="right">
<?php echo htmlspecialchars($current_charset); ?>
<?php if (! empty($mysqlCharsetsDesc[$current_charset])): ?>
(<i><?php echo htmlspecialchars($mysqlCharsetsDesc[$current_charset]); ?></i>)
<?php endif; ?>
</th>
</tr>
<?php $odd_row = true; ?>
<?php foreach ($mysqlCollations[$current_charset] as $current_collation): ?>
<tr class="
<?php echo ($odd_row ? 'odd' : 'even'); ?>
<?php echo ($mysqlDftCollations[$current_charset] == $current_collation ? ' marked' : ''); ?>
<?php echo ($mysqlCollAvailable[$current_collation] ? '' : ' disabled'); ?>
">
<td><?php echo htmlspecialchars($current_collation); ?></td>
<td><?php echo PMA_getCollationDescr($current_collation); ?></td>
</tr>
<?php $odd_row = ! $odd_row; ?>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
</div>

0 comments on commit 090a7e4

Please sign in to comment.