3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 class CRM_Event_Cart_BAO_MerParticipant
extends CRM_Event_BAO_Participant
{
30 public $contribution_id = NULL;
34 function __construct($participant = NULL) {
35 parent
::__construct();
36 $a = (array)$participant;
37 $this->copyValues($a);
39 $this->email
= CRM_Utils_Array
::value('email', $participant);
42 public static function &create($params) {
43 $participantParams = array(
44 'id' => CRM_Utils_Array
::value('id', $params),
45 'role_id' => self
::get_attendee_role_id(),
46 'status_id' => self
::get_pending_in_cart_status_id(),
47 'contact_id' => $params['contact_id'],
48 'event_id' => $params['event_id'],
49 'cart_id' => $params['cart_id'],
51 //'registered_by_id' =>
52 //'discount_amount' =>
53 //'fee_level' => $params['fee_level'],
55 $participant = CRM_Event_BAO_Participant
::create($participantParams);
57 if (is_a($participant, 'CRM_Core_Error')) {
58 CRM_Core_Error
::fatal(ts('There was an error creating a cart participant'));
61 $mer_participant = new CRM_Event_Cart_BAO_MerParticipant($participant);
63 return $mer_participant;
66 static function get_attendee_role_id() {
67 $roles = CRM_Event_PseudoConstant
::participantRole(NULL, "v.label='Attendee'");
68 $role_names = array_keys($roles);
69 return end($role_names);
72 static function get_pending_in_cart_status_id() {
73 $status_types = CRM_Event_PseudoConstant
::participantStatus(NULL, "name='Pending in cart'");
74 $status_names = array_keys($status_types);
75 return end($status_names);
78 public static function find_all_by_cart_id($event_cart_id) {
79 if ($event_cart_id == NULL) {
82 return self
::find_all_by_params(array('cart_id' => $event_cart_id));
85 public static function find_all_by_event_and_cart_id($event_id, $event_cart_id) {
86 if ($event_cart_id == NULL) {
89 return self
::find_all_by_params(array('event_id' => $event_id, 'cart_id' => $event_cart_id));
92 public static function find_all_by_params($params) {
93 $participant = new CRM_Event_BAO_Participant();
94 $participant->copyValues($params);
96 if ($participant->find()) {
97 while ($participant->fetch()) {
98 $result[] = new CRM_Event_Cart_BAO_MerParticipant(clone($participant));
104 public static function get_by_id($id) {
105 $results = self
::find_all_by_params(array('id' => $id));
106 return array_pop($results);
109 function load_associations() {
110 $contact_details = CRM_Contact_BAO_Contact
::getContactDetails($this->contact_id
);
111 $this->email
= $contact_details[1];
114 function get_participant_index() {
116 $this->cart
= CRM_Event_Cart_BAO_Cart
::find_by_id($this->cart_id
);
117 $this->cart
->load_associations();
119 $index = $this->cart
->get_participant_index_from_id($this->id
);
123 static function billing_address_from_contact($contact) {
124 foreach ($contact->address
as $loc) {
125 if ($loc['is_billing']) {
129 foreach ($contact->address
as $loc) {
130 if ($loc['is_primary']) {
137 function get_form() {
138 return new CRM_Event_Cart_Form_MerParticipant($this);