eZ\Publish\Core\FieldType\BinaryBase\BinaryBaseStorage\Gateway\LegacyStorage::countFileReferences PHP Method

countFileReferences() public method

Returns a map with the number of references each file from $files has.
public countFileReferences ( array $files ) : array
$files array
return array
    public function countFileReferences(array $files)
    {
        if (empty($files)) {
            return array();
        }
        $connection = $this->getConnection();
        $selectQuery = $connection->createSelectQuery();
        $selectQuery->select($connection->quoteColumn('filename'), $connection->quoteColumn('mime_type'), $selectQuery->alias($selectQuery->expr->count($connection->quoteColumn('contentobject_attribute_id')), 'count'))->from($connection->quoteTable($this->getStorageTable()))->where($selectQuery->expr->in($connection->quoteColumn('filename'), array_map(array($this, 'removeMimeFromPath'), $files)))->groupBy($connection->quoteColumn('filename'), $connection->quoteColumn('mime_type'));
        $statement = $selectQuery->prepare();
        $statement->execute();
        $countMap = array();
        foreach ($statement->fetchAll(\PDO::FETCH_ASSOC) as $row) {
            $path = $this->prependMimeToPath($row['filename'], $row['mime_type']);
            $countMap[$path] = (int) $row['count'];
        }
        // Complete counts
        foreach ($files as $path) {
            // This is already the correct path
            if (!isset($countMap[$path])) {
                $countMap[$path] = 0;
            }
        }
        return $countMap;
    }