2 class CRM_Event_Cart_Form_MerParticipant
extends CRM_Core_Form
{
3 public $participant = NULL;
5 function __construct($participant) {
8 $this->participant
= $participant;
11 function appendQuickForm(&$form) {
12 $textarea_size = array('size' => 30, 'maxlength' => 60);
13 $form->add('text', $this->email_field_name(), ts('Email Address'), $textarea_size, TRUE);
18 ) = $this->get_participant_custom_data_fields($this->participant
->event_id
);
20 foreach ($custom_fields_pre as $key => $field) {
21 CRM_Core_BAO_UFGroup
::buildProfile($form, $field, CRM_Profile_Form
::MODE_CREATE
, $this->participant
->id
);
23 foreach ($custom_fields_post as $key => $field) {
24 CRM_Core_BAO_UFGroup
::buildProfile($form, $field, CRM_Profile_Form
::MODE_CREATE
, $this->participant
->id
);
26 $custom = CRM_Utils_Array
::value('custom', $form->getTemplate()->_tpl_vars
, array());
27 $form->assign('custom', array_merge($custom, array(
28 $this->html_field_name('customPre') => $custom_fields_pre,
29 $this->html_field_name('customPost') => $custom_fields_post,
30 $this->html_field_name('number') => $this->name(),
34 function get_profile_groups($event_id) {
35 $ufJoinParams = array(
36 'entity_table' => 'civicrm_event',
37 'module' => 'CiviEvent',
38 'entity_id' => $event_id,
40 $group_ids = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
44 function get_participant_custom_data_fields() {
45 list($custom_pre_id, $custom_post_id) = self
::get_profile_groups($this->participant
->event_id
);
47 $pre_fields = $post_fields = array();
48 if ($custom_pre_id && CRM_Core_BAO_UFGroup
::filterUFGroups($custom_pre_id, $this->participant
->contact_id
)) {
49 $pre_fields = CRM_Core_BAO_UFGroup
::getFields($custom_pre_id, FALSE, CRM_Core_Action
::ADD
);
51 if ($custom_post_id && CRM_Core_BAO_UFGroup
::filterUFGroups($custom_post_id, $this->participant
->contact_id
)) {
52 $post_fields = CRM_Core_BAO_UFGroup
::getFields($custom_post_id, FALSE, CRM_Core_Action
::ADD
);
55 return array($pre_fields, $post_fields);
58 function email_field_name() {
59 return $this->html_field_name("email");
62 static function full_field_name($event_id, $participant_id, $field_name) {
63 return "event[$event_id][participant][$participant_id][$field_name]";
66 function html_field_name($field_name) {
67 return self
::full_field_name($this->participant
->event_id
, $this->participant
->id
, $field_name);
71 return "Participant {$this->participant->get_participant_index()}";
75 static public function get_form($participant) {
76 return new CRM_Event_Cart_Form_MerParticipant($participant);
79 function setDefaultValues() {
81 $this->html_field_name('email') => $this->participant
->email
,
83 list($custom_fields_pre, $custom_fields_post) = $this->get_participant_custom_data_fields($this->participant
->event_id
);
84 $all_fields = $custom_fields_pre +
$custom_fields_post;
86 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->participant
->contact_id
, $all_fields, $flat);
87 foreach ($flat as $name => $field) {
88 $defaults["field[{$this->participant->id}][{$name}]"] = $field;