예제 #1
0
 public function validate(ErrorElement $errorElement, $object)
 {
     //Marcó la opción que se usará en catálogo pero no ha elegido un catálog
     if ($object->getUsoEnCatalogo() == true and $object->getCatalogo() != '') {
         $errorElement->with('catalogo')->addViolation($this->getTranslator()->trans('no_catalogo_y_describir_catalogo'))->end();
     }
 }
예제 #2
0
 public function validate(ErrorElement $errorElement, $object)
 {
     //Marcó la opción que se usará en catálogo pero no ha elegido un catálog
     if ($object->getUsoEnCatalogo() == true and $object->getCatalogo() != '') {
         $errorElement->with('catalogo')->addViolation($this->getTranslator()->trans('no_catalogo_y_describir_catalogo'))->end();
     }
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\SignificadoCampo();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:SignificadoCampo', array('codigo' => $object->getCodigo()));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $gallery)
 {
     $formats = $this->pool->getFormatNamesByContext($gallery->getContext());
     if (!array_key_exists($gallery->getDefaultFormat(), $formats)) {
         $errorElement->with('defaultFormat')->addViolation('invalid format')->end();
     }
 }
예제 #4
0
 public function validate(ErrorElement $errorElement, $object)
 {
     $codigo = $object->getCodigo();
     $hashes = explode('#', $codigo);
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\Alerta();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:Alerta', array('codigo' => $codigo));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
     // validar formato #000000
     if (count($hashes) > 1) {
         // # como primer caracter y solo debe haber uno
         if (strpos($codigo, '#') != 0 || count($hashes) > 2 || strlen($codigo) != 7) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('codigo de color invalido'))->end();
         }
     }
 }
예제 #5
0
 public function validate(ErrorElement $errorElement, $object)
 {
     if ($object->getEsFusionado() == false) {
         if ($object->file == '' and $object->getArchivoNombre() == '' and $object->getSentenciaSql() == '') {
             $errorElement->with('sentenciaSql')->addViolation($this->getTranslator()->trans('validacion.sentencia_o_archivo'))->end();
         }
         if ($object->file != '' and $object->getSentenciaSql() != '') {
             $errorElement->with('sentenciaSql')->addViolation($this->getTranslator()->trans('validacion.sentencia_o_archivo_no_ambas'))->end();
         }
         if ($object->getSentenciaSql() != '' and count($object->getConexiones()) == 0) {
             $errorElement->with('conexiones')->addViolation($this->getTranslator()->trans('validacion.requerido'))->end();
         }
     }
     // Revisar la validación, no me reconoce los archivos con los tipos que debería
     /*
     * 'application/octet-stream',
      'text/comma-separated-values',
      'application/zip',
      'text/x-c++'
     */
     /* $errorElement
        ->with('file')
        ->assertFile(array(
        'mimeTypes' => array("application/vnd.ms-excel",
        "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        'text/csv','application/vnd.oasis.opendocument.spreadsheet',
        'application/vnd.ms-office'
        )))
        ->end()
        ; */
     return true;
 }
예제 #6
0
 /**
  * {@inheritdoc}
  */
 public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
 {
     if (($name = $block->getSetting('menu_name')) && $name !== "" && !$this->menuProvider->has($name)) {
         // If we specified a menu_name, check that it exists
         $errorElement->with('menu_name')->addViolation('sonata.block.menu.not_existing', array('name' => $name))->end();
     }
 }
예제 #7
0
 public function validate(ErrorElement $errorElement, $object)
 {
     $campos_no_configurados = $this->getModelManager()->findBy('IndicadoresBundle:Campo', array('origenDato' => $object->getOrigenDatos(), 'significado' => null));
     if (count($campos_no_configurados) > 0) {
         $errorElement->with('origenDatos')->addViolation($this->getTranslator()->trans('origen_no_configurado'))->end();
     }
 }
예제 #8
0
 public function validate(ErrorElement $errorElement, $object)
 {
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\Campo();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:Campo', array('nombre' => $object->getNombre()));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('nombre')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('nombre')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
     $vars_formula = array();
     $formula = str_replace(' ', '', $object->getFormula());
     preg_match_all('/(\\{[\\w]+\\})/', $formula, $vars_formula);
     //Verificar que haya utilizado solo campos existentes en el origen de datos
     foreach ($object->getOrigenDato()->getCampos() as $campo) {
         if ($campo->getSignificado() and $campo->getTipoCampo()) {
             $campos[$campo->getSignificado()->getCodigo()] = $campo->getTipoCampo()->getCodigo();
         }
     }
     //Verificar que todas las variables sean campos del origen de datos
     foreach ($vars_formula[0] as $var) {
         if (!array_key_exists(str_replace(array('{', '}'), '', $var), $campos)) {
             $errorElement->with('formula')->addViolation('<span style="color:red">' . $var . '</span> ' . $this->getTranslator()->trans('_variable_no_campo_'))->end();
             return;
         }
     }
     // ******** Verificar si matematicamente la fórmula es correcta
     // 1) Sustituir las variables por valores aleatorios entre 1 y 100
     foreach ($vars_formula[0] as $var) {
         $variable = str_replace(array('{', '}'), '', $var);
         if ($campos[$variable] == 'integer' or $campos[$variable] == 'float') {
             $formula = str_replace($var, rand(1, 100), $formula);
         } elseif ($campos[$variable] == 'date') {
             $formula = str_replace($var, ' current_date ', $formula);
         } else {
             $formula = str_replace($var, "'texto'", $formula);
         }
     }
     //evaluar la formula
     try {
         $sql = 'SELECT ' . $formula;
         $this->getConfigurationPool()->getContainer()->get('doctrine')->getEntityManager()->getConnection()->executeQuery($sql);
     } catch (\Doctrine\DBAL\DBALException $exc) {
         $errorElement->with('formula')->addViolation($this->getTranslator()->trans('sintaxis_invalida') . $exc->getMessage())->end();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $userByEmail = $this->userManager->findUserByEmail($object->getEmail());
     if ($userByEmail && $userByEmail->getId() != $object->getId()) {
         $errorElement->with('email')->addViolation('Email already exist')->end();
     }
     $userByUsername = $this->userManager->findUserByUsername($object->getUsername());
     if ($userByUsername && $userByUsername->getId() != $object->getId()) {
         $errorElement->with('username')->addViolation('Username already exist')->end();
     }
 }
예제 #10
0
 public function validate(ErrorElement $errorElement, $object)
 {
     //Verificar que todos los campos esten configurados
     foreach ($object->getVariables() as $variable) {
         $campos_no_configurados = $this->getModelManager()->findBy('IndicadoresBundle:Campo', array('origenDato' => $variable->getOrigenDatos(), 'significado' => null));
         if (count($campos_no_configurados) > 0) {
             $errorElement->with('variables')->addViolation($variable->getIniciales() . ': ' . $this->getTranslator()->trans('origen_no_configurado'))->end();
         }
     }
     //Obtener las variables marcadas
     $variables_sel = array();
     foreach ($object->getVariables() as $variable) {
         $variables_sel[] = $variable->getIniciales();
     }
     if (count($variables_sel) == 0) {
         $errorElement->with('variables')->addViolation($this->getTranslator()->trans('elija_al_menos_una_variable'))->end();
     } else {
         //Obtener las variables utilizadas en la fórmula
         //Quitar todos los espacios en blanco de la fórmula
         $vars_formula = array();
         $formula = str_replace(' ', '', $object->getFormula());
         preg_match_all('/\\{([\\w]+)\\}/', $formula, $vars_formula);
         //Para que la fórmula sea válida la cantidad de variables seleccionadas
         //debe coincidir con las utilizadas en la fórmula
         if (count(array_diff($variables_sel, $vars_formula[1])) > 0 or count(array_diff($vars_formula[1], $variables_sel)) > 0) {
             $errorElement->with('formula')->addViolation($this->getTranslator()->trans('vars_sel_diff_vars_formula'))->end();
         }
         // ******** Verificar si matematicamente la fórmula es correcta
         // 1) Sustituir las variables por valores aleatorios entre 1 y 100
         $formula_check = $formula;
         $formula_valida = true;
         $result = '';
         foreach ($vars_formula[0] as $var) {
             $formula_check = str_replace($var, rand(1, 100), $formula_check);
         }
         //Verificar que no tenga letras, para evitar un ataque de inyección
         if (preg_match('/[A-Z]+/i', $formula_check) != 0) {
             $formula_valida = false;
             $mensaje = 'sintaxis_invalida_variables_entre_llaves';
         } else {
             //evaluar la formula, evitar que se muestren los errores por si los lleva
             ob_start();
             $test = eval('$result=' . $formula_check . ';');
             ob_end_clean();
             if (!is_numeric($result)) {
                 $formula_valida = false;
                 $mensaje = 'sintaxis_invalida';
             }
         }
         if ($formula_valida == false) {
             $errorElement->with('formula')->addViolation($this->getTranslator()->trans($mensaje))->end();
         }
     }
 }
예제 #11
0
 /**
  * The validator asks each product repository to validate the related basket element
  *
  * @param BasketInterface $basket
  * @param Constraint      $constraint
  */
 public function validate($basket, Constraint $constraint)
 {
     foreach ($basket->getBasketElements() as $pos => $basketElement) {
         // create a new ErrorElement object
         $errorElement = new ErrorElement($basket, $this->constraintValidatorFactory, $this->context, $this->context->getGroup());
         $errorElement->with('basketElements[' . $pos . ']');
         // validate the basket element through the related service provider
         $this->productPool->getProvider($basketElement->getProductCode())->validateFormBasketElement($errorElement, $basketElement, $basket);
     }
     if (count($this->context->getViolations()) > 0) {
         $this->context->addViolationAt('basketElements', $constraint->message);
     }
 }
예제 #12
0
 /**
  * @param ErrorElement $errorElement
  * @param AzureRole $object
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $r = $this->getConfigurationPool()->getContainer()->get("doctrine.orm.entity_manager")->getRepository("BdEMainBundle:AzureRole");
     $q = $r->createQueryBuilder('r')->where('r.azureGid = ?1')->setParameter(1, $object->getAzureGid());
     if ($object->getId() != null) {
         $q->andWhere("r.id!=?2")->setParameter(2, $object->getId());
     }
     $ar = $q->getQuery()->getArrayResult();
     if (count($ar) > 0) {
         $errorElement->with('azureGid')->addViolation("Il existe déjà une liaison avec ce groupe")->end();
     } else {
         $object->setAzureGroupName($this->getAzureGroupChoices()[$object->getAzureGid()]);
     }
 }
예제 #13
0
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $onlyAlphanumeric = new \MINSAL\IndicadoresBundle\Validator\OnlyAlphanumeric();
     $onlyAlphanumeric->message = "OnlyAlphanumeric.Message";
     $errorElement->with('name')->addConstraint($onlyAlphanumeric)->assertLength(array('max' => 8))->end();
     // use the validator to validate the value
     $errorList = $this->getValidator()->validate($object, array('Profile'));
     for ($i = 0; $i < count($errorList); $i++) {
         if ($errorList[$i]->getMessageTemplate() == 'fos_user.group.blank') {
             $errorElement->with('name')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         } else {
             $errorElement->with('username')->addViolation($errorList[$i]->getMessage())->end();
         }
     }
 }
예제 #14
0
 /**
  * @{inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     // find object with toLink
     $fromPath = $this->modelManager->findOneBy($this->getClass(), array('fromPath' => $object->getFromPath()));
     // @formatter:off
     if (null !== $fromPath && $fromPath->getId() !== $object->getId()) {
         $errorElement->with('fromPath')->addViolation('This link is already being redirected somewhere else!')->end();
     }
     if (substr($object->getToPath(), 0, 1) !== '/') {
         $errorElement->with('toPath')->addViolation('Invalid path! A path start with a "/"')->end();
     }
     if (substr($object->getFromPath(), 0, 1) !== '/') {
         $errorElement->with('fromPath')->addViolation('Invalid path! A path start with a "/"')->end();
     }
     // @formatter:on
 }
예제 #15
0
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $onlyAlphanumeric = new \MINSAL\IndicadoresBundle\Validator\OnlyAlphanumeric();
     $onlyAlphanumeric->message = "OnlyAlphanumeric.Message";
     $validMail = new \MINSAL\IndicadoresBundle\Validator\ValidMail();
     $validMail->message = "ValidMail.Message";
     $errorElement->with('username')->addConstraint($onlyAlphanumeric)->assertLength(array('max' => 25))->end()->with('email')->addConstraint($validMail)->end();
     // use the validator to validate the value
     $errorList = $this->getValidator()->validate($object, array('Profile'));
     for ($i = 0; $i < count($errorList); $i++) {
         if ($errorList[$i]->getMessageTemplate() == 'fos_user.email.already_used') {
             $errorElement->with('email')->addViolation($errorList[$i]->getMessage())->end();
         } else {
             $errorElement->with('username')->addViolation($errorList[$i]->getMessage())->end();
         }
     }
 }
예제 #16
0
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->with('locale')->assertNotNull(array())->assertNotBlank()->end();
     $errorElement->with('translationKey')->assertNotNull(array())->assertNotBlank()->assertLength(array('max' => 255))->end();
     $errorElement->with('title')->assertNotNull(array())->assertNotBlank()->end();
     $errorElement->with('text')->assertNotNull(array())->assertNotBlank()->end();
     if (strlen(strip_tags($object->getText())) <= 5) {
         $errorElement->with('textMinLength')->addViolation($this->translator->trans('helptext.text.minlength', array(), $this->translationDomain))->end();
     }
 }
예제 #17
0
 /**
  * @param ErrorElement $errorElement
  * @param \Application\Sonata\ClientBundle\Entity\Contact $object
  */
 protected function _setupValidate(ErrorElement $errorElement, $object)
 {
     /** http://redmine.testenm.com/issues/1378  */
     $value = $object->getAffichageFactureId();
     if ($value) {
         /** @var $doctrine  \Doctrine\Bundle\DoctrineBundle\Registry */
         $doctrine = $this->getConfigurationPool()->getContainer()->get('doctrine');
         /* @var $em \Doctrine\ORM\EntityManager */
         $em = $doctrine->getManager();
         /** @var $dql \Doctrine\ORM\QueryBuilder */
         $dql = $em->createQueryBuilder()->select('count(c.id)')->from('ApplicationSonataClientBundle:Contact', 'c')->where('c.client = :client')->andWhere('c.affichage_facture_id = :affichage_facture_id')->setParameter(':client', $object->getClient())->setParameter(':affichage_facture_id', $value);
         // Edit
         if ($object->getId()) {
             $dql->andWhere('c.id != :id')->setParameter(':id', $object->getId());
         }
         $count = $dql->getQuery()->getSingleScalarResult();
         if ($count) {
             $errorElement->with('affichage_facture_id')->addViolation('Un contact a déjà ce N° ordre facturation')->end();
         }
     }
 }
 public function validate(ErrorElement $errorElement, $object)
 {
     $piecesURL = explode("/", $_SERVER['REQUEST_URI']);
     $pieceAction = $piecesURL[count($piecesURL) - 1];
     // create or update
     $pieceId = $piecesURL[count($piecesURL) - 2];
     // id/edit
     $obj = new \MINSAL\IndicadoresBundle\Entity\ClasificacionNivel();
     $rowsRD = $this->getModelManager()->findBy('IndicadoresBundle:ClasificacionNivel', array('codigo' => $object->getCodigo()));
     if (strpos($pieceAction, 'create') !== false) {
         if (count($rowsRD) > 0) {
             $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
         }
     } else {
         if (count($rowsRD) > 0) {
             $obj = $rowsRD[0];
             if ($obj->getId() != $pieceId) {
                 $errorElement->with('codigo')->addViolation($this->getTranslator()->trans('registro existente, no se puede duplicar'))->end();
             }
         }
     }
 }
 public function validate(ErrorElement $errorElement, $object)
 {
     if (count($object->getLinks()) == 0) {
         $errorElement->with('links')->addViolation('Please select atleast one link')->end();
     } else {
         $enabled = 0;
         foreach ($object->getLinks() as $key => $val) {
             if (is_null($val->getMedia()) && $val->getDeleteFooter() == false) {
                 $errorElement->with('links')->addViolation('Please select image from media or click "Delete Link" checkbox to remove specific entry')->end();
             }
             if (is_null($val->getMediaHover()) && $val->getDeleteFooter() == false) {
                 $errorElement->with('links')->addViolation('Please select image from hver media or click "Delete Link" checkbox to remove specific entry')->end();
             }
             if ($val->getEnabled() && $val->getDeleteFooter() == false) {
                 $enabled++;
             }
         }
         if ($enabled > 2) {
             $errorElement->with('links')->addViolation('Maximum 2 links can be enabled at a time')->end();
         }
     }
 }
예제 #20
0
 public function validate(ErrorElement $errorElement, $camino)
 {
     $posta = $camino->getPrimerPosta();
     $subgrupos = new ArrayCollection();
     $piezas = new ArrayCollection();
     while ($posta != null) {
         $subgrupo = $posta->getSubgrupo();
         $pieza = $posta->getPoi()->getPiezaARecolectar();
         if ($subgrupos->contains($subgrupo)) {
             $posta = null;
             $errorElement->with('subgrupo')->addViolation('No pueden existir dos postas con el mismo subgrupo.')->end();
         } else {
             $posta = $posta->getPostaSiguiente();
             $subgrupos->add($subgrupo);
         }
         if ($piezas->contains($pieza)) {
             $posta = null;
             $errorElement->with('subgrupo')->addViolation('No pueden existir dos postas con la misma pieza a recolectar.')->end();
         } else {
             $piezas->add($pieza);
         }
     }
 }
예제 #21
0
 /**
  * {@inheritdoc}
  */
 public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
 {
     $errorElement->with('settings[url]')->assertNotNull(array())->assertNotBlank()->end()->with('settings[title]')->assertNotNull(array())->assertNotBlank()->assertMaxLength(array('limit' => 50))->end();
 }
예제 #22
0
 /**
  * Validator function
  *
  * This function validates that title of the media is no longer
  * than 255 characters long.
  *
  * @param ErrorElement $errorElement
  * @param type $object
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->with('title')->assertMaxLength(array('limit' => 255))->end();
 }
예제 #23
0
 /**
  * Validator function
  *
  * This function validates that the maximum amount of characters given for a
  * is 50 characters long.
  *
  * @param ErrorElement $errorElement
  * @param mixed        $object
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->with('name')->assertLength(array('max' => 50))->end();
 }
예제 #24
0
 /**
  * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
  * @param $object
  * @return void
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->with('name')->assertNotNull()->assertNotBlank()->assertMaxLength(array('limit' => 25))->end();
 }
예제 #25
0
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->with('pageTitle')->assertMaxLength(array('limit' => 100))->end()->with('url')->assertMaxLength(array('limit' => 100))->end();
 }
예제 #26
0
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, MediaInterface $media)
 {
     if (!$media->getBinaryContent() instanceof \SplFileInfo) {
         return;
     }
     if ($media->getBinaryContent() instanceof UploadedFile) {
         $fileName = $media->getBinaryContent()->getClientOriginalName();
     } elseif ($media->getBinaryContent() instanceof File) {
         $fileName = $media->getBinaryContent()->getFilename();
     } else {
         throw new \RuntimeException(sprintf('Invalid binary content type: %s', get_class($media->getBinaryContent())));
     }
     if (!in_array(strtolower(pathinfo($fileName, PATHINFO_EXTENSION)), $this->allowedExtensions)) {
         $errorElement->with('binaryContent')->addViolation('Invalid extensions')->end();
     }
     if (!in_array($media->getBinaryContent()->getMimeType(), $this->allowedMimeTypes)) {
         $errorElement->with('binaryContent')->addViolation('Invalid mime type : ' . $media->getBinaryContent()->getMimeType())->end();
     }
 }
예제 #27
0
 /**
  * @param \Sonata\AdminBundle\Validator\ErrorElement $errorElement
  * @param $object
  * @return void
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     if (!$object->getUrl()) {
         $this->cmsManager->getPageManager()->fixUrl($object);
     }
     $page = $this->cmsManager->getPageManager()->getPageByUrl($object->getUrl());
     if (!$page) {
         $page = $this->cmsManager->getPageManager()->getPageByUrl(substr($object->getUrl(), -1) == '/' ? substr($object->getUrl(), 0, -1) : $object->getUrl() . '/');
     }
     if ($page && $page->getId() != $object->getId()) {
         $errorElement->addViolation($this->trans('error.uniq_url', array('%url%' => $object->getUrl())));
     }
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->assertCallback(array('validateOneMainCategory'));
 }
예제 #29
0
 public function validate(ErrorElement $errorElement, $object)
 {
     $errorElement->with('artworkname')->assertMaxLength(array('limit' => 32))->end();
 }
예제 #30
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();
 }