From 4360b4d8bad2e865f840f007b5ae4e778e73fb93 Mon Sep 17 00:00:00 2001 From: Pierre Ducoudray Date: Mon, 19 Sep 2016 16:50:02 +0200 Subject: [PATCH] Fixes for project copywriting (#27) --- DependencyInjection/Configuration.php | 1 + .../WorldiaTextmasterExtension.php | 1 + Resources/config/services.xml | 1 + .../Project/app/config/config_test.yml | 1 + .../DependencyInjection/ConfigurationTest.php | 1 + .../WorldiaTextmasterExtensionTest.php | 3 ++ .../Translation/TranslationManagerTest.php | 5 +++- Translation/TranslationGenerator.php | 5 ++-- Translation/TranslationGeneratorInterface.php | 6 ++-- Translation/TranslationManager.php | 29 +++++++++++++++++-- Translation/TranslationManagerInterface.php | 4 ++- 11 files changed, 48 insertions(+), 9 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b6c488e..1984c07 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -52,6 +52,7 @@ public function getConfigTreeBuilder() ->prototype('scalar')->end() ->end() ->end() + ->scalarNode('copywriting_word_count')->isRequired()->end() ->end() ; diff --git a/DependencyInjection/WorldiaTextmasterExtension.php b/DependencyInjection/WorldiaTextmasterExtension.php index 6910ab7..aed6d17 100644 --- a/DependencyInjection/WorldiaTextmasterExtension.php +++ b/DependencyInjection/WorldiaTextmasterExtension.php @@ -41,5 +41,6 @@ public function load(array $configs, ContainerBuilder $container) $container->setParameter('worldia.textmaster.templates.job.reject', $config['templates']['job']['reject']); $container->setParameter('worldia.textmaster.mapping.properties', $config['mapping_properties']); + $container->setParameter('worldia.textmaster.copywriting_word_count', $config['copywriting_word_count']); } } diff --git a/Resources/config/services.xml b/Resources/config/services.xml index 00fcd0f..79609e5 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -69,6 +69,7 @@ + %worldia.textmaster.copywriting_word_count% diff --git a/Tests/Fixtures/Project/app/config/config_test.yml b/Tests/Fixtures/Project/app/config/config_test.yml index e61d338..ab38527 100644 --- a/Tests/Fixtures/Project/app/config/config_test.yml +++ b/Tests/Fixtures/Project/app/config/config_test.yml @@ -54,3 +54,4 @@ worldia_textmaster: base_uri: textmaster_api_base_uri mapping_properties: Worldia\Bundle\ProductTestBundle\Entity\Product: ['title', 'description'] + copywriting_word_count: 200 diff --git a/Tests/Units/DependencyInjection/ConfigurationTest.php b/Tests/Units/DependencyInjection/ConfigurationTest.php index dd7505b..50cdb3f 100644 --- a/Tests/Units/DependencyInjection/ConfigurationTest.php +++ b/Tests/Units/DependencyInjection/ConfigurationTest.php @@ -37,6 +37,7 @@ public function assertValidConfiguration() 'mapping_properties' => [ 'Worldia\Bundle\ProductTestBundle\Entity\Product' => ['title', 'description'], ], + 'copywriting_word_count' => 200, ], ] ); diff --git a/Tests/Units/DependencyInjection/WorldiaTextmasterExtensionTest.php b/Tests/Units/DependencyInjection/WorldiaTextmasterExtensionTest.php index 80f87fd..708aad3 100644 --- a/Tests/Units/DependencyInjection/WorldiaTextmasterExtensionTest.php +++ b/Tests/Units/DependencyInjection/WorldiaTextmasterExtensionTest.php @@ -27,6 +27,7 @@ protected function getMinimalConfiguration() 'api_key' => 'My API key', 'api_secret' => 'My API secret', ], + 'copywriting_word_count' => 200, ]; } @@ -46,6 +47,8 @@ public function assertParameters() $this->assertContainerBuilderHasParameter('worldia.textmaster.templates.project.index', 'WorldiaTextmasterBundle:Project:list.html.twig'); $this->assertContainerBuilderHasParameter('worldia.textmaster.templates.job.show', 'WorldiaTextmasterBundle:Job:show.html.twig'); $this->assertContainerBuilderHasParameter('worldia.textmaster.templates.job.index', 'WorldiaTextmasterBundle:Job:list.html.twig'); + + $this->assertContainerBuilderHasParameter('worldia.textmaster.copywriting_word_count', 200); } /** diff --git a/Tests/Units/Translation/TranslationManagerTest.php b/Tests/Units/Translation/TranslationManagerTest.php index 5bbaaea..37fabca 100644 --- a/Tests/Units/Translation/TranslationManagerTest.php +++ b/Tests/Units/Translation/TranslationManagerTest.php @@ -47,6 +47,9 @@ public function shouldCreateProject() $projectMock->expects($this->once()) ->method('setCallback') ->willReturn($projectMock); + $projectMock->expects($this->once()) + ->method('setWorkTemplate') + ->willReturn($projectMock); $projectMock->expects($this->once()) ->method('save') ->willReturn($projectMock); @@ -63,7 +66,7 @@ public function shouldCreateProject() ->method('create') ->willReturn($documentMock); - $translationManager = new TranslationManager($textmasterManagerMock, $translatorMock, $routerMock); + $translationManager = new TranslationManager($textmasterManagerMock, $translatorMock, $routerMock, 150); $project = $translationManager->create([$translatableMock], 'Project 1', 'en', 'fr', 'CO21', 'Lorem ipsum...', ['language_level' => 'premium']); $this->assertTrue(in_array('Textmaster\Model\ProjectInterface', class_implements($project))); diff --git a/Translation/TranslationGenerator.php b/Translation/TranslationGenerator.php index a0bff1f..4fff0a1 100644 --- a/Translation/TranslationGenerator.php +++ b/Translation/TranslationGenerator.php @@ -48,7 +48,8 @@ public function generate( $briefing, $languageTo = null, array $options = [], - $activity = ProjectInterface::ACTIVITY_TRANSLATION + $activity = ProjectInterface::ACTIVITY_TRANSLATION, + $workTemplate = null ) { if (null === $locale = $languageTo) { $locale = $languageFrom; @@ -59,7 +60,7 @@ public function generate( return; } - $project = $this->translationManager->create($translatables, $name, $languageFrom, $category, $briefing, $languageTo, $options, $activity); + $project = $this->translationManager->create($translatables, $name, $languageFrom, $category, $briefing, $languageTo, $options, $activity, $workTemplate); return $project->launch(); } diff --git a/Translation/TranslationGeneratorInterface.php b/Translation/TranslationGeneratorInterface.php index a9e878f..96b119d 100644 --- a/Translation/TranslationGeneratorInterface.php +++ b/Translation/TranslationGeneratorInterface.php @@ -17,7 +17,8 @@ interface TranslationGeneratorInterface * @param string $briefing textmaster project briefing * @param string $languageTo destination language identifier (ex: fr, en, de...) * @param array $options textmaster project options - * @param array $activity textmaster project activity + * @param string $activity textmaster project activity + * @param string $workTemplate textmaster project work template * * @return ProjectInterface|null */ @@ -30,6 +31,7 @@ public function generate( $briefing, $languageTo = null, array $options = [], - $activity + $activity, + $workTemplate = null ); } diff --git a/Translation/TranslationManager.php b/Translation/TranslationManager.php index b753433..6447a71 100644 --- a/Translation/TranslationManager.php +++ b/Translation/TranslationManager.php @@ -25,21 +25,29 @@ class TranslationManager implements TranslationManagerInterface */ protected $router; + /** + * @var int + */ + protected $defaultWordCount; + /** * TranslationManager constructor. * * @param Manager $textmasterManager * @param TranslatorInterface $translator * @param UrlGeneratorInterface $router + * @param int $defaultWordCount */ public function __construct( Manager $textmasterManager, TranslatorInterface $translator, - UrlGeneratorInterface $router + UrlGeneratorInterface $router, + $defaultWordCount ) { $this->textmasterManager = $textmasterManager; $this->translator = $translator; $this->router = $router; + $this->defaultWordCount = $defaultWordCount; } /** @@ -53,7 +61,8 @@ public function create( $briefing, $languageTo = null, array $options = [], - $activity = ProjectInterface::ACTIVITY_TRANSLATION + $activity = ProjectInterface::ACTIVITY_TRANSLATION, + $workTemplate = null ) { $project = $this->textmasterManager->getProject(); $project @@ -64,6 +73,7 @@ public function create( ->setCategory($category) ->setBriefing($briefing) ->setOptions($options) + ->setWorkTemplate($workTemplate) ->setCallback($this->generateProjectCallback()) ; @@ -93,8 +103,8 @@ protected function generateDocuments(ProjectInterface $project, array $translata { $callback = $this->generateDocumentCallback($project); $activity = $project->getActivity(); - $documents = []; + $documents = []; foreach ($translatableList as $translatable) { $params = []; $params['project'] = $project; @@ -102,6 +112,7 @@ protected function generateDocuments(ProjectInterface $project, array $translata 'title' => $this->generateTitle($project, $translatable), 'instructions' => $this->generateInstructions($translatable, $activity), 'callback' => $callback, + 'word_count' => ProjectInterface::ACTIVITY_COPYWRITING === $activity ? $this->getWordCount($translatable) : 0, ]; $documents[] = $this->translator->create($translatable, $params, false); } @@ -140,6 +151,18 @@ protected function generateInstructions($translatable, $activity) return ''; } + /** + * Get word count for a copywriting document. + * + * @param object $translatable + * + * @return string + */ + protected function getWordCount($translatable) + { + return $this->defaultWordCount; + } + /** * Generate a default callback for document in review. * diff --git a/Translation/TranslationManagerInterface.php b/Translation/TranslationManagerInterface.php index 0a049aa..e8f6ca6 100644 --- a/Translation/TranslationManagerInterface.php +++ b/Translation/TranslationManagerInterface.php @@ -18,6 +18,7 @@ interface TranslationManagerInterface * @param string $languageTo * @param array $options * @param string $activity + * @param string $workTemplate * * @return ProjectInterface */ @@ -29,7 +30,8 @@ public function create( $briefing, $languageTo = null, array $options = [], - $activity = ProjectInterface::ACTIVITY_TRANSLATION + $activity = ProjectInterface::ACTIVITY_TRANSLATION, + $workTemplate = null ); /**