<commit_before><?php if (!empty($searchFields) && !empty($listingFields)) : ?>
<?= $this->Html->css('Search.search_options', ['block' => 'cssBottom']) ?>
<?= $this->Html->script('Search.search_options', ['block' => 'scriptBottom']) ?>
<?php
$availableColumns = [];
$displayColumns = [];
foreach ($searchFields as $k => $v) {
    if (in_array($k, $listingFields)) {
        $displayColumns[$k] = $v;
    } else {
        $availableColumns[$k] = $v;
    }
}

// sort available columns by label
uasort($availableColumns, function($a, $b) {
    return strcmp($a['label'], $b['label']);
});

// sort display columns based on listing fields order
$displayColumns = array_merge(array_flip($listingFields), $displayColumns);
?>
    <div class="row">
        <div class="col-md-4">
        <?= $this->Form->label(__('Available Columns')) ?>
            <ul id="availableColumns" class="connectedSortable">
            <?php foreach ($availableColumns as $k => $v) : ?>
                <li data-id="<?= $k ?>">
                    <?= $v['label'] ?>
                </li>
            <?php endforeach; ?>
            </ul>
        </div>
        <div class="col-md-4">
        <?= $this->Form->label(__('Display Columns')) ?>
            <ul id="displayColumns" class="connectedSortable">
            <?php foreach ($displayColumns as $k => $v) : ?>
                <li data-id="<?= $k ?>">
                    <?= $v['label'] ?>
                </li>
            <?php endforeach; ?>
            </ul>
        </div>
        <div class="col-md-4">
        <?= $this->Form->label(__('Sort Field')) ?>
        <?php
        $sortByOptions = array_combine(
            array_keys($searchFields),
            array_map(function ($v) { return $v['label']; }, $searchFields)
        );
        echo $this->Form->select(
            'sort_by_field',
             $sortByOptions, [
                'default' => isset($searchData['sort_by_field']) ? $searchData['sort_by_field'] : key($sortByOptions),
                'class' => 'form-control input-sm'
            ]
        ) ?>
        <?= $this->Form->label(__('Sort Order')) ?>
        <?php
        echo $this->Form->select(
            'sort_by_order',<commit_msg>Display and available columns (task #2802)<commit_after><?php if (!empty($searchFields) && !empty($listingFields)) : ?>
<?= $this->Html->css('Search.search_options', ['block' => 'cssBottom']) ?>
<?= $this->Html->script('Search.search_options', ['block' => 'scriptBottom']) ?>
<?php
$availableColumns = [];
$displayColumns = [];
// get display and available columns
foreach ($searchFields as $k => $v) {
    if (in_array($k, $searchData['display_columns'])) {
        $displayColumns[$k] = $v['label'];
    } else {
        $availableColumns[$k] = $v['label'];
    }
}

// alphabetically sort available columns
asort($availableColumns);

// sort display columns based on listing fields order
$displayColumns = array_merge(array_flip($listingFields), $displayColumns);
?>
    <div class="row">
        <div class="col-md-4">
        <?= $this->Form->label(__('Available Columns')) ?>
            <ul id="availableColumns" class="connectedSortable">
            <?php foreach ($availableColumns as $k => $v) : ?>
                <li data-id="<?= $k ?>">
                    <?= $v ?>
                </li>
            <?php endforeach; ?>
            </ul>
        </div>
        <div class="col-md-4">
        <?= $this->Form->label(__('Display Columns')) ?>
            <ul id="displayColumns" class="connectedSortable">
            <?php foreach ($displayColumns as $k => $v) : ?>
                <li data-id="<?= $k ?>">
                    <?= $v ?>
                </li>
            <?php endforeach; ?>
            </ul>
        </div>
        <div class="col-md-4">
        <?= $this->Form->label(__('Sort Field')) ?>
        <?php
        $sortByOptions = array_combine(
            array_keys($searchFields),
            array_map(function ($v) { return $v['label']; }, $searchFields)
        );
        echo $this->Form->select(
            'sort_by_field',
             $sortByOptions, [
                'default' => isset($searchData['sort_by_field']) ? $searchData['sort_by_field'] : key($sortByOptions),
                'class' => 'form-control input-sm'
            ]
        ) ?>
        <?= $this->Form->label(__('Sort Order')) ?>
        <?php
        echo $this->Form->select(
            'sort_by_order',
{'fraction_non_alphanumeric': 0.19642857142857142, 'fraction_numerical': 0.0022603978300180833, 'mean_word_length': 2.183453237410072, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 111, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3733881', 'n_tokens_mistral': 1315, 'n_tokens_neox': 1298, 'n_words': 251}