public function preFillFromSourceLanguage($useGoogleTranslateData = true) { $path = APPPATH . "resources/languageforge/semdomtrans/GoogleTranslateHarvester/semdom-google-translate-{$this->languageIsoCode}.txt.gz"; $googleTranslateData = []; if ($useGoogleTranslateData && file_exists($path)) { $lines = gzfile($path); foreach ($lines as $line) { $splitLine = explode("|", $line); if (count($splitLine) == 2) { $googleTranslateData[$splitLine[0]] = $splitLine[1]; } } } // cjh review: we may actually want to only prefill from English, if in the future we allow creating projects from incomplete source projects $sourceProject = new SemDomTransProjectModel($this->sourceLanguageProjectId->asString()); $this->copyXmlToAssets($sourceProject->xmlFilePath); $sourceItems = new SemDomTransItemListModel($sourceProject); $sourceItems->read(); foreach ($sourceItems->entries as $item) { $newItem = new SemDomTransItemModel($this); // if Google translation exists for given name exists, use it if (array_key_exists($item['name']['translation'], $googleTranslateData)) { $newItem->name->translation = $googleTranslateData[$item['name']['translation']]; $newItem->name->status = SemDomTransStatus::Suggested; } // if Google translation exists for given description exists, use it if (array_key_exists($item['description']['translation'], $googleTranslateData)) { $newItem->description->translation = $googleTranslateData[$item['description']['translation']]; $newItem->description->status = SemDomTransStatus::Suggested; } $newItem->key = $item['key']; for ($x = 0; $x < count($item['questions']); $x++) { $q = new SemDomTransQuestion(); // if Google translation exists for given question, use it if (array_key_exists($item['questions'][$x]['question']['translation'], $googleTranslateData)) { $q->question->translation = $googleTranslateData[$item['questions'][$x]['question']['translation']]; $q->question->status = SemDomTransStatus::Suggested; } // if Google translation exists for given question term, use it if (array_key_exists($item['questions'][$x]['terms']['translation'], $googleTranslateData)) { $q->terms->translation = $googleTranslateData[$item['questions'][$x]['terms']['translation']]; $q->terms->status = SemDomTransStatus::Suggested; } $newItem->questions[] = $q; } for ($x = 0; $x < count($item['searchKeys']); $x++) { $sk = new SemDomTransTranslatedForm(); // if Google translation exists for given search key, use it if (array_key_exists($item['searchKeys'][$x]['translation'], $googleTranslateData)) { $sk->translation = $googleTranslateData[$item['searchKeys'][$x]['translation']]; $sk->status = SemDomTransStatus::Suggested; } $newItem->searchKeys[] = $sk; } $newItem->xmlGuid = $item['xmlGuid']; $newItem->write(); } }
function testCleanupFiles_4Files2Allowed_2Removed() { $project = self::$environ->createProject(SF_TESTPROJECT, SF_TESTPROJECTCODE); $project->write(); $text = new TextModel($project); $textId = $text->write(); $fakeId = new Id(); $fakeTextId = $fakeId->asString(); $folderPath = $project->getAssetsFolderPath(); FileUtilities::createAllFolders($folderPath); $allowedExtensions = array(".mp2", ".mp3"); // put a copy of the test files in the folderPath $fileName1 = 'TestAudio1.mp1'; $filePath1 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName1); copy(TestPhpPath . 'common/TestAudio.mp3', $filePath1); $fileName2 = 'TestAudio2.mp2'; $filePath2 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName2); copy(TestPhpPath . 'common/TestAudio.mp3', $filePath2); $fileName3 = 'TestAudio3.mp3'; $filePath3 = SfchecksUploadCommands::mediaFilePath($folderPath, $textId, $fileName3); copy(TestPhpPath . 'common/TestAudio.mp3', $filePath3); $fileName4 = 'TestAudio4.mp3'; $filePath4 = SfchecksUploadCommands::mediaFilePath($folderPath, $fakeTextId, $fileName4); copy(TestPhpPath . 'common/TestAudio.mp3', $filePath4); $this->assertTrue(file_exists($filePath1), 'File should exist before cleanup'); $this->assertTrue(file_exists($filePath2), 'File should exist before cleanup'); $this->assertTrue(file_exists($filePath3), 'File should exist before cleanup'); $this->assertTrue(file_exists($filePath4), 'File should exist before cleanup'); SfchecksUploadCommands::cleanupFiles($folderPath, $textId, $allowedExtensions); $this->assertTrue(file_exists($filePath1), 'File should exist after cleanup'); $this->assertFalse(file_exists($filePath2), 'File should not exist after cleanup'); $this->assertFalse(file_exists($filePath3), 'File should not exist after cleanup'); $this->assertTrue(file_exists($filePath4), 'File should exist after cleanup'); self::$environ->cleanupTestFiles($folderPath); }
/** * Adds / updates an answer to the given question. * @param AnswerModel $answer * @return string $id */ public function writeAnswer($answer) { $id = $answer->id->asString(); if (empty($id)) { $id = $answer->id->id = QuestionModelMongoMapper::makeId(); $answerToWrite = $answer; } else { $answerToWrite = $this->answers[$id]; $properties = get_object_vars($answer); $exclude = array('comments'); foreach ($properties as $key => $value) { if (!in_array($key, $exclude)) { $answerToWrite->{$key} = $value; } } } $this->_mapper->write($answerToWrite, $id, MongoMapper::ID_IN_KEY, $this->id->asString(), 'answers'); return $id; }
public function listUsers() { $userList = new UserListProjectModel($this->id->asString()); $userList->read(); for ($i = 0, $l = count($userList->entries); $i < $l; $i++) { $userId = $userList->entries[$i]['id']; if (!array_key_exists($userId, $this->users)) { continue; } $userList->entries[$i]['role'] = $this->users[$userId]->role; } return $userList; }
public function listQuestionsWithAnswers() { $questionList = new QuestionAnswersListModel($this->_projectModel, $this->id->asString()); $questionList->read(); return $questionList; }