Skip to content

Commit

Permalink
OPUSVIER-1907 Added option of filtering by modules.
Browse files Browse the repository at this point in the history
  • Loading branch information
j3nsch committed Apr 4, 2020
1 parent ac99d0f commit 6082760
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
10 changes: 9 additions & 1 deletion library/Opus/Translate/Dao.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,22 @@ public function renameKey($key, $newKey, $module = 'default')
$database->commit();
}

public function getTranslationsWithModules()
public function getTranslationsWithModules($modules = null)
{
$table = Opus_Db_TableGateway::getInstance('Opus_Db_Translations');

$select = $table->getAdapter()->select()
->from(['t' => 'translations'], ['keys.key', 'locale', 'value', 'keys.module'])
->join(['keys' => 'translationkeys'], 't.key_id = keys.id');

if (! is_null($modules)) {
if (is_array($modules)) {
$select->where('keys.module IN (?)', $modules);
} else {
$select->where('keys.module = ?', $modules);
}
}

$rows = $table->getAdapter()->fetchAll($select);

$result = [];
Expand Down
41 changes: 40 additions & 1 deletion tests/Opus/Translate/DaoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public function testSetSpecialTranslation()

$translations = $dao->getTranslation('admin-actionbox-goto-section');

var_dump($translations);
$this->assertEquals($data, $translations);
}

public function testGetTranslationsWithModules()
Expand All @@ -547,6 +547,45 @@ public function testGetTranslationsWithModules()
$this->assertEquals($data, $testKey['values']);
}

public function testGetTranslationsWithModulesFilteredByModules()
{
$dao = new Opus_Translate_Dao();

$keyData = ['en' => 'keyEN', 'de' => 'keyDE'];
$defaultKeyData = ['en' => 'defaultKeyEN', 'de' => 'defaultKeyDE'];
$publishKeyData = ['en' => 'publishKeyEN', 'de' => 'publishKeyDE'];
$adminKeyData = ['en' => 'adminKeyEN', 'de' => 'adminKeyDE'];

$dao->setTranslation('key', $keyData);
$dao->setTranslation('default_key', $defaultKeyData, 'default');
$dao->setTranslation('publish_key', $publishKeyData, 'publish');
$dao->setTranslation('admin_key', $adminKeyData, 'admin');

// test no module specified
$translations = $dao->getTranslationsWithModules();

$this->assertCount(4, $translations);

// test single module
$translations = $dao->getTranslationsWithModules('default');

$this->assertCount(2, $translations);
$this->assertArrayHasKey('key', $translations);
$this->assertArrayHasKey('default_key', $translations);

// test multiple modules
$translations = $dao->getTranslationsWithModules(['publish', 'admin']);

$this->assertCount(2, $translations);
$this->assertArrayHasKey('publish_key', $translations);
$this->assertArrayHasKey('admin_key', $translations);

// test unknown module
$translations = $dao->getTranslationsWithModules('unknown857');

$this->assertCount(0, $translations);
}

public function testGetModules()
{
$dao = new Opus_Translate_Dao();
Expand Down

0 comments on commit 6082760

Please sign in to comment.