php Sonata-AdminBundle-Validator-ErrorElement类(方法)实例源码

下面列出了php Sonata-AdminBundle-Validator-ErrorElement 类(方法)源码代码实例,从而了解它的用法。

作者:rajotic    项目:SII   
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();
     }
 }

作者:SM201    项目:Etab-hibrid   
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();
             }
         }
     }
 }

作者:novate    项目:SonataMediaBundl   
/**
  * {@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();
     }
 }

作者:SM201    项目:Etab-hibrid   
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();
         }
     }
 }

作者:SM201    项目:Etab-hibrid   
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;
 }

作者:LamaDelRa    项目:test_sym   
/**
  * {@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();
     }
 }

作者:SM201    项目:Etab-hibrid   
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();
     }
 }

作者:SM201    项目:Etab-hibrid   
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();
     }
 }

作者:TeodorSolvi    项目:EntitySerializationExampl   
/**
  * {@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();
     }
 }

作者:SM201    项目:Etab-hibrid   
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();
         }
     }
 }

作者:Dicodin    项目:ecommerc   
/**
  * 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);
     }
 }

作者:PhilippeGee    项目:adhesio   
/**
  * @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()]);
     }
 }

作者:SM201    项目:Etab-hibrid   
/**
  * {@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();
         }
     }
 }

作者:Neodor    项目:SonataRedirectBundl   
/**
  * @{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
 }

作者:SM201    项目:Etab-hibrid   
/**
  * {@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();
         }
     }
 }

作者:rapeme    项目:init-cms-bundl   
/**
  * {@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();
     }
 }

作者:defan-maruncha    项目:eurota   
/**
  * @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();
         }
     }
 }

作者:SM201    项目:Etab-hibrid   
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();
             }
         }
     }
 }

作者:realburne    项目:Sonata-media-upload-multiple-image   
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();
         }
     }
 }

作者:alexhuma    项目:jc-tesis-servido   
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);
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号