作者:alex6353
项目:theli
public function postActivation(ConnectionInterface $con = null)
{
// delete existing message
$message = MessageQuery::create()->filterByName('mail_virtualproduct')->findOne($con);
if (null !== $message) {
$message->delete($con);
}
// create new message
$message = new Message();
$message->setName('mail_virtualproduct')->setSecured(0);
$basePath = __DIR__ . '/Config/message/%s.xml';
$languages = LangQuery::create()->find();
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$path = sprintf($basePath, $language->getLocale());
if (file_exists($path) && is_readable($path)) {
$dom = new SimpleXMLElement(file_get_contents($path));
if ($dom) {
$message->setTitle((string) $dom->title);
$message->setSubject((string) $dom->subject);
$message->setTextMessage((string) $dom->text);
$message->setHtmlMessage((string) $dom->html);
}
}
}
$message->save();
}
作者:alex6353
项目:theli
/**
* Save the previous URL in session which is based on the referer header or the request, or
* the _previous_url request attribute, if defined.
*
* If the value of _previous_url is "dont-save", the current referrer is not saved.
*
* @param FilterResponseEvent $event
*/
public function registerPreviousUrl(PostResponseEvent $event)
{
$request = $event->getRequest();
$referrer = $request->attributes->get('_previous_url', null);
if (null !== $referrer) {
// A previous URL (or the keyword 'dont-save') has been specified.
if ('dont-save' == $referrer) {
// We should not save the current URL as the previous URL
$referrer = null;
}
} else {
// The current URL will become the previous URL
$referrer = $request->getUri();
}
// Set previous URL, if defined
if (null !== $referrer) {
$session = $request->getSession();
if (ConfigQuery::read("one_domain_foreach_lang", false) == 1) {
$components = parse_url($referrer);
$lang = LangQuery::create()->filterByUrl(sprintf("%s://%s", $components["scheme"], $components["host"]), ModelCriteria::LIKE)->findOne();
if (null !== $lang) {
$session->setReturnToUrl($referrer);
}
} else {
if (false !== strpos($referrer, $request->getSchemeAndHttpHost())) {
$session->setReturnToUrl($referrer);
}
}
}
}
作者:egrue
项目:jus-de-corosso
public function postActivation(ConnectionInterface $con = null)
{
// register config variables
if (null === ConfigQuery::read(self::CONFIG_TRACKING_URL, null)) {
ConfigQuery::write(self::CONFIG_TRACKING_URL, self::DEFAULT_TRACKING_URL);
}
if (null === ConfigQuery::read(self::CONFIG_PICKING_METHOD, null)) {
ConfigQuery::write(self::CONFIG_PICKING_METHOD, self::DEFAULT_PICKING_METHOD);
}
if (null === ConfigQuery::read(self::CONFIG_TAX_RULE_ID, null)) {
ConfigQuery::write(self::CONFIG_TAX_RULE_ID, self::DEFAULT_TAX_RULE_ID);
}
// create new message
if (null === MessageQuery::create()->findOneByName('mail_custom_delivery')) {
$message = new Message();
$message->setName('mail_custom_delivery')->setHtmlTemplateFileName('custom-delivery-shipping.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('custom-delivery-shipping.txt')->setTextLayoutFileName('')->setSecured(0);
$languages = LangQuery::create()->find();
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$message->setTitle($this->trans('Custom delivery shipping message', [], $locale));
$message->setSubject($this->trans('Your order {$order_ref} has been shipped', [], $locale));
}
$message->save();
}
}
作者:alex6353
项目:theli
/**
* Validate a date entered with the default Language date format.
*
* @param string $value
* @param ExecutionContextInterface $context
*/
public function checkLocalizedDate($value, ExecutionContextInterface $context)
{
$format = LangQuery::create()->findOneByByDefault(true)->getDateFormat();
if (false === \DateTime::createFromFormat($format, $value)) {
$context->addViolation(Translator::getInstance()->trans("Date '%date' is invalid, please enter a valid date using %fmt format", ['%fmt' => $format, '%date' => $value]));
}
}
作者:Mertiozy
项目:StockAler
public function postActivation(ConnectionInterface $con = null)
{
$languages = LangQuery::create()->find();
ConfigQuery::write(self::CONFIG_ENABLED, self::DEFAULT_ENABLED);
ConfigQuery::write(self::CONFIG_THRESHOLD, self::DEFAULT_THRESHOLD);
ConfigQuery::write(self::CONFIG_EMAILS, self::DEFAULT_EMAILS);
// create new message
if (null === MessageQuery::create()->findOneByName('stockalert_customer')) {
$message = new Message();
$message->setName('stockalert_customer')->setHtmlTemplateFileName('alert-customer.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('alert-customer.txt')->setTextLayoutFileName('')->setSecured(0);
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$message->setTitle($this->trans('Stock Alert - Customer', [], $locale));
$message->setSubject($this->trans('Product {$product_title} is available again', [], $locale));
}
$message->save();
$message = new Message();
$message->setName('stockalert_administrator')->setHtmlTemplateFileName('alert-administrator.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('alert-administrator.txt')->setTextLayoutFileName('')->setSecured(0);
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$message->setTitle($this->trans('Stock Alert - Administrator', [], $locale));
$message->setSubject($this->trans('Product {$product_title} is (nearly) out of stock', [], $locale));
}
$message->save();
}
try {
RestockingAlertQuery::create()->findOne();
} catch (\Exception $e) {
$database = new Database($con);
$database->insertSql(null, [__DIR__ . '/Config/thelia.sql']);
}
}
作者:MaximeMorill
项目:theli
public function uploadImage()
{
if (null !== ($response = $this->checkAuth(AdminResources::MODULE, ['carousel'], AccessManager::CREATE))) {
return $response;
}
$request = $this->getRequest();
$form = $this->createForm('carousel.image');
$error_message = null;
try {
$this->validateForm($form);
/** @var \Symfony\Component\HttpFoundation\File\UploadedFile $fileBeingUploaded */
$fileBeingUploaded = $request->files->get(sprintf('%s[file]', $form->getName()), null, true);
$fileModel = new Carousel();
$fileCreateOrUpdateEvent = new FileCreateOrUpdateEvent(1);
$fileCreateOrUpdateEvent->setModel($fileModel);
$fileCreateOrUpdateEvent->setUploadedFile($fileBeingUploaded);
$this->dispatch(TheliaEvents::IMAGE_SAVE, $fileCreateOrUpdateEvent);
// Compensate issue #1005
$langs = LangQuery::create()->find();
/** @var Lang $lang */
foreach ($langs as $lang) {
$fileCreateOrUpdateEvent->getModel()->setLocale($lang->getLocale())->setTitle('')->save();
}
$response = $this->redirectToConfigurationPage();
} catch (FormValidationException $e) {
$error_message = $this->createStandardFormValidationErrorMessage($e);
}
if (null !== $error_message) {
$this->setupFormErrorContext('carousel upload', $error_message, $form);
$response = $this->render("module-configure", ['module_code' => 'Carousel']);
}
return $response;
}
作者:marger
项目:theli
public function setUp()
{
$this->locale = LangQuery::create()->findOne()->getLocale();
$this->dispatcher = $this->getMock('\\Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
$stubContainer = $this->getMockBuilder('\\Symfony\\Component\\DependencyInjection\\ContainerInterface')->disableOriginalConstructor()->getMock();
$this->action = new Hook($stubContainer);
}
作者:marger
项目:theli
protected function retrieveLocale($viewLocale)
{
if (strlen($viewLocale) == 2) {
if (null !== ($lang = LangQuery::create()->findOneByCode($viewLocale))) {
$viewLocale = $lang->getLocale();
}
}
return $viewLocale;
}
作者:alex6353
项目:theli
protected function applyUserLocale(Admin $user)
{
// Set the current language according to Admin locale preference
$locale = $user->getLocale();
if (null === ($lang = LangQuery::create()->findOneByLocale($locale))) {
$lang = Lang::getDefaultLanguage();
}
$this->getSession()->setLang($lang);
}
作者:marger
项目:theli
protected function getLocaleList()
{
$locales = array();
$list = LangQuery::create()->find();
foreach ($list as $item) {
$locales[$item->getLocale()] = $item->getLocale();
}
return $locales;
}
作者:vigourouxjulie
项目:theli
public function updateAction($lang_id)
{
if (null !== ($response = $this->checkAuth(AdminResources::LANGUAGE, array(), AccessManager::UPDATE))) {
return $response;
}
$this->checkXmlHttpRequest();
$lang = LangQuery::create()->findPk($lang_id);
$langForm = $this->createForm(AdminForm::LANG_UPDATE, 'form', array('id' => $lang->getId(), 'title' => $lang->getTitle(), 'code' => $lang->getCode(), 'locale' => $lang->getLocale(), 'date_time_format' => $lang->getDateTimeFormat(), 'date_format' => $lang->getDateFormat(), 'time_format' => $lang->getTimeFormat(), 'decimal_separator' => $lang->getDecimalSeparator(), 'thousands_separator' => $lang->getThousandsSeparator(), 'decimals' => $lang->getDecimals()));
$this->getParserContext()->addForm($langForm);
return $this->render('ajax/language-update-modal', array('lang_id' => $lang_id));
}
作者:alex6353
项目:theli
/**
* @param integer $id
* @return Response
*
* This method is called when the route /admin/export/{id}
* is called with a POST request.
*/
public function export($id)
{
if (null === ($export = $this->getExport($id))) {
return $this->pageNotFound();
}
/**
* Get needed services
*/
$archiveBuilderManager = $this->getArchiveBuilderManager($this->container);
$formatterManager = $this->getFormatterManager($this->container);
/**
* Get the archive builders
*/
$archiveBuilders = [];
foreach ($archiveBuilderManager->getNames() as $archiveBuilder) {
$archiveBuilders[$archiveBuilder] = $archiveBuilder;
}
/**
* Define and validate the form
*/
$form = new ExportForm($this->getRequest());
$errorMessage = null;
try {
$boundForm = $this->validateForm($form);
$lang = LangQuery::create()->findPk($boundForm->get("language")->getData());
$archiveBuilder = null;
/**
* Get the formatter and the archive builder if we have to compress the file(s)
*/
/** @var \Thelia\Core\FileFormat\Formatting\AbstractFormatter $formatter */
$formatter = $formatterManager->get($boundForm->get("formatter")->getData());
if ($boundForm->get("do_compress")->getData()) {
/** @var \Thelia\Core\FileFormat\Archive\ArchiveBuilderInterface $archiveBuilder */
$archiveBuilder = $archiveBuilderManager->get($boundForm->get("archive_builder")->getData());
}
/**
* Return the generated Response
*/
return $this->processExport($formatter, $export->getHandleClassInstance($this->container), $archiveBuilder, $lang, $boundForm->get("images")->getData(), $boundForm->get("documents")->getData());
} catch (FormValidationException $e) {
$errorMessage = $this->createStandardFormValidationErrorMessage($e);
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
}
/**
* If has an error, display it
*/
if (null !== $errorMessage) {
$form->setErrorMessage($errorMessage);
$this->getParserContext()->addForm($form)->setGeneralError($errorMessage);
}
return $this->exportView($id);
}
作者:zorn-
项目:theli
public function buildModelCriteria()
{
$search = LangQuery::create();
if (null !== ($id = $this->getId())) {
$search->filterById($id, Criteria::IN);
}
if (null !== ($code = $this->getCode())) {
$search->filterByCode($code, Criteria::IN);
}
if (null !== ($locale = $this->getLocale())) {
$search->filterByLocale($locale, Criteria::IN);
}
if (!$this->getBackendContext() && Type\BooleanOrBothType::ANY !== ($visible = $this->getVisible())) {
$search->filterByVisible($visible);
}
if (Type\BooleanOrBothType::ANY !== ($active = $this->getActive())) {
$search->filterByActive($active);
}
if ($this->getDefaultOnly()) {
$search->filterByByDefault(true);
}
if ($this->getExcludeDefault()) {
$search->filterByByDefault(false);
}
if (null !== ($exclude = $this->getExclude())) {
$search->filterById($exclude, Criteria::NOT_IN);
}
$orders = $this->getOrder();
foreach ($orders as $order) {
switch ($order) {
case "id":
$search->orderById(Criteria::ASC);
break;
case "id_reverse":
$search->orderById(Criteria::DESC);
break;
case "alpha":
$search->orderByTitle(Criteria::ASC);
break;
case "alpha_reverse":
$search->orderByTitle(Criteria::DESC);
break;
case "position":
$search->orderByPosition(Criteria::ASC);
break;
case "position_reverse":
$search->orderByPosition(Criteria::DESC);
break;
}
}
return $search;
}
作者:marger
项目:theli
/**
* populate a list of field for each locale for an object
*
* @param mixed $object the object to populate
* @param array $fields list of field to populate
* @param array $localeList list of locale to use populate the object
*/
protected function setI18n(&$object, $fields = array("Title"), $localeList = null)
{
if (null === $localeList) {
if (null === self::$localeList) {
self::$localeList = LangQuery::create()->select("Locale")->find()->toArray();
}
$localeList = self::$localeList;
}
foreach ($localeList as $locale) {
foreach ($fields as $name) {
$object->getTranslation($locale)->setByName($name, $locale . ' : ' . $name);
}
}
}
作者:neywe
项目:StripePaymen
public function createMailMessage()
{
// Create payment confirmation message from templates, if not already defined
if (null === MessageQuery::create()->findOneByName(self::CONFIRMATION_MESSAGE_NAME)) {
$languages = LangQuery::create()->find();
$message = new Message();
$message->setName(self::CONFIRMATION_MESSAGE_NAME)->setHtmlTemplateFileName(self::CONFIRMATION_MESSAGE_NAME . '.html')->setTextTemplateFileName(self::CONFIRMATION_MESSAGE_NAME . '.txt');
foreach ($languages as $language) {
/** @var Lang $language */
$locale = $language->getLocale();
$message->setLocale($locale)->setTitle(Translator::getInstance()->trans("Payment confirmation for Stripe Payment", [], self::MESSAGE_DOMAIN, $locale))->setSubject(Translator::getInstance()->trans('Payment confirmation of your order {$order_ref} on {$store_name}', [], self::MESSAGE_DOMAIN, $locale));
}
$message->save();
}
}
作者:Mertiozy
项目:GoogleShoppin
public function getTaxonomy($langId = null)
{
$lang = LangQuery::create()->findOneById($langId);
if ($lang === null) {
$lang = Lang::getDefaultLanguage();
}
$file = file_get_contents("http://www.google.com/basepages/producttype/taxonomy." . str_replace("_", "-", $lang->getLocale()) . ".txt");
$rows = explode("\n", $file);
$cats = [];
foreach ($rows as $row) {
$splittedCat = explode('>', $row);
$name = end($splittedCat);
$cats[$name] = htmlspecialchars($row);
}
return new JsonResponse(['cats' => $cats]);
}
作者:marger
项目:theli
public function postActivation(ConnectionInterface $con = null)
{
// create new message
if (null === MessageQuery::create()->findOneByName('mail_virtualproduct')) {
$message = new Message();
$message->setName('mail_virtualproduct')->setHtmlTemplateFileName('virtual-product-download.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('virtual-product-download.txt')->setTextLayoutFileName('')->setSecured(0);
$languages = LangQuery::create()->find();
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$message->setSubject($this->trans('Order {$order_ref} validated. Download your files.', [], $locale));
$message->setTitle($this->trans('Virtual product download message', [], $locale));
}
$message->save();
}
}
作者:fachriz
项目:theli
public function toggleDefault()
{
if ($this->getId() === null) {
throw new \RuntimeException("impossible to just uncheck default language, choose a new one");
}
$con = Propel::getWriteConnection(LangTableMap::DATABASE_NAME);
$con->beginTransaction();
try {
LangQuery::create()->filterByByDefault(1)->update(array('ByDefault' => 0), $con);
$this->setByDefault(1)->save($con);
$con->commit();
} catch (PropelException $e) {
$con->rollBack();
throw $e;
}
}
作者:roadster3
项目:TNTFranc
protected function initializeMessage()
{
// create new message
if (null === MessageQuery::create()->findOneByName('mail_tnt_france')) {
$message = new Message();
$message->setName('mail_tnt_france')->setHtmlTemplateFileName('mail-tnt-france.html')->setHtmlLayoutFileName('')->setTextTemplateFileName('mail-tnt-france.txt')->setTextLayoutFileName('')->setSecured(0);
$languages = LangQuery::create()->find();
foreach ($languages as $language) {
$locale = $language->getLocale();
$message->setLocale($locale);
$message->setSubject($this->trans('Your order {$order_ref} has been shipped.', [], $locale));
$message->setTitle($this->trans('TNT France shipping message', [], $locale));
}
$message->save();
}
}
作者:Mertiozy
项目:GoogleShoppin
public function buildModelCriteria()
{
$query = GoogleshoppingProductSynchronisationQuery::create()->filterByProductId($this->getProductId());
if ($this->getCountry()) {
$targetCountry = $this->getCountry();
} else {
$targetCountry = Country::getDefaultCountry()->getIsoalpha2();
}
if ($this->getLocale()) {
$lang = LangQuery::create()->findOneByLocale($this->getLocale())->getCode();
} else {
$lang = Lang::getDefaultLanguage()->getCode();
}
$query->filterByTargetCountry($targetCountry)->filterByLang($lang);
return $query;
}