170 lines
5.1 KiB
PHP
170 lines
5.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* SOTESHOP/stLanguagePlugin
|
|
*
|
|
* Ten plik należy do aplikacji stLanguagePlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stLanguagePlugin
|
|
* @subpackage actions
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
|
* @version $Id: actions.class.php 11171 2011-02-21 13:07:13Z michal $
|
|
* @author Michal Prochowski <michal.prochowski@sote.pl>
|
|
*/
|
|
|
|
/**
|
|
* Klasa stLanguageBackendActions
|
|
*
|
|
* @package stLanguagePlugin
|
|
* @subpackage actions
|
|
*/
|
|
class stLanguageBackendActions extends autoStLanguageBackendActions
|
|
{
|
|
public function executePreview()
|
|
{
|
|
$language = LanguagePeer::retrieveByPK($this->getRequestParameter('id'));
|
|
|
|
return $this->redirect(stRoutingHelper::generateApplicationUrl('@stLanguage_changeLanguage?lang='.$language->getShortcut(), 'frontend', $language->getShortcut()));
|
|
}
|
|
|
|
public function executeIndex()
|
|
{
|
|
return $this->redirect('stLanguageBackend/list', 301);
|
|
}
|
|
|
|
/**
|
|
* Zmiana języka na angielski
|
|
*/
|
|
public function executeChangeLanguage()
|
|
{
|
|
$shortcut = $this->getRequest()->getParameter('name');
|
|
|
|
if (empty($shortcut))
|
|
{
|
|
$shortcut = 'pl';
|
|
}
|
|
|
|
$culture = stSimpleLanguageHelper::shortcutToCulture($shortcut);
|
|
|
|
$this->getUser()->setCulture($culture);
|
|
|
|
$configuration = stAdminGeneratorUserConfiguration::getDefault($this->getContext());
|
|
$configuration->setParameter('culture', $culture);
|
|
$configuration->save();
|
|
|
|
return $this->redirect($this->getRequest()->getReferer());
|
|
}
|
|
|
|
/**
|
|
* Przeciążenie aktualizacji config'a
|
|
*/
|
|
protected function updateConfigFromRequest()
|
|
{
|
|
$config = $this->getRequestParameter('config');
|
|
|
|
$c = new Criteria();
|
|
$c->add(LanguagePeer::ID, $config['language_panel']);
|
|
$language = LanguagePeer::doSelectOne($c);
|
|
|
|
if (is_object($language))
|
|
{
|
|
$language->setIsDefaultPanel(true);
|
|
$language->save();
|
|
|
|
$this->getUser()->setCulture($language->getOriginalLanguage());
|
|
|
|
$config = stConfig::getInstance($this->getContext(), 'stLanguagePlugin');
|
|
$config->set('admin_language', $language->getOriginalLanguage());
|
|
$config->save();
|
|
}
|
|
}
|
|
|
|
public function executeRestoreDefaultTranslations()
|
|
{
|
|
$languageId = $this->getRequestParameter('language_id');
|
|
$language = LanguagePeer::retrieveByPK($languageId);
|
|
$i18n = $this->getContext()->getI18N();
|
|
|
|
$language->restoreDefaultTranslations();
|
|
|
|
$this->setFlash('success', $i18n->__('Domyślne tłumaczenia przywrócone.'));
|
|
|
|
return $this->redirect($this->getRequest()->getReferer());
|
|
}
|
|
|
|
public function executeRestoreDefaultTranslation()
|
|
{
|
|
$catalogue = $this->getRequestParameter('catalogue');
|
|
$index = $this->getRequestParameter('index');
|
|
$languageId = $this->getRequestParameter('language_id');
|
|
|
|
$translation = LanguageTranslationPeer::retrieveByPK($catalogue, $index, $languageId);
|
|
$translation->restore();
|
|
$translation->save();
|
|
$i18n = $this->getContext()->getI18N();
|
|
$this->setFlash('success', $i18n->__('Domyślne tłumaczenie przywrócone.'));
|
|
|
|
return $this->redirect($this->getRequest()->getReferer());
|
|
}
|
|
|
|
public function executeTranslationList()
|
|
{
|
|
parent::executeTranslationList();
|
|
|
|
if (!$this->related_object->hasUserTranslations())
|
|
{
|
|
$this->hideAction('restore_default_translations');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function getTranslationLanguageTranslationOrCreate($catalogue = 'catalogue', $index = 'index', $language_id = 'language_id')
|
|
{
|
|
$translation = parent::getTranslationLanguageTranslationOrCreate($catalogue, $index, $language_id);
|
|
|
|
if (!$translation->hasUserPhraseTranslation())
|
|
{
|
|
$this->hideAction('restore_default_translation');
|
|
}
|
|
|
|
return $translation;
|
|
}
|
|
|
|
|
|
protected function addTranslationCacheFiltersCriteria($c)
|
|
{
|
|
parent::addTranslationCacheFiltersCriteria($c);
|
|
$c->add(TranslationCachePeer::LANGUAGE_ID, $this->related_object->getId());
|
|
}
|
|
|
|
protected function filterCriteriaByLanguageCurrencyId(Criteria $criteria, $value): bool
|
|
{
|
|
if ('null' === $value)
|
|
{
|
|
$criteria->add(LanguagePeer::CURRENCY_ID, null, Criteria::ISNULL);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
protected function filterCriteriaByLanguageCountryId(Criteria $criteria, $value): bool
|
|
{
|
|
if ('null' === $value)
|
|
{
|
|
$criteria->add(LanguagePeer::COUNTRY_ID, null, Criteria::ISNULL);
|
|
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|