public function semdom_editor_dto($browserId, $lastFetchTime = null)
 {
     $sessionLabel = 'lexDbeFetch_' . $browserId;
     $this->app['session']->set($sessionLabel, time());
     if ($lastFetchTime) {
         $lastFetchTime = $lastFetchTime - 5;
         // 5 second buffer
         return SemDomTransEditDto::encode($this->projectId, $this->userId, $lastFetchTime);
     } else {
         return SemDomTransEditDto::encode($this->projectId, $this->userId);
     }
 }
 public function testEncode_SourceProjectAndTargetProjectHaveItems_DtoAsExpected()
 {
     self::$environ = new SemDomMongoTestEnvironment();
     self::$environ->cleanPreviousProject('es');
     /** @noinspection PhpUnusedLocalVariableInspection */
     $sourceProject = self::$environ->getEnglishProjectAndCreateIfNecessary();
     $user1Id = self::$environ->createUser('u', 'u', 'u');
     $targetProject = self::$environ->createSemDomProject('es', 'Spanish', $user1Id);
     /*
     // insert dummy models
     $sourceItemModel = new SemDomTransItemModel($sourceProject);
     $sourceItemModel->key = '1';
     $sourceItemModel->name = new SemDomTransTranslatedForm('universe');
     $sourceItemModel->description = new SemDomTransTranslatedForm('Universe description');
     $sq = new SemDomTransQuestion('A universe question', 'A universe question term');
     $sourceItemModel->questions = new ArrayOf(function ($data) {
         return new SemDomTransQuestion();
     });
     $sourceItemModel->questions[] = $sq;
     $sourceItemModel->write();
     */
     $targetItemsModel = new SemDomTransItemListModel($targetProject);
     $targetItemsModel->read();
     $targetItems = $targetItemsModel->entries;
     $targetItemModel = new SemDomTransItemModel($targetProject);
     $targetItemModel->readByProperty('xmlGuid', $targetItems[0]['xmlGuid']);
     $targetItemModel->key = '1';
     $targetItemModel->name = new SemDomTransTranslatedForm('wszechswiat');
     $targetItemModel->description = new SemDomTransTranslatedForm('Opis wszechswiata');
     $tq = new SemDomTransQuestion('Pytanie wszechswiata', 'Termin zwiazany z wszechswiatem');
     $targetItemModel->questions = new ArrayOf(function () {
         return new SemDomTransQuestion();
     });
     $targetItemModel->questions[] = $tq;
     $targetItemModel->write();
     // call dto
     //$loadTargetProject = new SemDomTransProjectModel($prId->asString());
     //$loadSourceProject = new SemDomTransProjectModel($loadTargetProject->sourceLanguageProjectId);
     $prId = $targetProject->id;
     $result = SemDomTransEditDto::encode($prId->asString(), null);
     // print_r($result);
     // check dto returns expected results
     $entries = $result['entries'];
     $this->assertTrue($entries != null);
     $this->assertTrue(count($entries) > 0);
     $firstObject = $entries[0];
     $this->assertNotNull($firstObject['key']);
     $this->assertEquals('1', $firstObject['key']);
     $this->assertNotNull($firstObject['name']);
     $this->assertEquals('Universe, creation', $firstObject['name']['source']);
     $this->assertEquals('wszechswiat', $firstObject['name']['translation']);
     $this->assertEquals(SemDomTransStatus::Draft, $firstObject['name']['status']);
     $this->assertNotNull($firstObject['description']);
     $this->assertEquals('Opis wszechswiata', $firstObject['description']['translation']);
     $this->assertEquals(SemDomTransStatus::Draft, $firstObject['description']['status']);
     $this->assertNotNull($firstObject['questions']);
     $this->assertNotNull($firstObject['questions'][0]);
     $this->assertNotNull($firstObject['questions'][0]['question']);
     $this->assertNotNull($firstObject['questions'][0]['terms']);
     $this->assertEquals('(1) What words refer to everything we can see?', $firstObject['questions'][0]['question']['source']);
     $this->assertEquals('Pytanie wszechswiata', $firstObject['questions'][0]['question']['translation']);
     $this->assertEquals('universe, creation, cosmos, heaven and earth, macrocosm, everything that exists', $firstObject['questions'][0]['terms']['source']);
     $this->assertEquals('Termin zwiazany z wszechswiatem', $firstObject['questions'][0]['terms']['translation']);
     // this test messes with the English source project
     self::$environ->clean();
     self::$environ->cleanPreviousProject('en');
 }
 public function testEncode_SourceProjectAndTargetProjectHaveItems_DtoAsExpected()
 {
     $e = new SemDomMongoTestEnvironment();
     $e->cleanPreviousProject('es');
     $sourceProject = $e->getEnglishProjectAndCreateIfNecessary();
     $user1Id = $e->createUser('u', 'u', 'u');
     $targetProject = $e->createSemDomProject('es', "Spanish", $user1Id);
     /*
     // insert dummy models
     $sourceItemModel = new SemDomTransItemModel($sourceProject);
     $sourceItemModel->key = "1";
     $sourceItemModel->name = new SemDomTransTranslatedForm("universe");
     $sourceItemModel->description = new SemDomTransTranslatedForm("Universe description");
     $sq = new SemDomTransQuestion("A universe question", "A universe question term");
     $sourceItemModel->questions = new ArrayOf(function ($data) {
         return new SemDomTransQuestion();
     });
     $sourceItemModel->questions[] = $sq;
     $sourceItemModel->write();
     */
     $targetItemsModel = new SemDomTransItemListModel($targetProject);
     $targetItemsModel->read();
     $targetItems = $targetItemsModel->entries;
     $targetItemModel = new SemDomTransItemModel($targetProject);
     $targetItemModel->readByProperty('xmlGuid', $targetItems[0]['xmlGuid']);
     $targetItemModel->key = "1";
     $targetItemModel->name = new SemDomTransTranslatedForm("wszechswiat");
     $targetItemModel->description = new SemDomTransTranslatedForm("Opis wszechswiata");
     $tq = new SemDomTransQuestion("Pytanie wszechswiata", "Termin zwiazany z wszechswiatem");
     $targetItemModel->questions = new ArrayOf(function ($data) {
         return new SemDomTransQuestion();
     });
     $targetItemModel->questions[] = $tq;
     $targetItemModel->write();
     // call dto
     //$loadTargetProject = new SemDomTransProjectModel($prId->asString());
     //$loadSourceProject = new SemDomTransProjectModel($loadTargetProject->sourceLanguageProjectId);
     $prId = $targetProject->id;
     $result = SemDomTransEditDto::encode($prId->asString(), null);
     // print_r($result);
     // check dto returns expected results
     $entries = $result["entries"];
     $this->assertTrue($entries != null);
     $this->assertTrue(count($entries) > 0);
     $firstObject = $entries[0];
     $this->assertNotEqual($firstObject["key"], null);
     $this->assertEqual($firstObject["key"], "1");
     $this->assertNotEqual($firstObject["name"], null);
     $this->assertEqual($firstObject["name"]["source"], "Universe, creation");
     $this->assertEqual($firstObject["name"]["translation"], "wszechswiat");
     $this->assertEqual($firstObject["name"]["status"], SemDomTransStatus::Draft);
     $this->assertNotEqual($firstObject["description"], null);
     $this->assertEqual($firstObject["description"]["translation"], "Opis wszechswiata");
     $this->assertEqual($firstObject["description"]["status"], SemDomTransStatus::Draft);
     $this->assertNotEqual($firstObject["questions"], null);
     $this->assertNotEqual($firstObject["questions"][0], null);
     $this->assertNotEqual($firstObject["questions"][0]["question"], null);
     $this->assertNotEqual($firstObject["questions"][0]["terms"], null);
     $this->assertEqual($firstObject["questions"][0]["question"]["source"], "(1) What words refer to everything we can see?");
     $this->assertEqual($firstObject["questions"][0]["question"]["translation"], "Pytanie wszechswiata");
     $this->assertEqual($firstObject["questions"][0]["terms"]["source"], "universe, creation, cosmos, heaven and earth, macrocosm, everything that exists");
     $this->assertEqual($firstObject["questions"][0]["terms"]["translation"], "Termin zwiazany z wszechswiatem");
     // this test messes with the English source project
     $e->clean();
     $e->cleanPreviousProject('en');
 }