2 class CRM_Event_Cart_Form_Cart
extends CRM_Core_Form
{
7 public $event_cart_id = NULL;
11 public function preProcess() {
12 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
13 $this->_mode
= 'live';
16 $this->checkWaitingList();
18 $locationTypes = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_Address', 'location_type_id');
19 $this->_bltID
= array_search('Billing', $locationTypes);
20 $this->assign('bltID', $this->_bltID
);
22 $event_titles = array();
23 foreach ($this->cart
->get_main_events_in_carts() as $event_in_cart) {
24 $event_titles[] = $event_in_cart->event
->title
;
26 $this->description
= ts("Online Registration for %1", array(1 => implode(", ", $event_titles)));
27 if (!isset($this->discounts
)) {
28 $this->discounts
= array();
33 if ($this->event_cart_id
== NULL) {
34 $this->cart
= CRM_Event_Cart_BAO_Cart
::find_or_create_for_current_session();
37 $this->cart
= CRM_Event_Cart_BAO_Cart
::find_by_id($this->event_cart_id
);
39 $this->cart
->load_associations();
40 $this->stub_out_and_inherit();
43 function stub_out_and_inherit() {
44 $transaction = new CRM_Core_Transaction();
46 foreach ($this->cart
->get_main_events_in_carts() as $event_in_cart) {
47 if (empty($event_in_cart->participants
)) {
48 $participant_params = array(
49 'cart_id' => $this->cart
->id
,
50 'event_id' => $event_in_cart->event_id
,
51 'contact_id' => self
::find_or_create_contact($this->getContactID()),
53 $participant = CRM_Event_Cart_BAO_MerParticipant
::create($participant_params);
55 $event_in_cart->add_participant($participant);
57 $event_in_cart->save();
59 $transaction->commit();
62 function checkWaitingList() {
63 foreach ($this->cart
->events_in_carts
as $event_in_cart) {
64 $empty_seats = $this->checkEventCapacity($event_in_cart->event_id
);
65 if ($empty_seats === NULL) {
68 foreach ($event_in_cart->participants
as $participant) {
69 $participant->must_wait
= ($empty_seats <= 0);
75 function checkEventCapacity($event_id) {
76 $empty_seats = CRM_Event_BAO_Participant
::eventFull($event_id, TRUE);
77 if (is_numeric($empty_seats)) {
80 if (is_string($empty_seats)) {
88 static function is_administrator() {
90 return CRM_Core_Permission
::check('administer CiviCRM');
93 function getContactID() {
94 //XXX when do we query 'cid' ?
95 $tempID = CRM_Utils_Request
::retrieve('cid', 'Positive', $this);
97 //check if this is a checksum authentication
98 $userChecksum = CRM_Utils_Request
::retrieve('cs', 'String', $this);
100 //check for anonymous user.
101 $validUser = CRM_Contact_BAO_Contact_Utils
::validChecksum($tempID, $userChecksum);
107 // check if the user is registered and we have a contact ID
108 $session = CRM_Core_Session
::singleton();
109 return $session->get('userID');
112 static function find_contact($fields) {
113 $dedupe_params = CRM_Dedupe_Finder
::formatParams($fields, 'Individual');
114 $dedupe_params['check_permission'] = FALSE;
115 $ids = CRM_Dedupe_Finder
::dupesByParams($dedupe_params, 'Individual');
116 if (is_array($ids)) {
117 return array_pop($ids);
122 static function find_or_create_contact($registeringContactID = NULL, $fields = array(
124 $contact_id = self
::find_contact($fields);
129 $contact_params = array(
130 'email-Primary' => CRM_Utils_Array
::value('email', $fields, NULL),
131 'first_name' => CRM_Utils_Array
::value('first_name', $fields, NULL),
132 'last_name' => CRM_Utils_Array
::value('last_name', $fields, NULL),
133 'is_deleted' => CRM_Utils_Array
::value('is_deleted', $fields, TRUE),
135 $no_fields = array();
136 $contact_id = CRM_Contact_BAO_Contact
::createProfileContact($contact_params, $no_fields, NULL);
138 CRM_Core_Error
::displaySessionError("Could not create or match a contact with that email address. Please contact the webmaster.");
143 function getValuesForPage($page_name) {
144 $container = $this->controller
->container();
145 return $container['values'][$page_name];