3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * Class CRM_Event_Cart_BAO_MerParticipant
15 class CRM_Event_Cart_BAO_MerParticipant
extends CRM_Event_BAO_Participant
{
17 public $contribution_id = NULL;
22 * @param null $participant
24 public function __construct($participant = NULL) {
25 parent
::__construct();
26 $a = (array) $participant;
27 $this->copyValues($a);
29 $this->email
= CRM_Utils_Array
::value('email', $participant);
33 * @param array $params
35 * @return CRM_Event_Cart_BAO_MerParticipant
38 public static function create(&$params) {
39 $participantParams = [
40 'id' => CRM_Utils_Array
::value('id', $params),
41 'role_id' => self
::get_attendee_role_id(),
42 'status_id' => self
::get_pending_in_cart_status_id(),
43 'contact_id' => $params['contact_id'],
44 'event_id' => $params['event_id'],
45 'cart_id' => $params['cart_id'],
47 //'registered_by_id' =>
48 //'discount_amount' =>
49 //'fee_level' => $params['fee_level'],
51 $participant = CRM_Event_BAO_Participant
::create($participantParams);
53 if (is_a($participant, 'CRM_Core_Error')) {
54 CRM_Core_Error
::fatal(ts('There was an error creating a cart participant'));
57 $mer_participant = new CRM_Event_Cart_BAO_MerParticipant($participant);
59 return $mer_participant;
65 public static function get_attendee_role_id() {
66 $roles = CRM_Event_PseudoConstant
::participantRole(NULL, "v.label='Attendee'");
67 $role_names = array_keys($roles);
68 return end($role_names);
74 public static function get_pending_in_cart_status_id() {
75 $status_types = CRM_Event_PseudoConstant
::participantStatus(NULL, "name='Pending in cart'");
76 $status_names = array_keys($status_types);
77 return end($status_names);
81 * @param int $event_cart_id
85 public static function find_all_by_cart_id($event_cart_id) {
86 if ($event_cart_id == NULL) {
89 return self
::find_all_by_params(['cart_id' => $event_cart_id]);
93 * @param int $event_id
94 * @param int $event_cart_id
98 public static function find_all_by_event_and_cart_id($event_id, $event_cart_id) {
99 if ($event_cart_id == NULL) {
102 return self
::find_all_by_params(['event_id' => $event_id, 'cart_id' => $event_cart_id]);
106 * @param array $params
110 public static function find_all_by_params($params) {
111 $participant = new CRM_Event_BAO_Participant();
112 $participant->copyValues($params);
114 if ($participant->find()) {
115 while ($participant->fetch()) {
116 $result[] = new CRM_Event_Cart_BAO_MerParticipant(clone($participant));
127 public static function get_by_id($id) {
128 $results = self
::find_all_by_params(['id' => $id]);
129 return array_pop($results);
132 public function load_associations() {
133 $contact_details = CRM_Contact_BAO_Contact
::getContactDetails($this->contact_id
);
134 $this->email
= $contact_details[1];
140 public function get_participant_index() {
142 $this->cart
= CRM_Event_Cart_BAO_Cart
::find_by_id($this->cart_id
);
143 $this->cart
->load_associations();
145 $index = $this->cart
->get_participant_index_from_id($this->id
);
154 public static function billing_address_from_contact($contact) {
155 foreach ($contact->address
as $loc) {
156 if ($loc['is_billing']) {
160 foreach ($contact->address
as $loc) {
161 if ($loc['is_primary']) {
169 * @return CRM_Event_Cart_Form_MerParticipant
171 public function get_form() {
172 return new CRM_Event_Cart_Form_MerParticipant($this);