Exemplo n.º 1
0
 function validate()
 {
     parent::validate();
     if ($this->_errors) {
         return FALSE;
     }
     $this->cart->load_associations();
     $fields = $this->_submitValues;
     foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
         $price_set_id = CRM_Event_BAO_Event::usesPriceSet($event_in_cart->event_id);
         if ($price_set_id) {
             $priceField = new CRM_Price_DAO_PriceField();
             $priceField->price_set_id = $price_set_id;
             $priceField->find();
             $check = array();
             while ($priceField->fetch()) {
                 if (!empty($fields["event_{$event_in_cart->event_id}_price_{$priceField->id}"])) {
                     $check[] = $priceField->id;
                 }
             }
             //XXX
             if (empty($check)) {
                 $this->_errors['_qf_default'] = ts("Select at least one option from Price Levels.");
             }
             $lineItem = array();
             if (is_array($this->_values['fee']['fields'])) {
                 CRM_Price_BAO_PriceSet::processAmount($this->_values['fee']['fields'], $fields, $lineItem);
                 //XXX total...
                 if ($fields['amount'] < 0) {
                     $this->_errors['_qf_default'] = ts("Price Levels can not be less than zero. Please select the options accordingly");
                 }
             }
         }
         foreach ($event_in_cart->participants as $mer_participant) {
             $participant_fields = $fields['event'][$event_in_cart->event_id]['participant'][$mer_participant->id];
             //TODO what to do when profile responses differ for the same contact?
             $contact_id = self::find_contact($participant_fields);
             if ($contact_id) {
                 $participant = new CRM_Event_BAO_Participant();
                 $participant->event_id = $event_in_cart->event_id;
                 $participant->contact_id = $contact_id;
                 $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
                 $participant->find();
                 while ($participant->fetch()) {
                     if (array_key_exists($participant->status_id, $statusTypes)) {
                         $form = $mer_participant->get_form();
                         $this->_errors[$form->html_field_name('email')] = ts("The participant %1 is already registered for %2 (%3).", array(1 => $participant_fields['email'], 2 => $event_in_cart->event->title, 3 => $event_in_cart->event->start_date));
                     }
                 }
             }
         }
     }
     return empty($this->_errors);
 }
Exemplo n.º 2
0
 /**
  * @return bool
  */
 public function validate()
 {
     if ($this->is_pay_later) {
         $this->_fields['credit_card_number']['is_required'] = FALSE;
         $this->_fields['cvv2']['is_required'] = FALSE;
         $this->_fields['credit_card_exp_date']['is_required'] = FALSE;
         $this->_fields['credit_card_type']['is_required'] = FALSE;
     }
     return parent::validate();
 }