public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->addConstraint(new UniqueObject(array('fields' => 'alias', 'message' => $this->trans('fc.label.admin.alias', array(), $this->getTranslationDomain()) . ': ' . $this->trans('fc.constraint.admin.not_unique', array(), 'validators'))));
     /** @var FcForm $object */
     if ($this->field_chain->hasField($object->getAlias())) {
         $errorElement->addViolation($this->trans('fc.message.admin.form.alias_conflicts', array(), $this->getTranslationDomain()));
     }
     if ($object->isColumnModified(FcFormPeer::IS_WIDGET) && !$object->getIsWidget() && $object->isUsedAsWidget()) {
         $errorElement->addViolation($this->trans('fc.message.admin.form.is_used_as_widget', array(), $this->getTranslationDomain()));
     }
 }
 public function validate(ErrorElement $errorElement, $object)
 {
     $nip = $object->getInvoiceNip();
     if (!NipType::isValid($nip)) {
         $msg = sprintf('Wartość "%s" nie jest poprawnym numerem NIP.', $nip);
         $errorElement->addViolation($msg);
     }
 }
Beispiel #3
0
 public function validate(ErrorElement $errorElement, $object)
 {
     $translator = $this->getConfigurationPool()->getContainer()->get('translator');
     /**
      * @var UploadedFile $file
      * @var Ad $object
      */
     $file = $object->getUploadedFile();
     if (!$file instanceof UploadedFile and $object->getPath() === null) {
         $errorElement->addViolation($translator->trans('errors.no_image_file', array(), 'SiciarekAdRotator'));
     }
     if ($file instanceof UploadedFile) {
         $def = $object->getType()->getDefinition();
         $extensions = explode(';', $def['formats']);
         $width = $def['width'];
         $height = $def['height'];
         $ext = $file->getClientOriginalExtension();
         // Check file extension:
         if (!in_array($ext, $extensions)) {
             $msg = $translator->trans('errors.invalid_file_format', array('EXTS' => implode(', ', $extensions), 'EXT' => $ext), 'SiciarekAdRotator');
             $errorElement->addViolation($msg);
             return;
         }
         $bin = $file->getRealPath();
         $imageinfo = getimagesize($bin);
         if ($ext === 'svg') {
             // @ - Suppress warning about invalid file content:
             @($xml = simplexml_load_file($bin));
             if ($xml instanceof \SimpleXMLElement) {
                 $width = intval($xml->attributes()->width);
                 $height = intval($xml->attributes()->height);
                 $imageinfo = array($width, $height, IMAGETYPE_UNKNOWN, sprintf('width="%d" height="%d"', $width, $height), 'mime' => 'image/svg+xml');
             } else {
                 $imageinfo = false;
             }
         }
         if (!is_array($imageinfo)) {
             $msg = $translator->trans('errors.invalid_file_content', array(), 'SiciarekAdRotator');
             $msg = sprintf($msg);
             $errorElement->addViolation($msg);
             return;
         }
         $expected = array($width, $height);
         $given = array($imageinfo[0], $imageinfo[1]);
         // Check image width and height:
         if ($expected !== $given) {
             $msg = $translator->trans('errors.invalid_image_size', array('WIDTH' => $width, 'HEIGHT' => $height, 'XWIDTH' => $imageinfo[0], 'XHEIGHT' => $imageinfo[1]), 'SiciarekAdRotator');
             $errorElement->addViolation($msg);
         }
     }
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function validateFormBasketElement(ErrorElement $errorElement, BasketElementInterface $basketElement, BasketInterface $basket)
 {
     // the item is flagged as deleted, no need to validate the item
     if ($basketElement->getDelete() || 0 === $basketElement->getQuantity()) {
         return;
     }
     // refresh the product from the database
     $product = $basketElement->getProduct();
     // check if the product is still in database
     if (!$product) {
         $errorElement->addViolation('product_not_available');
         return;
     }
     // check if the product is still enabled
     if (!$basketElement->getProduct()->getEnabled()) {
         $errorElement->addViolation('product_not_enabled');
         return;
     }
     // check if the quantity is numeric
     if (!is_numeric($basketElement->getQuantity())) {
         $errorElement->with('quantity')->addViolation('product_quantity_not_numeric')->end();
         return;
     }
     $errorElement->with('quantity')->assertRange(array('min' => 1, 'max' => $this->getStockAvailable($basketElement->getProduct()), 'minMessage' => 'basket_quantity_limit_min', 'maxMessage' => 'basket_quantity_limit_max'))->end();
 }