<commit_before><?php
/**
 * Copyright (c) Qobo Ltd. (https://www.qobo.biz)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Qobo Ltd. (https://www.qobo.biz)
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */

echo $this->Html->css('Search.search_options', ['block' => 'css']);
echo $this->Html->script('Search./plugins/multiselect.min', ['block' => 'script']);
echo $this->Html->script('Search.search_options', ['block' => 'scriptBottom']);

$availableColumns = [];
$displayColumns = [];
$groupByColumns = [];
// get display, group and available columns
foreach ($searchableFields as $k => $v) {
    $tableName = substr($k, 0, strpos($k, '.'));
    $tableName = array_key_exists($tableName, $associationLabels) ? $associationLabels[$tableName] : $tableName;
    $suffix = $savedSearch->model === $tableName ? '' : ' (' . $tableName . ')';

    if (in_array($k, $searchData['display_columns'])) {
        $displayColumns[$k] = $v['label'] . $suffix;
    }

    if (! in_array($k, $searchData['display_columns'])) {
        $availableColumns[$k] = $v['label'] . $suffix;
    }

    if ($savedSearch->model === $tableName) {
        $groupByColumns[$k] = $v['label'] . $suffix;
    }
}

asort($availableColumns);
asort($groupByColumns);

// sort display columns based on saved search display_columns order
$displayColumns = array_merge(array_flip($searchData['display_columns']), $displayColumns);
?>

<div class="row">
    <div class="col-md-5 col-lg-4">
        <?= $this->Form->label(__('Available Columns')) ?>
        <?= $this->Form->select('', $availableColumns, [
            'id' => 'available-columns',
            'class' => 'form-control',
            'size' => '8',
            'multiple' => 'multiple'
            ]) ?>
    </div>
    <div class="col-md-2">
        <?= $this->Form->label(false, '&nbsp;', ['escape' => false]) ?>
        <button type="button" id="available-columns_rightSelected" class="btn btn-block">
            <i class="glyphicon glyphicon-chevron-right"></i>
        </button>
        <button type="button" id="available-columns_leftSelected" class="btn btn-block">
            <i class="glyphicon glyphicon-chevron-left"></i>
        </button>
    </div>
    <div class="col-md-5 col-lg-4">
        <?= $this->Form->label(__('Display Columns')) ?>
        <?= $this->Form->select('display_columns', $displayColumns, [
            'id' => 'available-columns_to',<commit_msg>Fix for reaching PHP's max_input_var limit (task #9939)<commit_after><?php
/**
 * Copyright (c) Qobo Ltd. (https://www.qobo.biz)
 *
 * Licensed under The MIT License
 * For full copyright and license information, please see the LICENSE
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright (c) Qobo Ltd. (https://www.qobo.biz)
 * @license       https://opensource.org/licenses/mit-license.php MIT License
 */

echo $this->Html->css('Search.search_options', ['block' => 'css']);
echo $this->Html->script('Search./plugins/multiselect.min', ['block' => 'script']);
echo $this->Html->script('Search.search_options', ['block' => 'scriptBottom']);

$availableColumns = [];
$displayColumns = [];
$groupByColumns = [];
// get display, group and available columns
foreach ($searchableFields as $k => $v) {
    $tableName = substr($k, 0, strpos($k, '.'));
    $tableName = array_key_exists($tableName, $associationLabels) ? $associationLabels[$tableName] : $tableName;
    $suffix = $savedSearch->model === $tableName ? '' : ' (' . $tableName . ')';

    if (in_array($k, $searchData['display_columns'])) {
        $displayColumns[$k] = $v['label'] . $suffix;
    }

    if (! in_array($k, $searchData['display_columns'])) {
        $availableColumns[$k] = $v['label'] . $suffix;
    }

    if ($savedSearch->model === $tableName) {
        $groupByColumns[$k] = $v['label'] . $suffix;
    }
}

asort($availableColumns);
asort($groupByColumns);

// sort display columns based on saved search display_columns order
$displayColumns = array_merge(array_flip($searchData['display_columns']), $displayColumns);
?>

<div class="row">
    <div class="col-md-5 col-lg-4">
        <?= $this->Form->label(__('Available Columns')) ?>
        <?php $html = $this->Form->select('', $availableColumns, [
            'id' => 'available-columns',
            'class' => 'form-control',
            'size' => '8',
            'multiple' => 'multiple'
        ]);
        // remove input name to avoid hitting PHP's max_input_vars limit
        echo str_replace('name="[]"', '', $html) ?>
    </div>
    <div class="col-md-2">
        <?= $this->Form->label(false, '&nbsp;', ['escape' => false]) ?>
        <button type="button" id="available-columns_rightSelected" class="btn btn-block">
            <i class="glyphicon glyphicon-chevron-right"></i>
        </button>
        <button type="button" id="available-columns_leftSelected" class="btn btn-block">
            <i class="glyphicon glyphicon-chevron-left"></i>
        </button>
    </div>
    <div class="col-md-5 col-lg-4">
        <?= $this->Form->label(__('Display Columns')) ?>
        <?= $this->Form->select('display_columns', $displayColumns, [
            'id' => 'available-columns_to',
{'fraction_non_alphanumeric': 0.19456339601563954, 'fraction_numerical': 0.0033513312232358963, 'mean_word_length': 3.40327868852459, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 97, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, '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': '3616546', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1641, 'n_words': 346}