PodsUI::get_params PHP Method

get_params() public method

Get find() params based on current UI action
public get_params ( null | array $params = null, null | string $action = null )
$params null | array
$action null | string
    public function get_params($params = null, $action = null)
    {
        if (null === $action) {
            $action = $this->action;
        }
        $defaults = array('full' => false, 'flatten' => true, 'fields' => null, 'type' => '');
        if (!empty($params) && is_array($params)) {
            $params = (object) array_merge($defaults, $params);
        } else {
            $params = (object) $defaults;
        }
        if (!in_array($action, array('manage', 'reorder'))) {
            $action = 'manage';
        }
        $params_override = false;
        $orderby = array();
        $limit = $this->limit;
        $sql = null;
        if ('reorder' == $this->action) {
            if (!empty($this->reorder['orderby'])) {
                $orderby[$this->reorder['orderby']] = $this->reorder['orderby_dir'];
            } else {
                $orderby[$this->reorder['on']] = $this->reorder['orderby_dir'];
            }
            if (!empty($this->reorder['limit'])) {
                $limit = $this->reorder['limit'];
            }
            if (!empty($this->reorder['sql'])) {
                $sql = $this->reorder['sql'];
            }
        }
        if (!empty($this->orderby)) {
            $this->orderby = (array) $this->orderby;
            foreach ($this->orderby as $order) {
                if (false !== strpos($order, ' ')) {
                    $orderby[] = $order;
                } elseif (!isset($orderby[$order])) {
                    $orderby[$order] = $this->orderby_dir;
                }
            }
        }
        if (false !== $this->pod && is_object($this->pod) && ('Pods' == get_class($this->pod) || 'Pod' == get_class($this->pod))) {
            $find_params = array('where' => pods_v($action, $this->where, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'search_across' => $this->search_across, 'search_across_picks' => $this->search_across_picks, 'filters' => $this->filters, 'sql' => $sql);
            $params_override = true;
        } else {
            $find_params = array('table' => $this->sql['table'], 'id' => $this->sql['field_id'], 'index' => $this->sql['field_index'], 'where' => pods_v($action, $this->where, null, true), 'orderby' => $orderby, 'page' => (int) $this->page, 'pagination' => true, 'limit' => (int) $limit, 'search' => $this->searchable, 'search_query' => $this->search, 'fields' => $this->fields['search'], 'sql' => $sql);
            if (!empty($this->sql['select'])) {
                $find_params['select'] = $this->sql['select'];
            }
        }
        if (empty($find_params['where']) && $this->restricted($this->action)) {
            $find_params['where'] = $this->pods_data->query_fields($this->restrict[$this->action], is_object($this->pod) ? $this->pod->pod_data : null);
        }
        if ($params_override) {
            $find_params = array_merge($find_params, (array) $this->params);
        }
        if ($params->full) {
            $find_params['limit'] = -1;
        }
        // Debug purposes
        if (1 == pods_v('pods_debug_params', 'get', 0) && pods_is_admin(array('pods'))) {
            pods_debug($find_params);
        }
        return $find_params;
    }