public function executePublish()
 {
     //send the id to the publishing class
     if (!$this->vocabulary) {
         $this->vocabulary = VocabularyPeer::retrieveByPK($this->getRequestParameter('id'));
     }
     $vocabulary = $this->vocabulary;
     //todo: these should be configured by the publish form
     $uselanguageMap = true;
     $useLanguage = "";
     $cLang = null;
     ini_set('memory_limit', '640M');
     ini_set('max_execution_time', 600);
     $repo = $vocabulary->getRepo();
     $mime = "jsonld";
     $vocabDir = parse_url($vocabulary->getNamespace(), PHP_URL_PATH);
     if (!$vocabulary->getRepo() || !$vocabDir) {
         $this->setFlash('error', 'This Vocabulary has NOT been published. We couldn\'t parse the file names from the uri.</br>Make sure that you\'ve set the the Git repository and have a valid namespace');
         $this->redirect($this->getRequest()->getUriPrefix() . '/vocabulary/show/id/' . $vocabulary->getId() . '.html');
     }
     $file = rtrim($vocabDir, "/") . "." . $mime;
     $repoRoot = SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'repos' . DIRECTORY_SEPARATOR . "agents" . DIRECTORY_SEPARATOR . $vocabulary->getAgentId() . DIRECTORY_SEPARATOR . $repo;
     $filesystem = new Filesystem(new Adapter($repoRoot), new Cache());
     $filePath = $repoRoot . DIRECTORY_SEPARATOR . $mime . DIRECTORY_SEPARATOR . $file;
     //TODO: create an alias file
     $aliasPath = "alias" . DIRECTORY_SEPARATOR . $vocabDir;
     //make sure the path is created
     $filesystem->put($mime . DIRECTORY_SEPARATOR . $file, '');
     //open a file for writing the complete vocabulary file
     $vocabFile = fopen($filePath, 'w');
     $jsonLdService = new jsonldService($vocabulary);
     fwrite($vocabFile, $jsonLdService->getJsonLd());
     fclose($vocabFile);
     //TODO: generate RDF/XML and save
     //TODO: generate other flavours of RDF using EasyRDF and save
     //if publish was successful
     $this->setFlash('notice', 'This Vocabulary has been published');
     $this->redirect($this->getRequest()->getUriPrefix() . '/vocabulary/show/id/' . $vocabulary->getId() . '.html');
 }
    public function testFullJsonLD(FunctionalTester $I)
    {
        //i have a value vocabulary
        $vocab = $this->vocab;

        //then I retrieve the attributes for the vocabulary
        $GuzzleClient = new GuzzleHttp\Client(['base_uri'=> 'https://api.github.com']);
        $response = $GuzzleClient->request('GET', '/repos/RDARegistry/RDA-Vocabularies/releases/latest');
        $repoRelease = json_decode($response->getBody());
        $releaseVersion = $repoRelease->tag_name;
        $releaseDate = DateTime::createFromFormat(DateTime::W3C, $repoRelease->published_at)->format('F j, Y');
        $vocab->setRepo('RDARegistry/RDA-Vocabularies');
        $I->assertInstanceOf('Vocabulary', $vocab);

        //then I pass it to a new jsonld builder
        $jsonLdService = new jsonldService($vocab);
        $I->assertInstanceOf("Vocabulary", $jsonLdService->getVocabulary());
        //then I initialize the master array
        //then I build the attributes array
        $I->assertEquals($jsonLdService->vocabArray['@id'], "http://rdaregistry.info/termList/AspectRatio/", "expected @id doesn't match URI");
        $I->assertEquals($jsonLdService->vocabArray['@type'], "ConceptScheme");
        $I->assertEquals($jsonLdService->vocabArray['title'], [ "en" => 'RDA Aspect Ratio' ]);
        $I->assertEquals($jsonLdService->vocabArray['description'], [ "en" => 'The ratio of the width to the height of a moving image.' ]);
        $I->assertEquals($jsonLdService->vocabArray['prefix'], "rdaar");
        $I->assertEquals($jsonLdService->vocabArray['dateOfPublication'], "July 28, 2016");
        $I->assertEquals($jsonLdService->vocabArray['token'], "AspectRatio");
        $I->assertEquals($jsonLdService->vocabArray['status'],
                         [
                             "@id"          => 'http://metadataregistry.org/uri/RegStatus/1001',
                             "label"        => "Published"
                         ]);
        $I->assertEquals("http://api.metadataregistry.org/vocabularies/58", $jsonLdService->vocabArray['omr_api']);
        $I->assertEquals("http://metadataregistry.org/vocabulary/show/id/58.html", $jsonLdService->vocabArray['omr_home']);
        $I->assertEquals("http://www.rdaregistry.info/termList/AspectRatio/", $jsonLdService->vocabArray['documentation']);
        $I->assertEquals(
                         [
                               "en"=> [
                                   "Libraries",
                                   "Information Services"
                               ]
                         ],
                         $jsonLdService->vocabArray['tags']);
        $I->assertEquals("3", $jsonLdService->vocabArray['count']);
        $I->assertEquals([
        [
            "code"=> "ar",
          "lang"=> "Arabic",
          "version"=> "WIP"
        ],
        [
            "code"=> "zh",
          "lang"=> "Chinese",
          "version"=> $releaseVersion
        ],
        [
            "code"=> "nl",
          "lang"=> "Dutch",
          "version"=> "WIP"
        ],
        [
            "code"=> "en",
          "lang"=> "English",
          "version"=> $releaseVersion
        ],
        [
            "code"=> "fr",
          "lang"=> "French",
          "version"=> $releaseVersion
        ],
        [
            "code"=> "de",
          "lang"=> "German",
          "version"=> $releaseVersion
        ],
        [
            "code"=> "es",
          "lang"=> "Spanish",
          "version"=> $releaseVersion
        ],
        [
            "code"=> "sv",
          "lang"=> "Swedish",
          "version"=> "WIP"
        ]
      ],
                         $jsonLdService->vocabArray['languages']);
        $I->assertEquals($jsonLdService->vocabArray['dateOfPublication'], $releaseDate);


        $I->assertEquals('{
  "@context": "http://rdaregistry.info/Contexts/concepts_langmap.jsonld",
  "@graph": [
    {
      "@id": "http://rdaregistry.info/termList/AspectRatio",
      "@type": "ConceptScheme",
      "title": {
        "en": "RDA Aspect Ratio Designation"
      },
      "description": {
        "en": "A general designation of the ratio of the width to the height of a moving image."
      },
      "prefix":"rdaar",
      "token": "AspectRatio",
      "status": "http://metadataregistry.org/uri/RegStatus/1001",
      "dateOfPublication":"07/28/2016",
      "omr_api": "http://api.metadataregistry.org/vocabularies/58",
      "omr_home": "http://metadataregistry.org/vocabulary/show/id/58.html",
      "documentation": "http://www.rdaregistry.info/termList/AspectRatio/",
      "count":3,
      "tags": {
        "en": [
          "Libraries",
          "Information Services"
        ]
      },
      "languages": [
        {
          "code": "ar",
          "lang": "Arabic",
          "version": "WIP"
        },
        {
          "code": "zh",
          "lang": "Chinese",
          "version": "2.4.3"
        },
        {
          "code": "nl",
          "lang": "Dutch",
          "version": "WIP"
        },
        {
          "code": "en",
          "lang": "English",
          "version": "2.4.3"
        },
        {
          "code": "fr",
          "lang": "French",
          "version": "2.4.3"
        },
        {
          "code": "de",
          "lang": "German",
          "version": "2.4.3"
        },
        {
          "code": "es",
          "lang": "Spanish",
          "version": "2.4.3"
        },
        {
          "code": "sv",
          "lang": "Swedish",
          "version": "WIP"
        }
      ]
    },
    {
      "@id": "http://rdaregistry.info/termList/AspectRatio/1003",
      "@type": "Concept",
      "toolkitDefinition": {
        "zh": "在同一资源中动态图像资源包括多种宽高比。",
        "de": "Bildformat einer Bewegtbildressource, die mehrere Bildformate innerhalb derselben Ressource enthält.",
        "es": "Proporción dimensional de un recurso que incluye múltiples proporciones dimensionales dentro del mismo recurso.",
        "fr": "Format de l\u2019image d\u2019une ressource d\u2019images animées comprenant divers formats de l\u2019image à l\u2019intérieur de la même ressource.",
        "en": "Aspect ratio for a moving image resource that includes multiple aspect ratios within thesame resource."
      },
      "toolkitLabel": {
        "en": "mixed",
        "zh": "混合",
        "es": "mixta",
        "de": "gemischt",
        "fr": "mixte"
      },
      "api": "http://api.metadataregistry.org/concepts/729",
      "status": "published",
      "definition": {
        "de": "Bildformat einer Bewegtbildressource, die mehrere Bildformate innerhalb derselben Ressource enthält.",
        "en": "Aspect ratio for a moving image resource that includes multiple aspect ratios within thesame resource.",
        "fr": "Format de l\u2019image d\u2019une ressource d\u2019images animées comprenant divers formats de l\u2019image à l\u2019intérieur de la même ressource.",
        "zh": "在同一资源中动态图像资源包括多种宽高比。",
        "es": "Proporción dimensional de un recurso que incluye múltiples proporciones dimensionales dentro del mismo recurso."
      },
      "inScheme": "http://rdaregistry.info/termList/AspectRatio/",
      "prefLabel": {
        "fr": "mixte",
        "zh": "混合",
        "en": "mixed",
        "es": "mixta",
        "de": "gemischt"
      }
    },
    {
      "@id": "http://rdaregistry.info/termList/AspectRatio/1002",
      "@type": "Concept",
      "toolkitDefinition": {
        "es": "Proporción dimensional de un recurso de imagen en movimiento de 1.5:1 o mayor.",
        "zh": "动态图像的宽高比为1.5:1或更大。",
        "de": "Bildformat einer Bewegtbildressource von 1.5:1 oder höher.",
        "fr": "Format de l\u2019image d\u2019une ressource d\u2019images animées égal ou supérieur à 1,5:1.",
        "en": "Aspect ratio for a moving image resource of 1.5:1 or greater."
      },
      "toolkitLabel": {
        "es": "pantalla ancha",
        "zh": "宽屏",
        "fr": "écran large",
        "de": "Breitbild",
        "en": "wide screen"
      },
      "api": "http://api.metadataregistry.org/concepts/728",
      "status": "published",
      "altLabel": {
        "en": "wide-screen"
      },
      "definition": {
        "fr": "Format de l\u2019image d\u2019une ressource d\u2019images animées égal ou supérieur à 1,5:1.",
        "zh": "动态图像的宽高比为1.5:1或更大。",
        "en": "Aspect ratio for a moving image resource of 1.5:1 or greater.",
        "es": "Proporción dimensional de un recurso de imagen en movimiento de 1.5:1 o mayor.",
        "de": "Bildformat einer Bewegtbildressource von 1.5:1 oder höher."
      },
      "inScheme": "http://rdaregistry.info/termList/AspectRatio/",
      "prefLabel": {
        "en": "wide screen",
        "de": "Breitbild",
        "fr": "écran large",
        "zh": "宽屏",
        "es": "pantalla ancha"
      }
    },
    {
      "@id": "http://rdaregistry.info/termList/AspectRatio/1001",
      "@type": "Concept",
      "toolkitDefinition": {
        "es": "Proporción dimensional de un recurso de imagen en movimiento menor que 1.5:1.",
        "de": "Bildformat einer Bewegtbildressource von weniger als 1.5:1.",
        "fr": "Format de l\u2019image d\u2019une ressource d\u2019images animées inférieur à 1,5:1.",
        "en": "Aspect ratio for a moving image resource of less than 1.5:1.",
        "zh": "动态图像资源的宽高比小于1.5:1"
      },
      "toolkitLabel": {
        "fr": "plein écran",
        "de": "Vollbild",
        "en": "full screen",
        "zh": "全屏",
        "es": "pantalla completa"
      },
      "api": "http://api.metadataregistry.org/concepts/727",
      "status": "published",
      "altLabel": {
        "en": "full-screen"
      },
      "definition": {
        "de": "Bildformat einer Bewegtbildressource von weniger als 1.5:1.",
        "zh": "动态图像资源的宽高比小于1.5:1。",
        "es": "Proporción dimensional de un recurso de imagen en movimiento menor que 1.5:1.",
        "en": "Aspect ratio for a moving image resource of less than 1.5:1.",
        "fr": "Format de l\u2019image d\u2019une ressource d\u2019images animées inférieur à 1,5:1."
      },
      "inScheme": "http://rdaregistry.info/termList/AspectRatio/",
      "prefLabel": {
        "fr": "plein écran",
        "es": "pantalla completa",
        "zh": "全屏",
        "en": "full screen",
        "de": "Vollbild"
      }
    },
    {
      "published": {
        "@id": "http://metadataregistry.org/uri/RegStatus/1001",
        "lexicalAlias": "http://metadataregistry.org/uri/RegStatus/Published.en",
        "url": "http://metadataregistry.org/concept/show/id/412.html",
        "label": "Published"
      }
    }
  ]
}
',
                         $jsonLdService->getJsonLd());




        //then I add it to the main array
        //then I retrieve each of the Concepts joined with their ConceptProfileProperty for the vocabulary
        //then I build the attributes array for each Concept
        //then I add it to the master array
        //when all done I export it to a file in the repo

        //i request a jsonld context representation of the profile for that vocabulary
        //i see a jsonld context file in the repository for that vocabulary
        //i see that the file contains the correct data
    }