Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented several methods in translation entry point #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/Openl10n/Sdk/EntryPoint/TranslationEntryPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Openl10n\Sdk\EntryPoint;

use Openl10n\Sdk\Model\Project;
use Openl10n\Sdk\Model\Translation;

class TranslationEntryPoint extends AbstractEntryPoint
Expand All @@ -16,6 +17,39 @@ public function findBy()
throw new \BadMethodCallException('Not implemented yet!');
}

/**
* Finds a Translation by its identifier
*
* @param Project $project
* @param string $identifier
*
* @return Translation
*/
public function findOneByIdentifier(Project $project, $identifier)
{
$results = json_decode(
$this->getClient()->get(
'translations',
[
'query' => [
'project' => $project->getSlug(),
'identifier' => $identifier
]
]
)->getBody(),
true
);

if (count($results) === 1) {
$translation = new Translation($results[0]['identifier'], $results[0]['resource_id']);
$translation->setId($results[0]['id']);

return $translation;
}

return null;
}

public function get($id)
{
throw new \BadMethodCallException('Not implemented yet!');
Expand Down Expand Up @@ -45,6 +79,6 @@ public function update(Translation $translation)

public function delete(Translation $translation)
{
throw new \BadMethodCallException('Not implemented yet!');
$this->getClient()->delete('translations/' . $translation->getId());
}
}