Converts DateTime objects into MongoDatetime.

@param array $query

@return array
332993
protected function normalizeDates(array $query): array
    {
        array_walk_recursive($query, function (&$value) {
            if ($value instanceof \DateTime) {
                //MongoDate is always UTC, which is good :)
                $value = new UTCDateTime($value);
            }
        });

        return $query;
    }
569039
private function convertData(array $data = null)
    {
        if (!is_array($data)) {
            return $data;
        }

        foreach ($data as $key => $val) {
            /** convert dbrefs */
            if (is_array($val) && isset($val['$ref']) && isset($val['$id'])) {
                $data[$key] = $this->convertData(
                    $this->resolveObject($val['$ref'], $val['$id'])
                );
            } elseif (is_array($val)) {
                $data[$key] = $this->convertData($val);
            }
            /** convert mongodate to text dates **/
            if ($val instanceof \MongoDate) {
                $data[$key] = $this->dateConverter->formatDateTime($val->toDateTime());
            }
            /** convert mongoid */
            if ($val instanceof \MongoId) {
                $data[$key] = (string) $val;
            }
        }

        return $data;
    }
303418
public function query($entity, $query)
	{
		$retValue = array();

		if (! is_null($this->_db)){
			try{
				$mongo = $this->_db->selectCollection($entity);

				// Find by query
				$cursor = $mongo->find($query);

				if (is_null($cursor))
					$retValue = array();
				else
					$retValue = iterator_to_array($cursor);
			}
			catch(Exception $e) {
				$this->_log->addError($e->getMessage());
			}	
		}

		return $retValue;
	}
520620
public static function search($query) {
    global $server;
    $response = $server->doCall('search', ['query' => $query]);
    $result = [];
    foreach ($response->getValue('list') as $item) {
      $result[] = ['type' => $item['type'], 'oid' => $item['oid'],
        'displayValue' => $item['displayValue'], 'summary' => $item['summary']
      ];
    }
    return ['return' => $result];
  }
1228247
private function query($query)
    {
		if(!is_array($query)) {
			return q($query);
		} else {
			foreach($query as $v) {
				q($v);
			}
			return true;
		}
    }
192178
public function getList(array $query = [])
    {
        $resource = self::DOMUSERP_API_OPERACIONAL . '/' . $this->cityId .'/bairros';
        $list = $this->pagination($resource);

        return $list;
    }
646436
private static function parseQuery( $query )
   {

      if ( empty( $query ) )
      {
         return [];
      }

      $elements = [];

      \parse_str( $query, $elements );

      if ( ! \is_array( $elements ) )
      {
         return [];
      }

      return $elements;

   }
735841
public function getCol(string $query, array $criteria = []): array {
		try {
			$results = $this->dbConn->fetchCol($query, $criteria);
			return is_array($results) ? $results : [];
		} catch (\PDOException $pdoException) {
			throw $this->prepareDatabaseException($pdoException, $query, $criteria);
		}
	}
1297999
private function getTimeObjects(array $data) {
    $date = \DateTime::createFromFormat(
      self::API_DATE_FORMAT,
      $data['date'],
      new \DateTimeZone(self::API_TIMEZONE)
    );

    $sourceTimes = explode('-', $data['time']);

    $sourceTimeStart = date_parse($sourceTimes[0]);
    if (!$sourceTimeStart) {
      throw new \Exception(sprintf('Failed to parse time %s', $sourceTimes[0]));
    }

    $sourceTimeEnd = date_parse($sourceTimes[1]);
    if (!$sourceTimeEnd) {
      throw new \Exception(sprintf('Failed to parse time %s', $sourceTimes[1]));
    }

    $dateStart = clone($date);
    $dateEnd = clone($date);

    $dateStart->setTime($sourceTimeStart['hour'], $sourceTimeStart['minute']);
    $dateEnd->setTime($sourceTimeEnd['hour'], $sourceTimeEnd['minute']);

    return [
      'start' => $dateStart,
      'end' => $dateEnd,
    ];
  }
330451
protected function compileWheresToArray($query)
    {
        return collect($query->wheres)->map(function ($where) use ($query) {
            return $where['boolean'].' '.$this->{"where{$where['type']}"}($query, $where);
        })->all();
    }
717536
public function getArrays($query)
    {
        $this->statement = $this->db->query($query);
        if ($this->statement) {
            $result =  $this->statement->fetchAll(\PDO::FETCH_ASSOC);
            if ($result) {
                return $result;
            }
        }
        return false;
    }
1146540
public static DateTime getUniversalTimestamp(final GroupByQuery query)
  {
    final Granularity gran = query.getGranularity();
    final String timestampStringFromContext = query.getContextValue(CTX_KEY_FUDGE_TIMESTAMP, "");

    if (!timestampStringFromContext.isEmpty()) {
      return DateTimes.utc(Long.parseLong(timestampStringFromContext));
    } else if (Granularities.ALL.equals(gran)) {
      final DateTime timeStart = query.getIntervals().get(0).getStart();
      return gran.getIterable(new Interval(timeStart, timeStart.plus(1))).iterator().next().getStart();
    } else {
      return null;
    }
  }
1010561
final public function queryArrayValues(string $query, array $overrideTypes = [])
    {
        $recordset = $this->queryRecordset($query, '', [], $overrideTypes);
        if (false === $recordset) {
            return false;
        }

        $return = [];
        while (! $recordset->eof()) {
            $return[] = $recordset->values;
            $recordset->moveNext();
        }
        return $return;
    }
649148
public static function aggregate($query)
    {
        $rows = self::connection()->aggregate(self::collectionName(), $query);
        return $rows;
    }
1230867
public function lookup(Query $query)
    {
        $id = $this->serializeQueryToIdentity($query);

        $expiredAt = $this->expiredAt;

        return $this->cache
            ->get($id)
            ->then(function ($value) use ($query, $expiredAt) {
                // cache 0.5+ resolves with null on cache miss, return explicit cache miss here
                if ($value === null) {
                    return Promise\reject();
                }

                /* @var $recordBag RecordBag */
                $recordBag = unserialize($value);

                // reject this cache hit if the query was started before the time we expired the cache?
                // todo: this is a legacy left over, this value is never actually set, so this never applies.
                // todo: this should probably validate the cache time instead.
                if (null !== $expiredAt && $expiredAt <= $query->currentTime) {
                    return Promise\reject();
                }

                return $recordBag->all();
            });
    }
188040
private function finalQueryPrepare(array $query)
    {
        if (isset($query['where']['compositeFilter']) && count($query['where']['compositeFilter']['filters']) === 1) {
            $filter = $query['where']['compositeFilter']['filters'][0];
            $query['where'] = $filter;
        }

        return $query;
    }
468126
private function prepareDateTimes($datetimes)
    {
        $parsedDateTimes = $this->parseDateTimes($datetimes);
        $sortedDateTimes = array();
        foreach ($parsedDateTimes as $parsedDateTime) {
            $hour = date('G', $parsedDateTime->date_time->getTimestamp());
            if (!isset($sortedDateTimes[$hour])) {
                $sortedDateTimes[$hour] = array();
            }
            if ($this->hasExceptions($parsedDateTime->links)) {
                usort($parsedDateTime->links, array($this, "sortLinks"));
            }
            $sortedDateTimes[$hour][] = $parsedDateTime;
        }

        return $sortedDateTimes;
    }