Habari\AdminTagsHandler::ajax_tags PHP Метод

ajax_tags() публичный Метод

Handles AJAX from /admin/tags Used to search for, delete and rename tags
public ajax_tags ( )
    public function ajax_tags()
    {
        Utils::check_request_method(array('POST', 'HEAD'));
        $this->create_theme();
        $params = $_POST['query'];
        // Get a usable array with filter parameters from the odd syntax we received from the faceted search
        $fetch_params = array();
        if (isset($params)) {
            foreach ($params as $param) {
                $key = key($param);
                // Revert translation
                if ($key != 'text') {
                    $key = self::$facets[$key];
                }
                $value = current($param);
                if (array_key_exists($key, $fetch_params)) {
                    $fetch_params[$key] = Utils::single_array($fetch_params[$key]);
                    $fetch_params[$key][] = $value;
                } else {
                    $fetch_params[$key] = $value;
                }
            }
        }
        // Grab facets / params
        $search = array_key_exists('text', $fetch_params) ? $fetch_params['text'] : null;
        $min = array_key_exists('morethan', $fetch_params) ? $fetch_params['morethan'] + 1 : 0;
        $max = array_key_exists('lessthan', $fetch_params) ? $fetch_params['lessthan'] - 1 : null;
        $orderby_code = array_key_exists('orderby', $fetch_params) ? $fetch_params['orderby'] : null;
        $orderby = isset($orderby_code) ? explode('_', self::$facet_values['orderby'][$orderby_code]) : ['alphabetical', 'asc'];
        $this->theme->tags = Tags::get_by_frequency(null, null, $min, $max, $search, self::$orderby_translate[$orderby[0]], $orderby[1] == 'asc');
        // Create FormUI elements (list items) from the filtered tag list
        $this->theme->max = Tags::vocabulary()->max_count();
        $this->theme->min = Tags::vocabulary()->min_count();
        $output = '';
        if (count($this->theme->tags) > 0) {
            $listitems = $this->get_tag_listitems();
            // Get HTML from FormUI
            foreach ($listitems as $listitem) {
                $output .= $listitem->get($this->theme);
            }
        }
        $ar = new AjaxResponse();
        $ar->html('#tag_collection', $output);
        $ar->out();
    }