Get the records for a given ContentType.

@param string     $contentTypeName
@param MutableBag $exportData
@param MutableBag $responseBag

@throws \Bolt\Exception\InvalidRepositoryException
489646
private function getRecords($contentTypeName, MutableBag $exportData, MutableBag $responseBag)
    {
        /** @var ContentRepository $repo */
        $repo = $this->em->getRepository($contentTypeName);
        $metadata = $repo->getClassMetadata();
        // Get all the records for the ContentType
        $entities = $this->query->getContent($contentTypeName);
        $contentTypeBag = $exportData->get($contentTypeName);

        foreach ($entities as $key => $entity) {
            $this->addRecord($contentTypeBag, $metadata, $entity);
        }

        /** @var MutableBag $success */
        $success = $responseBag->get('success');
        $success->add(sprintf('%s: %s records', $contentTypeName, count($entities)));
    }
646097
private function addRecord(MutableBag $contentTypeBag, ClassMetadata $metadata, Content $entity)
    {
        $values = [];
        foreach ($metadata->getFieldMappings() as $field) {
            $fieldName = $field['fieldname'];
            $val = $entity->$fieldName;
            if (in_array($field['type'], ['date', 'datetime'])) {
                $val = (string) $entity->$fieldName;
            }
            if (is_callable([$val, 'serialize'])) {
                /** @var Entity $val */
                $val = $val->serialize();
            }
            $values[$fieldName] = $val;
        }

        unset($values['id']);
        $values['_id'] = $entity->getContentType() . '/' . $entity->getSlug();
        $contentTypeBag->add($values);
    }
811131
private function getRecords($contentTypeKey, $limit)
    {
        $repo = $this->em->getRepository($contentTypeKey);
        $qb = $repo
            ->createQueryBuilder()
            ->setMaxResults($limit)
            ->orderBy('datechanged', 'DESC')
        ;

        return $repo->findWith($qb);
    }
979900
public function getFieldById(ContentTypeInterface $contentType, $fieldId)
    {
        $field = $this->om->getRepository($this->configurationManager->getEntityClass('field'))->find($fieldId);


        if (!$field instanceof FieldInterface) {
            return null;
        }
        if ($field->getContentType() && $field->getContentType()->getId() == $contentType->getId()) {
            return $field;
        }

        $parent = $field;
        while ($parent && $parentLayout = $parent->getLayout()) {
            if ($parent = $parentLayout->getParent()) {
                if ($parent->getContentType() !== null && $parent->getContentType()->getId() == $contentType->getId()) {
                    return $field;
                }
            }
        }

        return null;
    }
326436
public function deleteContentTypes(
        ContentTypesDeleteData $data = null,
        ?string $name = null
    ): FormInterface {
        $name = $name ?: StringUtil::fqcnToBlockPrefix(ContentTypesDeleteType::class);

        return $this->formFactory->createNamed($name, ContentTypesDeleteType::class, $data);
    }
1216330
public function create($contentOrName, $type = null, array $data = [])
    {
        // Check if container or name is defined
        if (!(
            $contentOrName instanceof Model\ContentInterface ||
            (is_string($contentOrName) && 0 < strlen($contentOrName))
        )
        ) {
            throw new InvalidOperationException("Excepted instance of ContentInterface or string.");
        }

        // Default type if null
        if (null === $type) {
            $type = $this->defaultType;
        }

        // New instance
        $container = $this->editor->getRepository()->createContainer();
        $container->setType($type);

        // Plugin creation
        $plugin = $this->editor->getContainerPlugin($type);
        $plugin->create($container, $data);

        // Create default row
        if (!$plugin instanceof CopyPlugin) {
            $this->editor->getRowManager()->create($container);
        }

        // Add to container if available
        if ($contentOrName instanceof Model\ContentInterface) {
            $count = $contentOrName->getContainers()->count();
            $container->setPosition($count);
            $contentOrName->addContainer($container);
        } else {
            $container->setName($contentOrName);
        }

        return $container;
    }
212142
private function resolveContentCreateData(
        ContentType $contentType,
        Location $location,
        string $languageCode
    ): ContentCreateData {
        $contentCreateMapper = new ContentCreateMapper();

        return $contentCreateMapper->mapToFormData(
            $contentType,
            [
                'mainLanguageCode' => $languageCode,
                'parentLocation' => $this->locationService->newLocationCreateStruct($location->id, $contentType),
            ]
        );
    }
287951
public function getRecord($recordId, $contentTypeName = null, DataDimensions $dataDimensions = null)
    {
        if ($contentTypeName == null)
        {
            $contentTypeName = $this->getCurrentContentTypeName();
        }

        if ($dataDimensions == null)
        {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        $folder = $this->getConfiguration()->getFolderNameRecords($contentTypeName, $dataDimensions);

        $fileName = $folder . '/' . $recordId . '.json';

        if ($this->fileExists($fileName))
        {
            $data = $this->readRecord($fileName);

            if ($data)
            {
                $data = json_decode($data, true);

                $definition = $this->getContentTypeDefinition($contentTypeName);

                $record = $this->getRecordFactory()
                               ->createRecordFromJSON($definition, $data, $dataDimensions->getViewName(), $dataDimensions->getWorkspace(), $dataDimensions->getLanguage());

                return $this->exportRecord($record, $dataDimensions);
            }
        }

        KVMLogger::instance('anycontent-connection')
                 ->info('Record ' . $recordId . ' not found for content type ' . $this->getCurrentContentTypeName());

        return false;

    }
1271923
public function updateContentTypeGroup($contentTypeGroupId, Request $request)
    {
        $createStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        try {
            $this->contentTypeService->updateContentTypeGroup(
                $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId),
                $this->mapToGroupUpdateStruct($createStruct)
            );

            return $this->contentTypeService->loadContentTypeGroup($contentTypeGroupId, Language::ALL);
        } catch (InvalidArgumentException $e) {
            throw new ForbiddenException($e->getMessage());
        }
    }
1327953
public function countRecords($contentTypeName = null, DataDimensions $dataDimensions = null)
    {
        if ($contentTypeName == null)
        {
            $contentTypeName = $this->getCurrentContentTypeName();
        }

        if ($dataDimensions == null)
        {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        if ($this->hasContentType($contentTypeName))
        {

            $info = $this->getRepositoryInfo($dataDimensions);

            return $info['content'][$contentTypeName]['count'];
        }

        throw new AnyContentClientException ('Unknown content type ' . $contentTypeName);

    }
1007954
public function queryExistingFields($id, $contentType, $field)
    {
        $query = $this->createQueryBuilder()
            ->select('grouping, id', 'name')
            ->where('content_id = :id')
            ->andWhere('contenttype = :contenttype')
            ->andWhere('name = :name')
            ->orderBy('grouping', 'ASC')
            ->setParameters([
                'id'          => $id,
                'contenttype' => $contentType,
                'name'        => $field,
            ]);

        return $query;
    }
71274
private function getContentTypeGroupsNumbers(array $contentTypeGroups): array
    {
        $contentTypeGroupsNumbers = array_column($contentTypeGroups, 'id');

        return array_combine($contentTypeGroupsNumbers, array_fill_keys($contentTypeGroupsNumbers, false));
    }
477268
protected function getAllMultiViewRecords($contentTypeName = null, DataDimensions $dataDimensions)
    {

        $folder = $this->getConfiguration()->getFolderNameRecords($contentTypeName, $dataDimensions);

        if (file_exists($folder))
        {
            $finder = new Finder();
            $finder->in($folder)->depth(0);

            $data = [ ];

            /** @var SplFileInfo $file */
            foreach ($finder->files()->name('*.json') as $file)
            {
                $data[] = json_decode($file->getContents(), true);

            }

            $definition = $this->getContentTypeDefinition($contentTypeName);

            $records = $this->getRecordFactory()
                            ->createRecordsFromJSONRecordsArray($definition, $data);

            return $records;

        }

        return [ ];

    }
1129115
private function getTimedRecords(ContentRepository $contentRepo, $type)
    {
        /** @var QueryBuilder $query */
        $query = $contentRepo->createQueryBuilder('t')
            ->andWhere('t.status = :status')
            ->setParameter('currenttime', Carbon::now(), Type::DATETIME)
        ;

        if ($type === 'timed') {
            $this->getTimedPublishQuery($query);
        } elseif ($type === 'hold') {
            $this->getHoldQuery($query);
        } else {
            throw new StorageException(sprintf('Invalid type "%s" for timed record processing.', $type));
        }

        return $contentRepo->findWith($query) ?: [];
    }
932500
public function getChangeLogByContentTypeQuery($contentType, array $options)
    {
        $alias = $this->getAlias();
        $contentTableName = $this->em->getRepository($contentType)->getTableName();

        $qb = $this->createQueryBuilder();
        $qb->select("$alias.*, $alias.title")
            ->leftJoin($alias, $contentTableName, 'content', "content.id = $alias.contentid");

        // Set required WHERE
        $this->setWhere($qb, $contentType, $options);

        // Set ORDER BY and LIMIT as requested
        $this->setLimitOrder($qb, $options);

        return $qb;
    }
106395
public function getAllRecords($contentTypeName = null, DataDimensions $dataDimensions = null)
    {
        if ($contentTypeName == null)
        {
            $contentTypeName = $this->getCurrentContentTypeName();
        }

        if ($dataDimensions == null)
        {
            $dataDimensions = $this->getCurrentDataDimensions();
        }

        if ($this->hasContentType($contentTypeName))
        {
            if ($this->hasStashedAllRecords($contentTypeName, $dataDimensions, $this->getRecordClassForContentType($contentTypeName)))
            {
                return $this->getStashedAllRecords($contentTypeName, $dataDimensions, $this->getRecordClassForContentType($contentTypeName));
            }

            $records = $this->requestRecords($contentTypeName, $dataDimensions, '');

            $this->stashAllRecords($records, $dataDimensions);

            return $records;
        }

        throw new AnyContentClientException ('Unknown content type ' . $contentTypeName);
    }
130922
public function loadRelations($contentId, $contentVersionNo = null, $relationType = null)
    {
        $query = $this->queryBuilder->createRelationFindQuery();
        $query->innerJoin(
            $query->alias(
                $this->dbHandler->quoteTable('ezcontentobject'),
                'ezcontentobject_to'
            ),
            $query->expr->lAnd(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('to_contentobject_id', 'ezcontentobject_link'),
                    $this->dbHandler->quoteColumn('id', 'ezcontentobject_to')
                ),
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('status', 'ezcontentobject_to'),
                    $query->bindValue(1, null, \PDO::PARAM_INT)
                )
            )
        )->where(
            $query->expr->eq(
                $this->dbHandler->quoteColumn('from_contentobject_id', 'ezcontentobject_link'),
                $query->bindValue($contentId, null, \PDO::PARAM_INT)
            )
        );

        // source version number
        if (isset($contentVersionNo)) {
            $query->where(
                $query->expr->eq(
                    $this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'),
                    $query->bindValue($contentVersionNo, null, \PDO::PARAM_INT)
                )
            );
        } else { // from published version only
            $query->from(
                $this->dbHandler->quoteTable('ezcontentobject')
            )->where(
                $query->expr->lAnd(
                    $query->expr->eq(
                        $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
                        $this->dbHandler->quoteColumn('from_contentobject_id', 'ezcontentobject_link')
                    ),
                    $query->expr->eq(
                        $this->dbHandler->quoteColumn('current_version', 'ezcontentobject'),
                        $this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link')
                    )
                )
            );
        }

        // relation type
        if (isset($relationType)) {
            $query->where(
                $query->expr->gt(
                    $query->expr->bitAnd(
                        $this->dbHandler->quoteColumn('relation_type', 'ezcontentobject_link'),
                        $query->bindValue($relationType, null, \PDO::PARAM_INT)
                    ),
                    0
                )
            );
        }

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }