Commit f1bb0896 authored by Utz, Wolf-Peter's avatar Utz, Wolf-Peter
Browse files

Merge branch 'feature/translation' into 'master'

Translation feature

See merge request shopware/plugins/RicoDynamicFAQ!17
parents c3121677 97f333c8
......@@ -26,6 +26,7 @@ class PluginInstaller
'dev',
'local',
'staging',
'debug',
];
/**
......
......@@ -7,12 +7,10 @@
* please read the LICENSE.txt file that was distributed with this source code.
*/
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\OptimisticLockException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\TransactionRequiredException;
use RicoDynamicFaq\Factory\MailFactory;
use RicoDynamicFaq\Models\Answer;
use RicoDynamicFaq\Models\Question;
/**
......@@ -56,28 +54,9 @@ class Shopware_Controllers_Backend_Faq extends Shopware_Controllers_Backend_Appl
protected function getDetailQuery($id)
{
$builder = parent::getDetailQuery($id);
$builder->leftJoin('question.answer', 'answer')
->leftJoin('question.categories', 'categories')
->addSelect('answer')
$builder->leftJoin('question.categories', 'categories')
->addSelect('categories');
return $builder;
}
/**
* {@inheritdoc}
*/
protected function resolveExtJsData($data)
{
$data = parent::resolveExtJsData($data);
$collection = new ArrayCollection();
foreach ($data['categories'] as $category) {
$collection->add($category);
}
$data['categories'] = $collection;
$answer = new Answer();
$data['answer'] = $answer->fromArray($data['answer']);
return $data;
}
}
......@@ -7,55 +7,18 @@
* please read the LICENSE.txt file that was distributed with this source code.
*/
namespace RicoDynamicFaq\Models;
use Doctrine\ORM\Mapping as ORM;
use Shopware\Components\Model\ModelEntity;
/**
* Class Answer.
*
* @ORM\Entity
* @ORM\Table(name="rico_faq_answer", options={"collate"="utf8_unicode_ci"})
* Class Shopware_Controllers_Backend_Faq.
*/
class Answer extends ModelEntity
class Shopware_Controllers_Backend_FaqQuestionCategories extends Shopware_Controllers_Backend_Application
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id = 0;
/**
* @var string
*
* @ORM\Column(type="text")
*/
protected $body = '';
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getBody()
{
return $this->body;
}
protected $model = \RicoDynamicFaq\Models\Question::class;
/**
* @param string $body
* @var string
*/
public function setBody($body)
{
$this->body = $body;
}
protected $alias = 'faq_question_category';
}
......@@ -51,13 +51,21 @@ class Shopware_Controllers_Frontend_Faq extends Enlight_Controller_Action
*/
public function indexAction()
{
$translationService = $this->container->get('rico_dynamic_faq.services.translation');
$this->view->assign([
'popularQuestions' => $this->questionRepository->findBestScored(
$this->get('rico_dynamic_faq.config')->get('questionLimit')
'popularQuestions' => $translationService->translateMultiple($this->questionRepository->findBestScored(
$this->get('rico_dynamic_faq.config')->get('questionLimit')),
'faq_question'
),
'topCategories' => $this->categoryRepository->findBy(['parent' => null]),
'categoryQuestionTree' => $this->get('rico_dynamic_faq.category_question_tree')->build(
$this->get('rico_dynamic_faq.category_tree')->build()
'topCategories' => $translationService->translateMultiple(
$this->categoryRepository->findBy(['parent' => null]),
'faq_category'
),
'categoryQuestionTree' => $translationService->translateMultiple(
$this->get('rico_dynamic_faq.category_question_tree')->build(
$this->get('rico_dynamic_faq.category_tree')->build()
),
'faq_category'
),
]);
}
......@@ -77,7 +85,8 @@ class Shopware_Controllers_Frontend_Faq extends Enlight_Controller_Action
$tracker->handleRequest(QuestionTracker::CLICK, $question);
$rated = Shopware()->Session()->get(QuestionTracker::SESSION_KEY)[$question->getId()]['rated'];
$this->view->assign([
'question' => $question,
'question' => $this->container->get('rico_dynamic_faq.services.translation')
->translateSingle($question, 'faq_question'),
'ratedQuestion' => $rated ? $rated : false,
]);
}
......
......@@ -43,11 +43,9 @@ class QuestionFixtures
{
$categories = $this->entityManager->getRepository(Category::class)->findAll();
for ($i = 1; $i < 15; ++$i) {
$answer = new Answer();
$answer->setBody($this->getRandomText());
$question = new Question();
$question->setBody("Question #$i");
$question->setAnswer($answer);
$question->setQuestionText("Question #$i");
$question->setAnswerText($this->getRandomText());
$question->setActive(true);
$question->setClicks(rand(1, 1234));
$question->setScore(rand(1, 1234));
......
......@@ -10,7 +10,6 @@
namespace RicoDynamicFaq\Loader;
use Doctrine\ORM\Tools\SchemaTool;
use RicoDynamicFaq\Models\Answer;
use RicoDynamicFaq\Models\Category;
use RicoDynamicFaq\Models\Question;
use Shopware\Components\Model\ModelManager;
......@@ -71,7 +70,6 @@ class DatabaseLoader
private function getClasses()
{
return [
$this->modelManager->getClassMetadata(Answer::class),
$this->modelManager->getClassMetadata(Question::class),
$this->modelManager->getClassMetadata(Category::class),
];
......
......@@ -27,15 +27,14 @@ class Question extends ModelEntity
*
* @ORM\Column(type="text")
*/
protected $body = '';
protected $questionText = '';
/**
* @var Answer
* @var string
*
* @ORM\OneToOne(targetEntity="RicoDynamicFaq\Models\Answer", cascade={"persist"}, orphanRemoval=true)
* @ORM\JoinColumn(name="answer", referencedColumnName="id")
* @ORM\Column(type="text")
*/
protected $answer;
protected $answerText = '';
/**
* @var int
......@@ -84,7 +83,7 @@ class Question extends ModelEntity
/**
* @var ArrayCollection
*
* @ORM\ManyToMany(targetEntity="RicoDynamicFaq\Models\Category")
* @ORM\ManyToMany(targetEntity="RicoDynamicFaq\Models\Category", cascade={"detach"})
* @ORM\JoinTable(name="rico_faq_answer_categoy_mm",
* joinColumns={@ORM\JoinColumn(name="question", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category", referencedColumnName="id")}
......@@ -111,33 +110,33 @@ class Question extends ModelEntity
/**
* @return string
*/
public function getBody()
public function getQuestionText()
{
return $this->body;
return $this->questionText;
}
/**
* @param string $body
* @param string $questionText
*/
public function setBody($body)
public function setQuestionText($questionText)
{
$this->body = $body;
$this->questionText = $questionText;
}
/**
* @return Answer
* @return string
*/
public function getAnswer()
public function getAnswerText()
{
return $this->answer;
return $this->answerText;
}
/**
* @param Answer $answer
* @param string $answerText
*/
public function setAnswer($answer)
public function setAnswerText($answerText)
{
$this->answer = $answer;
$this->answerText = $answerText;
}
/**
......
......@@ -64,7 +64,7 @@ class QuestionRepository extends ModelRepository
* @param int|null $limit
* @param int|null $offset
*
* @return array
* @return Question[]|null
*/
public function findBestScored($limit = null, $offset = null)
{
......
......@@ -2,6 +2,14 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/shopware/5.3/engine/Shopware/Components/Plugin/schema/config.xsd">
<elements>
<element>
<name>basePath</name>
<label>basePath</label>
<value>faq</value>
<description>
Should contain the base path for the main controller like "faq"
</description>
</element>
<element type="number">
<name>questionLimit</name>
<label>Question limit</label>
......@@ -11,4 +19,4 @@
<description lang="de">Definiert die maximale Anzahl an Fragen pro Seite.</description>
</element>
</elements>
</config>
\ No newline at end of file
</config>
......@@ -10,12 +10,12 @@
<br />
<b>Frage:</b>
<br />
{$question->getBody()}
{$question->getQuestionText()}
<br />
<br />
<b>Antwort:</b>
<br />
{$question->getAnswer()->getBody()}
{$question->getAnswerText()}
</p>
{include file="string:{config name=emailfooterhtml}"}
</div>
\ No newline at end of file
</div>
......@@ -4,9 +4,9 @@ Hallo,
Ihre Frage bei {config name=shopName} wurde beantwortet.
Frage:
{$question->getBody()}
{$question->getQuestionText()}
Antwort:
{$question->getAnswer()->getBody()}
{$question->getAnswerText()}
{include file="string:{config name=emailfooterhtml}"}
......@@ -9,14 +9,24 @@
<argument>%rico_dynamic_faq.plugin_dir%</argument>
<tag name="shopware.event_subscriber"/>
</service>
<service id="rico_dynamic_faq.subscribers.navigation_subscriber"
class="RicoDynamicFaq\Subscribers\NavigationSubscriber">
<service class="RicoDynamicFaq\Subscribers\UrlSubscriber"
id="rico_dynamic_faq.subscribers.url_subscriber">
<argument type="service" id="modules"/>
<argument type="service" id="models"/>
<argument type="service" id="shopware.plugin_manager"/>
<argument>%rico_dynamic_faq.plugin_name%</argument>
<tag name="shopware.event_subscriber"/>
</service>
<service class="RicoDynamicFaq\Subscribers\NavigationSubscriber"
id="rico_dynamic_faq.subscribers.navigation_subscriber">
<argument type="service" id="service_container" />
<argument type="service" id="models"/>
<tag name="shopware.event_subscriber"/>
</service>
<!-- misc -->
<service class="RicoDynamicFaq\Services\FaqConfigService" id="rico_dynamic_faq.config">
<argument type="service" id="shopware.plugin.cached_config_reader"/>
<argument>%rico_dynamic_faq.plugin_name%</argument>
<argument tag="service" id="service_container"/>
</service>
<service class="RicoDynamicFaq\Services\QueryPaginatorService" id="rico_dynamic_faq.paginator">
......@@ -42,5 +52,10 @@
<argument type="service" id="models"/>
<tag name="form.type"/>
</service>
<!-- Translation -->
<service id="rico_dynamic_faq.services.translation"
class="RicoDynamicFaq\Services\FaqTranslationService">
<argument type="service" id="translation"/>
</service>
</services>
</container>
[de_DE]
window_title = "Fragen & Antworten"
question_title = "Frage"
categories_title = "Kategorien"
answer_title = "Antwort"
question_detail = "Frage - Einzelansicht"
alert_error_title = "Fehler"
alert_success_title = "Erfolg"
mail_error_message = "Es ist ein Fehler aufgetreten! Die E-Mail konnte nicht versendet werden."
mail_success_message = "Die E-Mail wurde erfolgreich gesendet."
[en_GB]
window_title = "Questions & answers"
question_title = "Question"
categories_title = "Categories"
answer_title = "Answer"
question_detail = "Question - detail view"
alert_error_title = "Error"
alert_success_title = "Success"
mail_error_message = "An error occurred! The email has not been send."
mail_success_message = "The email has been send successfully."
\ No newline at end of file
[de_DE]
view/category/detail/title=Kategorie
view/category/window/title=Kategorie
view/detail/category/title="Kategorie"
view/detail/question/question_title="Frage"
view/detail/question/answer_title="Antwort"
view/detail/window/title="Frage - Einzelansicht"
view/detail/window/alert_error_title = "Fehler"
view/detail/window/mail_error_message = "Es ist ein Fehler aufgetreten! Die E-Mail konnte nicht versendet werden."
view/detail/window/alert_success_title = "Erfolg"
view/detail/window/mail_success_message = "Die E-Mail wurde erfolgreich gesendet."
view/main/window/title=FAQ
view/tab/category/title=Kategorie
view/tab/question/title=Frage
view/tab/question/question_title=Frage
view/tab/question/clicks_title=Klicks
view/tab/question/score_title=Wertung
view/tab/question/user_email=Email
view/tab/question/active_title=Aktiv
[en_GB]
view/category/detail/title=Category
view/category/window/title=Category
view/detail/category/title="Category"
view/detail/question/question_title="Question"
view/detail/question/answer_title="Answer"
view/detail/window/title="Question - detail"
view/detail/window/alert_error_title = "Error"
view/detail/window/mail_error_message = "An error occurred! The email has not been send."
view/detail/window/alert_success_title = "Success"
view/detail/window/mail_success_message = "The email has been send successfully."
view/main/window/title=FAQ
view/tab/category/title=Category
view/tab/question/title=Question
view/tab/question/question_title=Question
view/tab/question/clicks_title=Clicks
view/tab/question/score_title=Score
view/tab/question/user_email=Email
view/tab/question/active_title=Active
......@@ -8,13 +8,16 @@ Ext.define('Shopware.apps.Faq', {
'main.Window',
'tab.Category',
'tab.Question',
'detail.Window',
'detail.Question',
'detail.Answer',
'detail.Category'
'detail.Category',
'category.Window',
'category.Detail'
],
models: ['Question', 'Answer', 'Category'],
stores: ['Question', 'Answer', 'Category'],
models: ['Question', 'Category', 'QuestionCategory'],
stores: ['Question', 'Category'],
launch: function () {
return this.getController('Main').mainWindow;
}
......
Ext.define('Shopware.apps.Faq.controller.Main', {
extend: 'Enlight.app.Controller',
init: function () {
var me = this;
......@@ -14,10 +15,8 @@ Ext.define('Shopware.apps.Faq.controller.Main', {
handleStore: function(me) {
me.subApplication.categoryStore = me.subApplication.getStore('Category');
me.subApplication.questionStore = me.subApplication.getStore('Question');
me.subApplication.answerStore = me.subApplication.getStore('Answer');
me.subApplication.categoryStore.load();
me.subApplication.questionStore.load();
me.subApplication.answerStore.load();
}
});
......@@ -3,7 +3,7 @@ Ext.define('Shopware.apps.Faq.model.Category', {
configure: function () {
return {
controller: 'FaqCategory',
related: 'Shopware.apps.Faq.view.detail.Category'
related: 'Shopware.apps.Faq.view.category.Detail'
};
},
fields: [
......
Ext.define('Shopware.apps.Faq.model.Question', {
extend: 'Shopware.data.Model',
configure: function () {
return {
controller: 'Faq',
detail: 'Shopware.apps.Faq.view.detail.Question'
};
},
fields: [
{ name: 'id', type: 'int', useNull: true },
{ name: 'body', type: 'string' },
{ name: 'questionText', type: 'string' },
{ name: 'answerText', type: 'string' },
{ name: 'clicks', type: 'int' },
{ name: 'score', type: 'int' },
{ name: 'websiteUserCreated', type: 'boolean' },
......@@ -16,17 +19,10 @@ Ext.define('Shopware.apps.Faq.model.Question', {
{ name: 'active', type: 'boolean' }
],
associations: [
{
relation: 'OneToOne',
type: 'hasMany',
model: 'Shopware.apps.Faq.model.Answer',
name: 'getAnswer',
associationKey: 'answer'
},
{
relation: 'ManyToMany',
type: 'hasMany',
model: 'Shopware.apps.Faq.model.Category',
model: 'Shopware.apps.Faq.model.QuestionCategory',
name: 'getCategories',
associationKey: 'categories'
}
......
Ext.define('Shopware.apps.Faq.model.Answer', {
Ext.define('Shopware.apps.Faq.model.QuestionCategory', {
extend: 'Shopware.data.Model',
configure: function () {
configure: function() {
return {
controller: 'Faq',
detail: 'Shopware.apps.Faq.view.detail.Answer'
related: 'Shopware.apps.Faq.view.detail.Category'
};
},
fields: [
{ name: 'id', type: 'int', useNull: true },
{ name: 'body', type: 'string' }
{ name: 'name', type: 'string', useNull: true }
]
});
Ext.define('Shopware.apps.Faq.store.Answer', {
extend: 'Shopware.store.Listing',
configure: function () {
return {
controller: 'Faq'
};
},
model: 'Shopware.apps.Faq.model.Answer'
});
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment