Ejemplo n.º 1
0
 function add_participant_to_cart()
 {
     require 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $cart_id = $_GET['cart_id'];
     $event_id = $_GET['event_id'];
     $cart = CRM_Event_Cart_BAO_Cart::find_by_id($_GET['cart_id']);
     $params_array = array('cart_id' => $cart->id, 'contact_id' => CRM_Event_Cart_Form_Cart::find_or_create_contact(), 'event_id' => $event_id);
     //XXX security?
     $participant = CRM_Event_Cart_BAO_MerParticipant::create($params_array);
     $participant->save();
     $form = new CRM_Core_Form();
     $pform = new CRM_Event_Cart_Form_MerParticipant($participant);
     $pform->appendQuickForm($form);
     $renderer = $form->getRenderer();
     $config = CRM_Core_Config::singleton();
     $templateDir = $config->templateDir;
     if (is_array($templateDir)) {
         $templateDir = array_pop($templateDir);
     }
     $requiredTemplate = file_get_contents($templateDir . '/CRM/Form/label.tpl');
     $renderer->setRequiredTemplate($requiredTemplate);
     $form->accept($renderer);
     $template = CRM_Core_Smarty::singleton();
     $template->assign('form', $renderer->toArray());
     $template->assign('participant', $participant);
     $output = $template->fetch("CRM/Event/Cart/Form/Checkout/Participant.tpl");
     $transaction->commit();
     echo $output;
     CRM_Utils_System::civiExit();
 }
    function preProcess()
    {
        parent::preProcess();
        $matches = array();
        preg_match("/.*_(\\d+)_(\\d+)/", $this->getAttribute('name'), $matches);
        $event_id = $matches[1];
        $participant_id = $matches[2];
        $event_in_cart = $this->cart->get_event_in_cart_by_event_id($event_id);
        $this->conference_event = $event_in_cart->event;
        $this->main_participant = $event_in_cart->get_participant_by_id($participant_id);
        $this->contact_id = $this->main_participant->contact_id;
        $this->main_participant->display_name = CRM_Contact_BAO_Contact::displayName($this->contact_id);
        $events = new CRM_Event_BAO_Event();
        $query = <<<EOS
\t  SELECT
               civicrm_event.*,
               slot.label AS slot_label
          FROM
               civicrm_event
          JOIN
                civicrm_option_value slot ON civicrm_event.slot_label_id = slot.value
          JOIN
                civicrm_option_group og ON slot.option_group_id = og.id
\t  WHERE
\t\tparent_event_id = {$this->conference_event->id}
                AND civicrm_event.is_active = 1
                AND COALESCE(civicrm_event.is_template, 0) = 0
                AND og.name = 'conference_slot'
\t  ORDER BY
\t\tslot.weight, start_date
EOS;
        $events->query($query);
        while ($events->fetch()) {
            if (!array_key_exists($events->slot_label, $this->events_by_slot)) {
                $this->events_by_slot[$events->slot_label] = array();
            }
            $this->events_by_slot[$events->slot_label][] = clone $events;
        }
    }
Ejemplo n.º 3
0
 public function setDefaultValues()
 {
     $this->loadCart();
     $defaults = array();
     foreach ($this->cart->get_main_event_participants() as $participant) {
         $form = $participant->get_form();
         if (empty($participant->email) && !CRM_Event_Cart_Form_Cart::is_administrator() && $participant->get_participant_index() == 1 && $this->cid != 0) {
             $defaults = array();
             $params = array('id' => $this->cid);
             $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);
             $participant->contact_id = $this->cid;
             $participant->save();
             $participant->email = self::primary_email_from_contact($contact);
         } elseif ($this->cid == 0 && $participant->contact_id == self::getContactID()) {
             $participant->email = NULL;
             $participant->contact_id = self::find_or_create_contact($this->getContactID());
         }
         $defaults += $form->setDefaultValues();
     }
     return $defaults;
 }
 /**
  * Set default values.
  *
  * @return array
  */
 public function setDefaultValues()
 {
     $this->loadCart();
     $defaults = array();
     foreach ($this->cart->get_main_event_participants() as $participant) {
         $form = $participant->get_form();
         if (empty($participant->email) && !CRM_Event_Cart_Form_Cart::is_administrator() && $participant->get_participant_index() == 1 && $this->cid != 0) {
             $defaults = array();
             $params = array('id' => $this->cid);
             $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);
             $participant->contact_id = $this->cid;
             $participant->save();
             $participant->email = self::primary_email_from_contact($contact);
         } elseif ($this->cid == 0 && $participant->contact_id == self::getContactID()) {
             $participant->email = NULL;
             $participant->contact_id = self::find_or_create_contact($this->getContactID());
         }
         $defaults += $form->setDefaultValues();
         //Set price defaults if any
         foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) {
             $event_id = $event_in_cart->event_id;
             $price_set_id = CRM_Event_BAO_Event::usesPriceSet($event_in_cart->event_id);
             if ($price_set_id) {
                 $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE);
                 $price_set = $price_sets[$price_set_id];
                 foreach ($price_set['fields'] as $field) {
                     $options = CRM_Utils_Array::value('options', $field);
                     if (!is_array($options)) {
                         continue;
                     }
                     $field_name = "event_{$event_id}_price_{$field['id']}";
                     foreach ($options as $value) {
                         if ($value['is_default']) {
                             if ($field['html_type'] == 'Checkbox') {
                                 $defaults[$field_name] = 1;
                             } else {
                                 $defaults[$field_name] = $value['id'];
                             }
                         }
                     }
                 }
             }
         }
     }
     return $defaults;
 }
Ejemplo n.º 5
0
 /**
  * @return array
  */
 public function setDefaultValues()
 {
     $defaults = parent::setDefaultValues();
     $config = CRM_Core_Config::singleton();
     $default_country = new CRM_Core_DAO_Country();
     $default_country->iso_code = $config->defaultContactCountry();
     $default_country->find(TRUE);
     $defaults["billing_country_id-{$this->_bltID}"] = $default_country->id;
     if (self::getContactID() && !self::is_administrator()) {
         $params = array('id' => self::getContactID());
         $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);
         foreach ($contact->email as $email) {
             if ($email['is_billing']) {
                 $defaults["billing_contact_email"] = $email['email'];
             }
         }
         if (empty($defaults['billing_contact_email'])) {
             foreach ($contact->email as $email) {
                 if ($email['is_primary']) {
                     $defaults["billing_contact_email"] = $email['email'];
                 }
             }
         }
         $defaults["billing_first_name"] = $contact->first_name;
         $defaults["billing_middle_name"] = $contact->middle_name;
         $defaults["billing_last_name"] = $contact->last_name;
         $billing_address = CRM_Event_Cart_BAO_MerParticipant::billing_address_from_contact($contact);
         if ($billing_address != NULL) {
             $defaults["billing_street_address-{$this->_bltID}"] = $billing_address['street_address'];
             $defaults["billing_city-{$this->_bltID}"] = $billing_address['city'];
             $defaults["billing_postal_code-{$this->_bltID}"] = $billing_address['postal_code'];
             $defaults["billing_state_province_id-{$this->_bltID}"] = $billing_address['state_province_id'];
             $defaults["billing_country_id-{$this->_bltID}"] = $billing_address['country_id'];
         }
     }
     $defaults["source"] = $this->description;
     return $defaults;
 }