4 * Class CRM_Event_Cart_Form_MerParticipant
6 class CRM_Event_Cart_Form_MerParticipant
extends CRM_Core_Form
{
7 public $participant = NULL;
10 * @param null|object $participant
12 public function __construct($participant) {
13 parent
::__construct();
15 $this->participant
= $participant;
19 * @param CRM_Core_Form $form
21 public function appendQuickForm(&$form) {
22 $textarea_size = array('size' => 30, 'maxlength' => 60);
23 $form->add('text', $this->email_field_name(), ts('Email Address'), $textarea_size, TRUE);
28 ) = $this->get_participant_custom_data_fields($this->participant
->event_id
);
30 foreach ($custom_fields_pre as $key => $field) {
31 CRM_Core_BAO_UFGroup
::buildProfile($form, $field, CRM_Profile_Form
::MODE_CREATE
, $this->participant
->id
);
33 foreach ($custom_fields_post as $key => $field) {
34 CRM_Core_BAO_UFGroup
::buildProfile($form, $field, CRM_Profile_Form
::MODE_CREATE
, $this->participant
->id
);
36 $custom = CRM_Utils_Array
::value('custom', $form->getTemplate()->_tpl_vars
, array());
37 $form->assign('custom', array_merge($custom, array(
38 $this->html_field_name('customPre') => $custom_fields_pre,
39 $this->html_field_name('customPost') => $custom_fields_post,
40 $this->html_field_name('number') => $this->name(),
45 * @param int $event_id
49 public function get_profile_groups($event_id) {
50 $ufJoinParams = array(
51 'entity_table' => 'civicrm_event',
52 'module' => 'CiviEvent',
53 'entity_id' => $event_id,
55 $group_ids = CRM_Core_BAO_UFJoin
::getUFGroupIds($ufJoinParams);
62 public function get_participant_custom_data_fields() {
63 list($custom_pre_id, $custom_post_id) = self
::get_profile_groups($this->participant
->event_id
);
65 $pre_fields = $post_fields = array();
66 if ($custom_pre_id && CRM_Core_BAO_UFGroup
::filterUFGroups($custom_pre_id, $this->participant
->contact_id
)) {
67 $pre_fields = CRM_Core_BAO_UFGroup
::getFields($custom_pre_id, FALSE, CRM_Core_Action
::ADD
);
69 if ($custom_post_id && CRM_Core_BAO_UFGroup
::filterUFGroups($custom_post_id, $this->participant
->contact_id
)) {
70 $post_fields = CRM_Core_BAO_UFGroup
::getFields($custom_post_id, FALSE, CRM_Core_Action
::ADD
);
73 return array($pre_fields, $post_fields);
79 public function email_field_name() {
80 return $this->html_field_name("email");
84 * @param int $event_id
85 * @param int $participant_id
86 * @param string $field_name
90 public static function full_field_name($event_id, $participant_id, $field_name) {
91 return "event[$event_id][participant][$participant_id][$field_name]";
95 * @param string $field_name
99 public function html_field_name($field_name) {
100 return self
::full_field_name($this->participant
->event_id
, $this->participant
->id
, $field_name);
106 public function name() {
107 return "Participant {$this->participant->get_participant_index()}";
112 * @param $participant
114 * @return CRM_Event_Cart_Form_MerParticipant
116 static public function get_form($participant) {
117 return new CRM_Event_Cart_Form_MerParticipant($participant);
123 public function setDefaultValues() {
125 $this->html_field_name('email') => $this->participant
->email
,
127 list($custom_fields_pre, $custom_fields_post) = $this->get_participant_custom_data_fields($this->participant
->event_id
);
128 $all_fields = $custom_fields_pre +
$custom_fields_post;
130 CRM_Core_BAO_UFGroup
::setProfileDefaults($this->participant
->contact_id
, $all_fields, $flat);
131 foreach ($flat as $name => $field) {
132 $defaults["field[{$this->participant->id}][{$name}]"] = $field;