src/Controller/Framework/DocTreeController.php
/**
     * Export a CFPackage in a special json format designed for efficiently loading the package's data to the OpenSALT doctree client.
     *
     * @Route("/docexport/{id}.json", name="doctree_cfpackage_export", methods={"GET"})
     */
Export a CFPackage in a special json format designed for efficiently loading the package's data to the OpenSALT doctree client.
Export a CFPackage in a special json format designed for efficiently loading the package ' s data to the OpenSALT doctree client .
public function exportAction(Request $request, LsDoc $lsDoc): JsonResponse
    {
        $response = new JsonResponse();
        $changeRepo = $this->getDoctrine()->getRepository(ChangeEntry::class);
        $lastChange = $changeRepo->getLastChangeTimeForDoc($lsDoc);
        $lastModified = $lsDoc->getUpdatedAt();
        if (false !== $lastChange && null !== $lastChange['changed_at']) {
            $lastModified = new \DateTime($lastChange['changed_at'], new \DateTimeZone('UTC'));
        }
        $response->setEtag(md5($lastModified->format('U.u').self::ETAG_SEED), true);
        $response->setLastModified($lastModified);
        $response->setMaxAge(0);
        $response->setSharedMaxAge(0);
        $response->setExpires(\DateTime::createFromFormat('U', $lastModified->format('U'))->sub(new \DateInterval('PT1S')));
        $response->setPublic();
        $response->headers->addCacheControlDirective('must-revalidate');
        if ($response->isNotModified($request)) {
            return $response;
        }
        $items = $this->getDoctrine()->getRepository(LsDoc::class)->findItemsForExportDoc($lsDoc);
        $associations = $this->getDoctrine()->getRepository(LsDoc::class)->findAssociationsForExportDoc($lsDoc);
        $assocGroups = $this->getDoctrine()->getRepository(LsDefAssociationGrouping::class)->findBy(['lsDoc' => $lsDoc]);
        $associatedDocs = array_merge(
            $lsDoc->getExternalDocs(),
            $this->getDoctrine()->getRepository(LsDoc::class)->findAssociatedDocs($lsDoc)
        );
        $docAttributes = [
            'baseDoc' => $lsDoc->getAttribute('baseDoc'),
            'associatedDocs' => $associatedDocs,
        ];
        $itemTypes = [];
        foreach ($items as $item) {
            if (!empty($item['itemType'])) {
                $itemTypes[$item['itemType']['code']] = $item['itemType'];
            }
        }
        $arr = [
            'lsDoc' => $lsDoc,
            'docAttributes' => $docAttributes,
            'items' => $items,
            'associations' => $associations,
            'itemTypes' => $itemTypes,
            'subjects' => $lsDoc->getSubjects(),
            'concepts' => [],
            'licences' => [$lsDoc->getLicence()],
            'assocGroups' => $assocGroups,
        ];
        $response->setContent($this->renderView('framework/doc_tree/export.json.twig', $arr));
        return $response;
    }
public function exportAction ( Request $ request , LsDoc $ lsDoc ) : JsonResponse { $ response = new JsonResponse ( ) ; $ changeRepo = $ this -> getDoctrine ( ) -> getRepository ( ChangeEntry :: class ) ; $ lastChange = $ changeRepo -> getLastChangeTimeForDoc ( $ lsDoc ) ; $ lastModified = $ lsDoc -> getUpdatedAt ( ) ; if ( false !== $ lastChange && null !== $ lastChange [ 'changed_at' ] ) { $ lastModified = new \ DateTime ( $ lastChange [ 'changed_at' ] , new \ DateTimeZone ( 'UTC' ) ) ; } $ response -> setEtag ( md5 ( $ lastModified -> format ( 'U.u' ) . self :: ETAG_SEED ) , true ) ; $ response -> setLastModified ( $ lastModified ) ; $ response -> setMaxAge ( 0 ) ; $ response -> setSharedMaxAge ( 0 ) ; $ response -> setExpires ( \ DateTime :: createFromFormat ( 'U' , $ lastModified -> format ( 'U' ) ) -> sub ( new \ DateInterval ( 'PT1S' ) ) ) ; $ response -> setPublic ( ) ; $ response -> headers -> addCacheControlDirective ( 'must-revalidate' ) ; if ( $ response -> isNotModified ( $ request ) ) { return $ response ; } $ items = $ this -> getDoctrine ( ) -> getRepository ( LsDoc :: class ) -> findItemsForExportDoc ( $ lsDoc ) ; $ associations = $ this -> getDoctrine ( ) -> getRepository ( LsDoc :: class ) -> findAssociationsForExportDoc ( $ lsDoc ) ; $ assocGroups = $ this -> getDoctrine ( ) -> getRepository ( LsDefAssociationGrouping :: class ) -> findBy ( [ 'lsDoc' => $ lsDoc ] ) ; $ associatedDocs = array_merge ( $ lsDoc -> getExternalDocs ( ) , $ this -> getDoctrine ( ) -> getRepository ( LsDoc :: class ) -> findAssociatedDocs ( $ lsDoc ) ) ; $ docAttributes = [ 'baseDoc' => $ lsDoc -> getAttribute ( 'baseDoc' ) , 'associatedDocs' => $ associatedDocs , ] ; $ itemTypes = [ ] ; foreach ( $ items as $ item ) { if ( ! empty ( $ item [ 'itemType' ] ) ) { $ itemTypes [ $ item [ 'itemType' ] [ 'code' ] ] = $ item [ 'itemType' ] ; } } $ arr = [ 'lsDoc' => $ lsDoc , 'docAttributes' => $ docAttributes , 'items' => $ items , 'associations' => $ associations , 'itemTypes' => $ itemTypes , 'subjects' => $ lsDoc -> getSubjects ( ) , 'concepts' => [ ] , 'licences' => [ $ lsDoc -> getLicence ( ) ] , 'assocGroups' => $ assocGroups , ] ; $ response -> setContent ( $ this -> renderView ( 'framework/doc_tree/export.json.twig' , $ arr ) ) ; return $ response ; }
Export a CFPackage in a special json format designed for efficiently loading the package's data to the OpenSALT doctree client.
Export a CFPackage in a special json format designed for efficiently loading the package ' s data to the OpenSALT doctree client .
// This is called to retrieve a response by other methods, so cannot use a template