<commit_before><?php use Cake\Utility\Inflector; ?>
<div class="well">
    <h4><?= __('Saved Searches') ?></h4>
    <hr />
    <div class="row">
        <div class="col-xs-12 col-sm-6">
            <?php if (!empty($savedSearches)) : ?>
                <div class="row">
                <?php
                $groupedSavedSearches = [];
                foreach ($savedSearches as $savedSearch) {
                    $groupedSavedSearches[$savedSearch->type][] = $savedSearch;
                }
                ksort($groupedSavedSearches);
                ?>
                <?php foreach ($groupedSavedSearches as $type => $searches) : $count = 12 / count($groupedSavedSearches) ?>
                    <div class="col-xs-<?= $count ?> saved-searches">
                        <strong><?= Inflector::pluralize(Inflector::humanize($type)) ?>:</strong>
                        <?php foreach ($searches as $search) : ?>
                            <samp>
                            <?php if ('result' === $type) {
                                echo $this->Html->link($search->name, ['action' => 'saved_result', $search->model, $search->id]);
                            } else {
                                echo $this->Html->link($search->name, ['action' => 'advanced', $search->model, $search->id]);
                            }
                            ?>
                            </samp>
                        <?php endforeach; ?>
                    </div>
                <?php endforeach; ?>
                </div>
            <?php endif; ?>
        </div>
        <div class="col-xs-12 col-sm-6">
            <?php if (isset($saveSearchCriteriaId) && isset($saveSearchResultsId)) : ?>
                <?= $this->Form->create(null, [
                    'class' => 'form-inline pull-right save-search-form',
                    'url' => [
                        'plugin' => 'Search',
                        'controller' => 'Search',
                        'action' => 'save',
                        $saveSearchCriteriaId
                    ]
                ]); ?>
                <div class="input-group">
                    <?= $this->Form->input('name', [
                        'label' => false,
                        'class' => 'form-control input-sm',
                        'placeholder' => 'Save criteria name',
                        'required' => true,
                        'value' => ''
                    ]); ?>
                    <span class="input-group-btn">
                        <?= $this->Form->button(
                            '<span class="glyphicon glyphicon-floppy-save"></span>',
                            ['class' => 'btn btn-primary btn-sm']
                        ) ?>
                    </span>
                </div>
                <?= $this->Form->end(); ?>

                <?= $this->Form->create(null, [
                    'class' => 'form-inline pull-right save-search-form',
                    'url' => [
                        'plugin' => 'Search',
                        'controller' => 'Search',
                        'action' => 'save',
                        $saveSearchResultsId
                    ]
                ]); ?>
                <div class="input-group">
                    <?= $this->Form->input('name', [
                        'label' => false,
                        'class' => 'form-control input-sm',
                        'placeholder' => 'Save results name',
                        'required' => true,
                        'value' => false
                    ]); ?>
                    <span class="input-group-btn">
                        <?= $this->Form->button(
                            '<span class="glyphicon glyphicon-floppy-save"></span>',
                            ['class' => 'btn btn-primary btn-sm']
                        ) ?>
                    </span>
                </div>
                <?= $this->Form->end(); ?>
            <?php endif; ?>
        </div>
    </div>
</div>
<commit_msg>add saved searches as forms (task #1596)<commit_after><?php use Cake\Utility\Inflector; ?>
<div class="well">
    <h4><?= __('Saved Searches') ?></h4>
    <hr />
    <div class="row">
        <div class="col-xs-12 col-sm-6">
        <?php if (!empty($savedSearches)) : ?>
            <div class="row">
            <?php
            $groupedSavedSearches = [];
            foreach ($savedSearches as $savedSearch) {
                $groupedSavedSearches[$savedSearch->type][] = $savedSearch;
            }
            ksort($groupedSavedSearches);
            ?>
            <?php foreach ($groupedSavedSearches as $type => $searches) : $count = 12 / count($groupedSavedSearches) ?>
                <div class="col-xs-<?= $count ?> saved-searches">
                    <strong><?= Inflector::pluralize(Inflector::humanize($type)) ?>:</strong>
                    <?php foreach ($searches as $search) : ?>
                        <samp>
                        <?php
                        switch ($type) {
                            case 'result':
                                echo $this->Html->link($search->name, [
                                    'action' => 'saved_result',
                                    $search->model,
                                    $search->id
                                ]);
                                break;

                            case 'criteria':
                                $savedSearchContent = json_decode($search->content);
                                echo $this->Form->create(null, [
                                    'class' => 'saved-criteria-form',
                                    'url' => [
                                        'plugin' => 'Search',
                                        'controller' => 'Search',
                                        'action' => 'advanced',
                                        $search->model
                                    ]
                                ]);

                                foreach ($savedSearchContent as $fieldName => $properties) {
                                    foreach ($properties as $k => $property) {
                                        echo $this->Form->hidden($fieldName . '[' . $k . '][type]', [
                                            'value' => $property->type,
                                        ]);
                                        echo $this->Form->hidden($fieldName . '[' . $k . '][operator]', [
                                            'value' => $property->operator,
                                        ]);
                                        echo $this->Form->hidden($fieldName . '[' . $k . '][value]', [
                                            'value' => $property->value,
                                        ]);
                                    }
                                }

                                echo $this->Form->button(
                                    $search->name,
                                    ['class' => 'btn btn-link']
                                );

                                echo $this->Form->end();
                                break;
                        }
                        ?>
                        </samp>
                    <?php endforeach; ?>
                </div>
            <?php endforeach; ?>
            </div>
        <?php endif; ?>
        </div>
        <div class="col-xs-12 col-sm-6">
            <?php if (isset($saveSearchCriteriaId) && isset($saveSearchResultsId)) : ?>
                <?= $this->Form->create(null, [
                    'class' => 'form-inline pull-right save-search-form',
                    'url' => [
                        'plugin' => 'Search',
                        'controller' => 'Search',
                        'action' => 'save',
                        $saveSearchCriteriaId
                    ]
                ]); ?>
                <div class="input-group">
                    <?= $this->Form->input('name', [
                        'label' => false,
                        'class' => 'form-control input-sm',
                        'placeholder' => 'Save criteria name',
                        'required' => true,
                        'value' => ''
                    ]); ?>
                    <span class="input-group-btn">
                        <?= $this->Form->button(
                            '<span class="glyphicon glyphicon-floppy-save"></span>',
                            ['class' => 'btn btn-primary btn-sm']
                        ) ?>
                    </span>
                </div>
                <?= $this->Form->end(); ?>

                <?= $this->Form->create(null, [
                    'class' => 'form-inline pull-right save-search-form',
                    'url' => [
                        'plugin' => 'Search',
                        'controller' => 'Search',
                        'action' => 'save',
                        $saveSearchResultsId
                    ]
                ]); ?>
                <div class="input-group">
                    <?= $this->Form->input('name', [
                        'label' => false,
                        'class' => 'form-control input-sm',
                        'placeholder' => 'Save results name',
                        'required' => true,
                        'value' => false
                    ]); ?>
                    <span class="input-group-btn">
                        <?= $this->Form->button(
                            '<span class="glyphicon glyphicon-floppy-save"></span>',
                            ['class' => 'btn btn-primary btn-sm']
                        ) ?>
                    </span>
                </div>
                <?= $this->Form->end(); ?>
            <?php endif; ?>
        </div>
    </div>
</div>

{'fraction_non_alphanumeric': 0.14551863041289023, 'fraction_numerical': 0.002416918429003021, 'mean_word_length': 0.8462539505484291, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 236, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3818430', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2229, 'n_words': 400}