Report::getMatchAttribute PHP Method

getMatchAttribute() public method

public getMatchAttribute ( )
    public function getMatchAttribute()
    {
        $reportArr = $this->toArray();
        $match = [];
        $actorMatch = [];
        $instructorMatch = [];
        $query = isset($reportArr['query']) ? (array) $reportArr['query'] : null;
        if (is_array($query) && count($query) > 0 && !isset($query[0])) {
            foreach ($query as $key => $value) {
                if (in_array($key, $this->actorQuery)) {
                    $actorMatch['$or'][] = $this->constructOr($key, $value);
                } else {
                    if (in_array($key, $this->instructorQuery)) {
                        $instructorMatch['$or'][] = $this->constructOr($key, $value);
                    } else {
                        if (is_array($value)) {
                            if ($value[0] != '<>') {
                                $match[$key] = ['$in' => $value];
                            } else {
                                $match[$key] = ['$lte' => $value[2], '$gte' => $value[1]];
                            }
                        } else {
                            $match[$key] = $value;
                        }
                    }
                }
            }
        }
        $since = isset($reportArr['since']) ? $this->constructDate($reportArr['since']) : null;
        $until = isset($reportArr['until']) ? $this->constructDate($reportArr['until']) : null;
        if ($since || $until) {
            $match['statement.timestamp'] = [];
        }
        if ($since) {
            $match['statement.timestamp']['$gte'] = $since;
        }
        if ($until) {
            $match['statement.timestamp']['$lte'] = $until;
        }
        $andMatch = [];
        if (!empty($actorMatch)) {
            $andMatch[] = $actorMatch;
        }
        if (!empty($instructorMatch)) {
            $andMatch[] = $instructorMatch;
        }
        if (!empty($match)) {
            $andMatch[] = $match;
        }
        if (!empty($andMatch)) {
            $match = ['$and' => $andMatch];
        }
        return $match;
    }