Exemplo n.º 1
0
 protected function trans($id, $parameters = [], $locale = null)
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, self::MESSAGE_DOMAIN, $locale);
 }
Exemplo n.º 2
0
 protected function trans($id, $locale, $parameters = [])
 {
     if ($this->translator === null) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, self::MODULE_DOMAIN, $locale);
 }
Exemplo n.º 3
0
 public function checkOrders(array $values)
 {
     foreach ($this->getOrder() as $order) {
         if (!array_key_exists($order, $values)) {
             throw new \ErrorException($this->translator->trans("The column %column that you want to sort doesn't exist", ["%column" => $order]));
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Process the count function: executes a loop and return the number of items found
  *
  * @param array $params parameters array
  * @param \Smarty_Internal_Template $template
  *
  * @return int                       the item count
  * @throws \InvalidArgumentException if a parameter is missing
  *
  */
 public function hasFlashMessage($params, $template)
 {
     $type = $this->getParam($params, 'type', null);
     if (null == $type) {
         throw new \InvalidArgumentException($this->translator->trans("Missing 'type' parameter in {hasflash} function arguments"));
     }
     return $this->getSession()->getFlashBag()->has($type);
 }
Exemplo n.º 5
0
 public function registerValidatorTranslator(GetResponseEvent $event)
 {
     /** @var \Thelia\Core\HttpFoundation\Request $request */
     $request = $event->getRequest();
     $lang = $request->getSession()->getLang();
     $vendorFormDir = THELIA_VENDOR . 'symfony' . DS . 'form' . DS . 'Symfony' . DS . 'Component' . DS . 'Form';
     $vendorValidatorDir = THELIA_VENDOR . 'symfony' . DS . 'validator' . DS . 'Symfony' . DS . 'Component' . DS . 'Validator';
     $this->translator->addResource('xlf', sprintf($vendorFormDir . DS . 'Resources' . DS . 'translations' . DS . 'validators.%s.xlf', $lang->getCode()), $lang->getLocale(), 'validators');
     $this->translator->addResource('xlf', sprintf($vendorValidatorDir . DS . 'Resources' . DS . 'translations' . DS . 'validators.%s.xlf', $lang->getCode()), $lang->getLocale(), 'validators');
 }
Exemplo n.º 6
0
 protected function getHookChoices()
 {
     $choices = array();
     $hooks = HookQuery::create()->filterByActivate(true, Criteria::EQUAL)->joinWithI18n($this->translator->getLocale())->orderBy('HookI18n.title', Criteria::ASC)->find();
     /** @var Hook $hook */
     foreach ($hooks as $hook) {
         $choices[$hook->getId()] = $hook->getTitle() . ' (code ' . $hook->getCode() . ')';
     }
     return $choices;
 }
Exemplo n.º 7
0
 /**
  * Get operator translation
  *
  * @param Translator $translator Provide necessary value from Thelia
  * @param string     $operator   Operator const
  *
  * @return string
  */
 public static function getI18n(Translator $translator, $operator)
 {
     $ret = $operator;
     switch ($operator) {
         case self::INFERIOR:
             $ret = $translator->trans('Less than', []);
             break;
         case self::INFERIOR_OR_EQUAL:
             $ret = $translator->trans('Less than or equals', []);
             break;
         case self::EQUAL:
             $ret = $translator->trans('Equal to', []);
             break;
         case self::SUPERIOR_OR_EQUAL:
             $ret = $translator->trans('Greater than or equals', []);
             break;
         case self::SUPERIOR:
             $ret = $translator->trans('Greater than', []);
             break;
         case self::DIFFERENT:
             $ret = $translator->trans('Not equal to', []);
             break;
         case self::IN:
             $ret = $translator->trans('In', []);
             break;
         case self::OUT:
             $ret = $translator->trans('Not in', []);
             break;
         default:
     }
     return $ret;
 }
Exemplo n.º 8
0
 protected function checkMandatoryColumns(array $row)
 {
     $mandatoryColumns = $this->getMandatoryColumns();
     sort($mandatoryColumns);
     $diff = [];
     foreach ($mandatoryColumns as $name) {
         if (!isset($row[$name]) || empty($row[$name])) {
             $diff[] = $name;
         }
     }
     if (!empty($diff)) {
         throw new \UnexpectedValueException($this->translator->trans("The following columns are missing: %columns", ["%columns" => implode(", ", $diff)]));
     }
 }
Exemplo n.º 9
0
 /**
  * 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]));
     }
 }
Exemplo n.º 10
0
 public function verifyCountry($value, ExecutionContextInterface $context)
 {
     $address = CountryQuery::create()->findPk($value);
     if (null === $address) {
         $context->addViolation(Translator::getInstance()->trans("Country ID not found"));
     }
 }
Exemplo n.º 11
0
 public function verifyExistingCode($value, ExecutionContextInterface $context)
 {
     $coupon = CouponQuery::create()->findOneByCode($value);
     if (null === $coupon) {
         $context->addViolation(Translator::getInstance()->trans("This coupon does not exists"));
     }
 }
Exemplo n.º 12
0
 public function verifyProfileId($value, ExecutionContextInterface $context)
 {
     $profile = ProfileQuery::create()->findPk($value);
     if (null === $profile) {
         $context->addViolation(Translator::getInstance()->trans("Profile ID not found"));
     }
 }
Exemplo n.º 13
0
 protected function checkInterface()
 {
     /* Must implement either :
      *  - PropelSearchLoopInterface
      *  - ArraySearchLoopInterface
      */
     $searchInterface = false;
     if ($this instanceof PropelSearchLoopInterface) {
         if (true === $searchInterface) {
             throw new LoopException($this->translator->trans('Loop cannot implements multiple Search Interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`'), LoopException::MULTIPLE_SEARCH_INTERFACE);
         }
         $searchInterface = true;
     }
     if ($this instanceof ArraySearchLoopInterface) {
         if (true === $searchInterface) {
             throw new LoopException($this->translator->trans('Loop cannot implements multiple Search Interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`'), LoopException::MULTIPLE_SEARCH_INTERFACE);
         }
         $searchInterface = true;
     }
     if (false === $searchInterface) {
         throw new LoopException($this->translator->trans('Loop must implements one of the following interfaces : `PropelSearchLoopInterface`, `ArraySearchLoopInterface`'), LoopException::SEARCH_INTERFACE_NOT_FOUND);
     }
     /* Only PropelSearch allows timestamp and version */
     if (!$this instanceof PropelSearchLoopInterface) {
         if (true === $this->timestampable) {
             throw new LoopException($this->translator->trans("Loop must implements 'PropelSearchLoopInterface' to be timestampable"), LoopException::NOT_TIMESTAMPED);
         }
         if (true === $this->versionable) {
             throw new LoopException($this->translator->trans("Loop must implements 'PropelSearchLoopInterface' to be versionable"), LoopException::NOT_VERSIONED);
         }
     }
 }
Exemplo n.º 14
0
 public function verifyTaxList($value, ExecutionContextInterface $context)
 {
     $jsonType = new JsonType();
     if (!$jsonType->isValid($value)) {
         $context->addViolation(Translator::getInstance()->trans("Tax list is not valid JSON"));
     }
     $taxList = json_decode($value, true);
     /* check we have 2 level max */
     foreach ($taxList as $taxLevel1) {
         if (is_array($taxLevel1)) {
             foreach ($taxLevel1 as $taxLevel2) {
                 if (is_array($taxLevel2)) {
                     $context->addViolation(Translator::getInstance()->trans("Bad tax list JSON"));
                 } else {
                     $taxModel = TaxQuery::create()->findPk($taxLevel2);
                     if (null === $taxModel) {
                         $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
                     }
                 }
             }
         } else {
             $taxModel = TaxQuery::create()->findPk($taxLevel1);
             if (null === $taxModel) {
                 $context->addViolation(Translator::getInstance()->trans("Tax ID not found in tax list JSON"));
             }
         }
     }
 }
Exemplo n.º 15
0
 /**
  * @inherited
  */
 protected function buildForm()
 {
     $translator = Translator::getInstance();
     BaseProductCreationForm::buildForm();
     $this->formBuilder->add("brand_id", "integer", ['required' => true, 'label' => $translator->trans('Brand / Supplier'), 'label_attr' => ['for' => 'mode', 'help' => $translator->trans("Select the product brand, or supplier.")]]);
     $this->addStandardDescFields(array('title', 'locale'));
 }
Exemplo n.º 16
0
 public function checkCityName($value, ExecutionContextInterface $context)
 {
     $isValid = InseeGeoMunicipalityQuery::create()->findOneById($value);
     if (!isset($isValid)) {
         $context->addViolation(Translator::getInstance()->trans('city.error', [], INSEEGeo::DOMAIN_NAME));
     }
 }
 public function checkAtLeastOnePhoneNumberIsDefined($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if (empty($data["phone"]) && empty($data["cellphone"])) {
         $context->addViolationAt("phone", Translator::getInstance()->trans("Please enter a home or mobile phone number"));
     }
 }
 public function verifyPasswordField($value, ExecutionContextInterface $context)
 {
     $data = $context->getRoot()->getData();
     if ($data["password"] != $data["password_confirm"]) {
         $context->addViolation(Translator::getInstance()->trans("password confirmation is not the same as password field"));
     }
 }
Exemplo n.º 19
0
 public function checkDuplicateRef($value, ExecutionContextInterface $context)
 {
     $count = ProductQuery::create()->filterByRef($value)->count();
     if ($count > 0) {
         $context->addViolation(Translator::getInstance()->trans("A product with reference %ref already exists. Please choose another reference.", array('%ref' => $value)));
     }
 }
Exemplo n.º 20
0
 /**
  * Process url generator function
  *
  * @param  array   $params
  * @param  \Smarty $smarty
  * @return string  no text is returned.
  */
 public function generateUrlFunction($params, &$smarty)
 {
     // the path to process
     $current = $this->getParam($params, 'current', false);
     $path = $this->getParam($params, 'path', null);
     $file = $this->getParam($params, 'file', null);
     // Do not invoke index.php in URL (get a static file in web space
     if ($current) {
         $path = $this->request->getPathInfo();
         unset($params["current"]);
         // Delete the current param, so it isn't included in the url
         // Then build the query variables
         $params = array_merge($this->request->query->all(), $params);
     }
     if ($file !== null) {
         $path = $file;
         $mode = URL::PATH_TO_FILE;
     } elseif ($path !== null) {
         $mode = URL::WITH_INDEX_PAGE;
     } else {
         throw new \InvalidArgumentException(Translator::getInstance()->trans("Please specify either 'path' or 'file' parameter in {url} function."));
     }
     $excludeParams = $this->resolvePath($params, $path, $smarty);
     $url = URL::getInstance()->absoluteUrl($path, $this->getArgsFromParam($params, array_merge(['noamp', 'path', 'file', 'target'], $excludeParams)), $mode);
     $this->applyNoAmpAndTarget($params, $url);
     return $url;
 }
Exemplo n.º 21
0
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = NewsletterQuery::create()->filterByUnsubscribed(false)->findOneByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("You are already registered!"));
     }
 }
Exemplo n.º 22
0
 /**
  * @inheritdoc
  */
 protected function buildForm()
 {
     $translator = Translator::getInstance();
     $this->formBuilder->add('file', 'file', ['required' => false, 'constraints' => [new Image([])], 'label' => $translator->trans('Replace current image by this file'), 'label_attr' => ['for' => 'file']])->add('visible', 'checkbox', ['constraints' => [], 'required' => false, 'label' => $translator->trans('This image is online'), 'label_attr' => ['for' => 'visible_create']]);
     // Add standard description fields
     $this->addStandardDescFields();
 }
Exemplo n.º 23
0
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::getCustomerByEmail($value);
     if ($customer) {
         $context->addViolation(Translator::getInstance()->trans("This email already exists."));
     }
 }
Exemplo n.º 24
0
 public function checkDuplicateCode($value, ExecutionContextInterface $context)
 {
     $currency = CurrencyQuery::create()->findOneByCode($value);
     if ($currency) {
         $context->addViolation(Translator::getInstance()->trans('A currency with code "%name" already exists.', ['%name' => $value]));
     }
 }
Exemplo n.º 25
0
 protected function trans($id, $parameters = [])
 {
     if (null === $this->translator) {
         $this->translator = Translator::getInstance();
     }
     return $this->translator->trans($id, $parameters, $this->domain);
 }
Exemplo n.º 26
0
 protected function buildForm()
 {
     parent::buildForm(true);
     $this->formBuilder->add("id", "hidden", array("constraints" => array(new GreaterThan(array('value' => 0)))))->add("by_module", "checkbox", array("label" => Translator::getInstance()->trans("By Module"), "label_attr" => array("for" => "by_module")))->add("block", "checkbox", array("label" => Translator::getInstance()->trans("Hook block"), "label_attr" => array("for" => "block")));
     // Add standard description fields, excluding title and locale, which a re defined in parent class
     $this->addStandardDescFields(array('title', 'postscriptum', 'locale'));
 }
Exemplo n.º 27
0
 public function verifyExistingEmail($value, ExecutionContextInterface $context)
 {
     $customer = CustomerQuery::create()->findOneByEmail($value);
     if (null === $customer) {
         $context->addViolation(Translator::getInstance()->trans("This email does not exists"));
     }
 }
Exemplo n.º 28
0
 /**
  * @param $areaId
  * @param $weight
  *
  * @return mixed
  * @throws \Thelia\Exception\OrderException
  */
 public static function getPostageAmount($areaId, $weight)
 {
     $freeshipping = ColissimoFreeshippingQuery::create()->getLast();
     $postage = 0;
     if (!$freeshipping) {
         $prices = self::getPrices();
         /* check if Colissimo delivers the asked area */
         if (!isset($prices[$areaId]) || !isset($prices[$areaId]["slices"])) {
             throw new DeliveryException(Translator::getInstance()->trans("Colissimo delivery unavailable for the delivery country", [], self::MESSAGE_DOMAIN));
         }
         $areaPrices = $prices[$areaId]["slices"];
         ksort($areaPrices);
         /* Check cart weight is below the maximum weight */
         end($areaPrices);
         $maxWeight = key($areaPrices);
         if ($weight > $maxWeight) {
             throw new DeliveryException(Translator::getInstance()->trans("Colissimo delivery unavailable for this cart weight (%weight kg)", array("%weight" => $weight), self::MESSAGE_DOMAIN));
         }
         $postage = current($areaPrices);
         while (prev($areaPrices)) {
             if ($weight > key($areaPrices)) {
                 break;
             }
             $postage = current($areaPrices);
         }
     }
     return $postage;
 }
Exemplo n.º 29
0
 public function checkDuplicateName($value, ExecutionContextInterface $context)
 {
     $config = ConfigQuery::create()->findOneByName($value);
     if ($config) {
         $context->addViolation(Translator::getInstance()->trans('A variable with name "%name" already exists.', array('%name' => $value)));
     }
 }
Exemplo n.º 30
0
 public function __construct(Request $request, $type = "form", $data = array(), $options = array())
 {
     $this->request = $request;
     $validator = Validation::createValidatorBuilder();
     if (!isset($options["attr"]["name"])) {
         $options["attr"]["thelia_name"] = $this->getName();
     }
     $builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension());
     if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) {
         $builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__)))));
     }
     $translator = Translator::getInstance();
     $validator->setTranslationDomain('validators')->setTranslator($translator);
     $this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options));
     $this->buildForm();
     // If not already set, define the success_url field
     // This field is not included in the standard form hidden fields
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('success_url')) {
         $this->formBuilder->add("success_url", "hidden");
     }
     // The "error_message" field defines the error message displayed if
     // the form could not be validated. If it is empty, a standard error message is displayed instead.
     // This field is not included in the hidden fields generated by form_hidden_fields Smarty function
     if (!$this->formBuilder->has('error_message')) {
         $this->formBuilder->add("error_message", "hidden");
     }
     $this->form = $this->formBuilder->getForm();
 }