Imbo\Database\MongoDB::getNumBytes PHP Method

getNumBytes() public method

public getNumBytes ( $user = null )
    public function getNumBytes($user = null)
    {
        try {
            $collection = $this->getImageCollection();
            $group = ['$group' => ['_id' => null, 'numBytes' => ['$sum' => '$size']]];
            if ($user) {
                $results = $collection->aggregate(['$match' => ['user' => $user]], $group);
            } else {
                $results = $collection->aggregate($group);
            }
            $result = $results['result'];
            if (empty($result)) {
                return 0;
            }
            return (int) $result[0]['numBytes'];
        } catch (MongoException $e) {
            throw new DatabaseException('Unable to fetch information from the database', 500, $e);
        }
    }