Report::getWhereAttribute PHP Method

getWhereAttribute() public method

public getWhereAttribute ( )
    public function getWhereAttribute()
    {
        $reportArr = $this->toArray();
        $wheres = [];
        $query = isset($reportArr['query']) ? (array) $reportArr['query'] : null;
        $actorArray = [];
        $instructorArray = [];
        if (is_array($query) && count($query) > 0 && !isset($query[0])) {
            foreach (array_keys($query) as $key) {
                if (in_array($key, $this->actorQuery)) {
                    array_push($actorArray, [$key, $query[$key]]);
                } else {
                    if (in_array($key, $this->instructorQuery)) {
                        array_push($instructorArray, [$key, $query[$key]]);
                    } else {
                        if (is_array($query[$key])) {
                            if ($query[$key][0] != '<>') {
                                array_push($wheres, [$key, 'in', $query[$key]]);
                            } else {
                                array_push($wheres, [$key, 'between', $query[$key][1], $query[$key][2]]);
                            }
                        } else {
                            array_push($wheres, [$key, '=', $query[$key]]);
                        }
                    }
                }
            }
            if (!empty($actorArray)) {
                array_push($wheres, ['orArray', 'or', $actorArray]);
            }
            if (!empty($instructorArray)) {
                array_push($wheres, ['orArray', 'or', $instructorArray]);
            }
        }
        $since = isset($reportArr['since']) ? $this->constructDate($reportArr['since']) : null;
        $until = isset($reportArr['until']) ? $this->constructDate($reportArr['until']) : null;
        if ($since && $until) {
            $wheres[] = ['statement.timestamp', 'between', $since, $until];
        } else {
            if ($since) {
                $wheres[] = ['statement.timestamp', '>=', $since];
            } else {
                if ($until) {
                    $wheres[] = ['statement.timestamp', '<=', $until];
                }
            }
        }
        return $wheres;
    }