HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/public_html/src/core/Directus/GraphQL/Collection/CollectionList.php
<?php

namespace Directus\GraphQL\Collection;

use Directus\GraphQL\Types;
use Directus\Application\Application;

class CollectionList
{

    protected $param;
    protected $limit;
    protected $offset;
    protected $container;
    protected $lang;

    public function __construct()
    {
        $this->param = ['fields' => '*.*.*.*.*.*', 'meta' => '*'];
        $this->id = ['id' => Types::int()];
        $this->limit = ['limit' => Types::int()];
        $this->offset = ['offset' => Types::int()];
        $this->container = Application::getInstance()->getContainer();
        $this->lang = ['lang' => Types::string()];
    }

    protected function convertArgsToFilter($args)
    {
        $this->param = (isset($args)) ? array_merge($this->param, $args) : $this->param;
        if (isset($this->param['filter'])) {
            $filters = [];
            foreach ($this->param['filter'] as $filter => $value) {
                /**
                 * TODO :: Need to rewrite the code for better readiablity.
                 */
                if ($filter == 'or' || $filter == 'and') {
                    $c = 0;
                    foreach ($value as $innerFilters) {
                        $innerFilter = array_keys($innerFilters)[0];
                        $innerFilterValue = $innerFilters[$innerFilter];
                        $temp = $this->parseArg($innerFilter, $innerFilterValue);
                        $filters[$temp['key']] = $temp['value'];
                        if ($c++ > 0) { // Logical filter is not allowed on first filter
                            $filters[$temp['key']]['logical'] = $filter;
                        }
                    }
                } else {
                    $temp = $this->parseArg($filter, $value);
                    $filters[$temp['key']] = $temp['value'];
                }
            }
            $this->param['filter'] = $filters;
        }
    }

    private function parseArg($key, $value)
    {
        $filterParts = preg_split('~_(?=[^_]*$)~', $key);
        $res['key'] = $filterParts[0];
        $res['value'] = [$filterParts[1] => $value];
        return $res;
    }
}