Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | class CRM_Event_Cart_Form_MerParticipant extends CRM_Core_Form { | |
3 | public $participant = NULL; | |
4 | ||
5 | function __construct($participant) { | |
6 | parent::__construct(); | |
7 | //XXX | |
8 | $this->participant = $participant; | |
9 | } | |
10 | ||
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); | |
14 | ||
15 | list( | |
16 | $custom_fields_pre, | |
17 | $custom_fields_post | |
18 | ) = $this->get_participant_custom_data_fields($this->participant->event_id); | |
19 | ||
20 | foreach ($custom_fields_pre as $key => $field) { | |
21 | CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, $this->participant->id); | |
22 | } | |
23 | foreach ($custom_fields_post as $key => $field) { | |
24 | CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, $this->participant->id); | |
25 | } | |
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(), | |
31 | ))); | |
32 | } | |
33 | ||
34 | function get_profile_groups($event_id) { | |
35 | $ufJoinParams = array( | |
36 | 'entity_table' => 'civicrm_event', | |
37 | 'module' => 'CiviEvent', | |
38 | 'entity_id' => $event_id, | |
39 | ); | |
40 | $group_ids = CRM_Core_BAO_UFJoin::getUFGroupIds($ufJoinParams); | |
41 | return $group_ids; | |
42 | } | |
43 | ||
44 | function get_participant_custom_data_fields() { | |
45 | list($custom_pre_id, $custom_post_id) = self::get_profile_groups($this->participant->event_id); | |
46 | ||
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); | |
50 | } | |
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); | |
53 | } | |
54 | ||
55 | return array($pre_fields, $post_fields); | |
56 | } | |
57 | ||
58 | function email_field_name() { | |
59 | return $this->html_field_name("email"); | |
60 | } | |
61 | ||
62 | static function full_field_name($event_id, $participant_id, $field_name) { | |
63 | return "event[$event_id][participant][$participant_id][$field_name]"; | |
64 | } | |
65 | ||
66 | function html_field_name($field_name) { | |
67 | return self::full_field_name($this->participant->event_id, $this->participant->id, $field_name); | |
68 | } | |
69 | ||
70 | function name() { | |
71 | return "Participant {$this->participant->get_participant_index()}"; | |
72 | } | |
73 | ||
74 | //XXX poor name | |
75 | static public function get_form($participant) { | |
76 | return new CRM_Event_Cart_Form_MerParticipant($participant); | |
77 | } | |
78 | ||
79 | function setDefaultValues() { | |
80 | $defaults = array( | |
81 | $this->html_field_name('email') => $this->participant->email, | |
82 | ); | |
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; | |
85 | $flat = array(); | |
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; | |
89 | } | |
90 | return $defaults; | |
91 | } | |
92 | } | |
93 |