Ejemplo n.º 1
0
 /**
  * Register a participant.
  *
  * @param array $params
  * @param CRM_Event_BAO_Participant $participant
  * @param CRM_Event_BAO_Event $event
  *
  * @return mixed
  */
 public function registerParticipant($params, &$participant, $event)
 {
     $transaction = new CRM_Core_Transaction();
     // handle register date CRM-4320
     $registerDate = date('YmdHis');
     $participantParams = array('id' => $participant->id, 'event_id' => $event->id, 'register_date' => $registerDate, 'source' => CRM_Utils_Array::value('participant_source', $params, $this->description), 'is_pay_later' => $this->is_pay_later, 'fee_amount' => CRM_Utils_Array::value('amount', $params, 0), 'fee_currency' => CRM_Utils_Array::value('currencyID', $params));
     if ($participant->must_wait) {
         $participant_status = 'On waitlist';
     } elseif (CRM_Utils_Array::value('is_pay_later', $params, FALSE)) {
         $participant_status = 'Pending from pay later';
     } else {
         $participant_status = 'Registered';
     }
     $participant_statuses = CRM_Event_PseudoConstant::participantStatus();
     $participantParams['status_id'] = array_search($participant_status, $participant_statuses);
     $participant_status_label = CRM_Utils_Array::value($participantParams['status_id'], CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'));
     $participantParams['participant_status'] = $participant_status_label;
     $this->assign('isOnWaitlist', $participant->must_wait);
     if ($this->_action & CRM_Core_Action::PREVIEW || CRM_Utils_Array::value('mode', $params) == 'test') {
         $participantParams['is_test'] = 1;
     } else {
         $participantParams['is_test'] = 0;
     }
     if (self::is_administrator()) {
         if (!empty($params['note'])) {
             $note_params = array('participant_id' => $participant->id, 'contact_id' => self::getContactID(), 'note' => $params['note']);
             CRM_Event_BAO_Participant::update_note($note_params);
         }
     }
     $participant->copyValues($participantParams);
     $participant->save();
     if (!empty($params['contributionID'])) {
         $payment_params = array('participant_id' => $participant->id, 'contribution_id' => $params['contributionID']);
         $ids = array();
         CRM_Event_BAO_ParticipantPayment::create($payment_params, $ids);
     }
     $transaction->commit();
     $event_values = array();
     CRM_Core_DAO::storeValues($event, $event_values);
     $location = array();
     if (CRM_Utils_Array::value('is_show_location', $event_values) == 1) {
         $locationParams = array('entity_id' => $participant->event_id, 'entity_table' => 'civicrm_event');
         $location = CRM_Core_BAO_Location::getValues($locationParams, TRUE);
         CRM_Core_BAO_Address::fixAddress($location['address'][1]);
     }
     list($pre_id, $post_id) = CRM_Event_Cart_Form_MerParticipant::get_profile_groups($participant->event_id);
     $payer_values = array('email' => '', 'name' => '');
     if ($this->payer_contact_id) {
         $payer_contact_details = CRM_Contact_BAO_Contact::getContactDetails($this->payer_contact_id);
         $payer_values = array('email' => $payer_contact_details[1], 'name' => $payer_contact_details[0]);
     }
     $values = array('params' => array($participant->id => $participantParams), 'event' => $event_values, 'location' => $location, 'custom_pre_id' => $pre_id, 'custom_post_id' => $post_id, 'payer' => $payer_values);
     CRM_Event_BAO_Event::sendMail($participant->contact_id, $values, $participant->id);
     return $participant;
 }
Ejemplo n.º 2
0
 /**
  * Takes an associative array and creates a participant object.
  *
  * the function extract all the params it needs to initialize the create a
  * participant object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Event_BAO_Participant
  */
 public static function &add(&$params)
 {
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Participant', NULL, $params);
     }
     // converting dates to mysql format
     if (!empty($params['register_date'])) {
         $params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']);
     }
     if (!empty($params['participant_fee_amount'])) {
         $params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']);
     }
     if (!empty($params['fee_amount'])) {
         $params['fee_amount'] = CRM_Utils_Rule::cleanMoney($params['fee_amount']);
     }
     // ensure that role ids are encoded as a string
     if (isset($params['role_id']) && is_array($params['role_id'])) {
         if (in_array(key($params['role_id']), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
             $op = key($params['role_id']);
             $params['role_id'] = $params['role_id'][$op];
         } else {
             $params['role_id'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['role_id']);
         }
     }
     $participantBAO = new CRM_Event_BAO_Participant();
     if (!empty($params['id'])) {
         $participantBAO->id = CRM_Utils_Array::value('id', $params);
         $participantBAO->find(TRUE);
         $participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date);
     }
     $participantBAO->copyValues($params);
     //CRM-6910
     //1. If currency present, it should be valid one.
     //2. We should have currency when amount is not null.
     $currency = $participantBAO->fee_currency;
     if ($currency || !CRM_Utils_System::isNull($participantBAO->fee_amount)) {
         if (!CRM_Utils_Rule::currencyCode($currency)) {
             $config = CRM_Core_Config::singleton();
             $currency = $config->defaultCurrency;
         }
     }
     $participantBAO->fee_currency = $currency;
     $participantBAO->save();
     $session = CRM_Core_Session::singleton();
     CRM_Contact_BAO_GroupContactCache::opportunisticCacheFlush();
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO);
     } else {
         CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO);
     }
     return $participantBAO;
 }
Ejemplo n.º 3
0
 /**
  * takes an associative array and creates a participant object
  *
  * the function extract all the params it needs to initialize the create a
  * participant object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array  $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Event_BAO_Participant object
  * @access public
  * @static
  */
 static function &add(&$params)
 {
     require_once 'CRM/Utils/Hook.php';
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Participant', null, $params);
     }
     // converting dates to mysql format
     if (CRM_Utils_Array::value('register_date', $params)) {
         $params['register_date'] = CRM_Utils_Date::isoToMysql($params['register_date']);
     }
     if (CRM_Utils_Array::value('participant_fee_amount', $params)) {
         $params['participant_fee_amount'] = CRM_Utils_Rule::cleanMoney($params['participant_fee_amount']);
     }
     if (CRM_Utils_Array::value('participant_fee_amount', $params)) {
         $params['fee_amount'] = CRM_Utils_Rule::cleanMoney($params['fee_amount']);
     }
     $participantBAO = new CRM_Event_BAO_Participant();
     if (CRM_Utils_Array::value('id', $params)) {
         $participantBAO->id = CRM_Utils_Array::value('id', $params);
         $participantBAO->find(true);
         $participantBAO->register_date = CRM_Utils_Date::isoToMysql($participantBAO->register_date);
     }
     $participantBAO->copyValues($params);
     //CRM-6910
     //1. If currency present, it should be valid one.
     //2. We should have currency when amount is not null.
     require_once 'CRM/Utils/Rule.php';
     $currency = $participantBAO->fee_currency;
     if ($currency || !CRM_Utils_System::isNull($participantBAO->fee_amount)) {
         if (!CRM_Utils_Rule::currencyCode($currency)) {
             $config = CRM_Core_Config::singleton();
             $currency = $config->defaultCurrency;
         }
     }
     $participantBAO->fee_currency = $currency;
     $participantBAO->save();
     $session =& CRM_Core_Session::singleton();
     // reset the group contact cache for this group
     require_once 'CRM/Contact/BAO/GroupContactCache.php';
     CRM_Contact_BAO_GroupContactCache::remove();
     if (CRM_Utils_Array::value('id', $params)) {
         CRM_Utils_Hook::post('edit', 'Participant', $participantBAO->id, $participantBAO);
     } else {
         CRM_Utils_Hook::post('create', 'Participant', $participantBAO->id, $participantBAO);
     }
     return $participantBAO;
 }