Ticket #193: siwapp.193.diff

File siwapp.193.diff, 4.6 KB (added by jzarate, 3 years ago)

diff del ticket

  • apps/siwapp/modules/recurring/templates/editSuccess.php

     
    4949        <li> 
    5050          <span> 
    5151            <span class="_75 _last"> 
    52               <?php echo $invoiceForm['enabled']->renderLabel()?><?php echo $invoiceForm['enabled']?> 
     52              <?php echo $invoiceForm['enabled']->renderLabel()?> 
     53              <?php echo $invoiceForm['enabled']?> 
     54              <?php echo $invoiceForm['enabled']->renderError()?> 
    5355              &nbsp;&nbsp; 
    5456              <?php echo $invoiceForm['max_occurrences']->renderLabel()?> 
    5557              <?php echo $invoiceForm['max_occurrences']->render(array('class'=>'short'))?> 
  • lib/form/RecurringInvoiceForm.class.php

     
    9797    // validators 
    9898    $this->validatorSchema['tags']    = new sfValidatorString(array('required'=>false)); 
    9999    $this->validatorSchema['customer_email'] = new sfValidatorEmail(array('max_length' => 100, 'required' => false)); 
     100    $this->validatorSchema->setPostValidator(new sfValidatorSchemaAndOr(array('draft'=>new sfValidatorBoolean(),'enabled'=>new sfValidatorBoolean()))); 
    100101 
    101  
    102102    $this->addContainerForm('invoiceItems','RecurringInvoiceItemForm',array('key'=>'id','object'=>$o->getRecurringInvoiceItems())); 
    103103     
    104104    $this->widgetSchema->setNameFormat("invoice[%s]"); 
  • lib/validator/sfValidatorSchemaAndOr.class.php

     
     1<?php 
     2  /** 
     3   * sfValidatorSchemaAndOr validates if all validators (each one associated 
     4   * with different fields) passes, or any of them (it depends on the logic 
     5   * specified in the options). 
     6   *  
     7   * @author JoeZ <jzarate@gmail.com> 
     8   * @version SVN: $Id$ 
     9   */ 
     10class sfValidatorSchemaAndOr extends sfValidatorSchema 
     11{ 
     12  const LOGIC_AND     = 'AND'; 
     13  const LOGIC_OR      = 'OR'; 
     14 
     15  protected 
     16    $field_validator_array = array(); 
     17 
     18  /** 
     19   * Constructor. 
     20   * 
     21   * The first argument can be: 
     22   * 
     23   *  * null 
     24   *  * an associative array  
     25   *    with field names as keys and sfValidatorBase instances as values 
     26   * 
     27   * @param mixed $validators Initial field=>validator array 
     28   * @param array $options    An array of options 
     29   * @param array $messages   An array of error messages 
     30   * 
     31   */ 
     32  public function __construct($field_validator_array = null,$options = array(), $messages = array()) 
     33  { 
     34    if(is_array($field_validator_array)) 
     35    { 
     36      foreach($field_validator_array as $field => $validator) 
     37      { 
     38        $this->field_validator_array[$field] = $validator; 
     39      } 
     40    } 
     41    else if(!is_null($field_validator_array)) 
     42    { 
     43      throw new InvalidArgumentException('sfValidatorSchemaAndOr constructor takes a field=>sfValidatorBase array.'); 
     44    } 
     45    parent::__construct($options,$messages); 
     46  } 
     47 
     48  /**  
     49   * Configures the current validator. 
     50   * 
     51   * Available options: 
     52   * 
     53   *  * logic: Logic to use "AND" , "OR" 
     54   * 
     55   * @param array $options  An array of optiones 
     56   * @param array $messages An array of error messages 
     57   * 
     58   */ 
     59  protected function configure($options = array(),$messages = array()) 
     60  { 
     61    $this->addOption('logic_to_use',sfValidatorSchemaAndOr::LOGIC_AND); 
     62    $this->addMessage('enabled', 'ennnnabbb'); 
     63    $this->setMessage('enabled','sisisisisisi'); 
     64  } 
     65 
     66  protected function doClean($values) 
     67  { 
     68    $clean = array(); 
     69    $valid = true; 
     70    $errors = array(); 
     71    foreach($this->field_validator_array as $field => $validator) 
     72    { 
     73      try 
     74      { 
     75        $clean[$values[$field]] = $validator->clean($values[$field]); 
     76      } 
     77      catch(sfValidatorError $e) 
     78      { 
     79        $errors[$field] = $e; 
     80        throw $e; 
     81      } 
     82    } 
     83    throw new sfValidatorError($this,'invalid'); 
     84    if( (count($errors) && $this->getOption('logic_to_use') == sfValidatorSchemaAndOr::LOGIC_AND) || 
     85        (count($errors) == count($this->field_validator_array) && $this->getOption('logic_to_use') == sfValidatorSchemaAndOr::LOGIC_OR)) 
     86    { 
     87      throw new sfValidatorErrorSchema($this,array_values($errors)); 
     88    } 
     89    return $values; 
     90  } 
     91 
     92} 
     93 No newline at end of file