<commit_before><?php

/**
 * Adds filterby action to a standard controller and pulls in a list of
 * items to be filtered.
 *
 * By default, filterable will find all objects that need filtering
 * merge them and return an ArrayList of items
 *
 * The intention of this is to allow people to develop their own custom
 * filters to their own controllers that add additional features beyond
 * what this action provides.
 *
 * @author i-lateral (http://www.i-lateral.com)
 * @package Filterable
 */
class FilterableController extends Extension {

    private static $allowed_actions = array(
        "filterby"
    );

    public function filterby() {
        // Get a list of filterable classes
        $classes = Filterable::getFilteredClasses();
        $results = ArrayList::create();
        $get_vars = $this->owner->request->getVars();
        $filter_ids = array();

        if(isset($get_vars["filter"])) {
            // First explode the filters stored in our filter var
            $filter_vars = explode(";", $get_vars["filter"]);

            // Now get the filter options we need to filter objects by
            foreach($filter_vars as $single_var) {
                $key_value = explode(":", $single_var);

                $filter_option = FilterOption::get()
                    ->filter(array(
                        "Parent.Title:nocase" => $key_value[0],
                        "Title:nocase" => $key_value[1]
                    ))->first();

                if($filter_option && $results->exists()) {
                    foreach($results as $result) {
                        if(!$result->Filters()->find("ID",$filter_option->ID)) {
                            $results->remove($result);
                        }
                    }
                } elseif($filter_option) {
                    foreach($classes as $class) {
                        $list = $class::get()
                            ->filter("Filters.ID:ExactMatch",$filter_option->ID);

                        if($list->exists())
                            $results->merge($list);
                    }
                }
            }
        }

        $data = array(
            'Results' => $results
        );

        $this->owner->extend("updateFilterBy", $data);

        return $this
            ->owner
            ->customise($data)
            ->renderWith(array(
                'Page_filterby',
                'FilterBy',
                'Page'
            ));
    }
}<commit_msg>Add pagination to filter results<commit_after><?php

/**
 * Adds filterby action to a standard controller and pulls in a list of
 * items to be filtered.
 *
 * By default, filterable will find all objects that need filtering
 * merge them and return an ArrayList of items
 *
 * The intention of this is to allow people to develop their own custom
 * filters to their own controllers that add additional features beyond
 * what this action provides.
 *
 * @author i-lateral (http://www.i-lateral.com)
 * @package Filterable
 */
class FilterableController extends Extension {

    private static $allowed_actions = array(
        "filterby"
    );

    public function filterby() {
        // Get a list of filterable classes
        $classes = Filterable::getFilteredClasses();
        $results = ArrayList::create();
        $get_vars = $this->owner->request->getVars();
        $filter_ids = array();

        if(isset($get_vars["filter"])) {
            // First explode the filters stored in our filter var
            $filter_vars = explode(";", $get_vars["filter"]);

            // Now get the filter options we need to filter objects by
            foreach($filter_vars as $single_var) {
                $key_value = explode(":", $single_var);

                $filter_option = FilterOption::get()
                    ->filter(array(
                        "Parent.Title:nocase" => $key_value[0],
                        "Title:nocase" => $key_value[1]
                    ))->first();

                if($filter_option && $results->exists()) {
                    foreach($results as $result) {
                        if(!$result->Filters()->find("ID",$filter_option->ID)) {
                            $results->remove($result);
                        }
                    }
                } elseif($filter_option) {
                    foreach($classes as $class) {
                        $list = $class::get()
                            ->filter("Filters.ID:ExactMatch",$filter_option->ID);

                        if($list->exists())
                            $results->merge($list);
                    }
                }
            }
        }

        $results = new PaginatedList($results, $this->owner->request);

        $data = array(
            'Results' => $results
        );

        $this->owner->extend("updateFilterBy", $data);

        return $this
            ->owner
            ->customise($data)
            ->renderWith(array(
                'Page_filterby',
                'FilterBy',
                'Page'
            ));
    }
}
{'fraction_non_alphanumeric': 0.11955020714144801, 'fraction_numerical': 0.000789110278161373, 'mean_word_length': 1.5541561712846348, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7045640', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1233, 'n_words': 332}