3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
29 * Class CRM_Event_Cart_BAO_MerParticipant
31 class CRM_Event_Cart_BAO_MerParticipant
extends CRM_Event_BAO_Participant
{
33 public $contribution_id = NULL;
38 * @param null $participant
40 function __construct($participant = NULL) {
41 parent
::__construct();
42 $a = (array)$participant;
43 $this->copyValues($a);
45 $this->email
= CRM_Utils_Array
::value('email', $participant);
49 * @param array $params
51 * @return CRM_Event_Cart_BAO_MerParticipant
54 static function create(&$params) {
55 $participantParams = array(
56 'id' => CRM_Utils_Array
::value('id', $params),
57 'role_id' => self
::get_attendee_role_id(),
58 'status_id' => self
::get_pending_in_cart_status_id(),
59 'contact_id' => $params['contact_id'],
60 'event_id' => $params['event_id'],
61 'cart_id' => $params['cart_id'],
63 //'registered_by_id' =>
64 //'discount_amount' =>
65 //'fee_level' => $params['fee_level'],
67 $participant = CRM_Event_BAO_Participant
::create($participantParams);
69 if (is_a($participant, 'CRM_Core_Error')) {
70 CRM_Core_Error
::fatal(ts('There was an error creating a cart participant'));
73 $mer_participant = new CRM_Event_Cart_BAO_MerParticipant($participant);
75 return $mer_participant;
81 static function get_attendee_role_id() {
82 $roles = CRM_Event_PseudoConstant
::participantRole(NULL, "v.label='Attendee'");
83 $role_names = array_keys($roles);
84 return end($role_names);
90 static function get_pending_in_cart_status_id() {
91 $status_types = CRM_Event_PseudoConstant
::participantStatus(NULL, "name='Pending in cart'");
92 $status_names = array_keys($status_types);
93 return end($status_names);
97 * @param $event_cart_id
101 public static function find_all_by_cart_id($event_cart_id) {
102 if ($event_cart_id == NULL) {
105 return self
::find_all_by_params(array('cart_id' => $event_cart_id));
110 * @param $event_cart_id
114 public static function find_all_by_event_and_cart_id($event_id, $event_cart_id) {
115 if ($event_cart_id == NULL) {
118 return self
::find_all_by_params(array('event_id' => $event_id, 'cart_id' => $event_cart_id));
126 public static function find_all_by_params($params) {
127 $participant = new CRM_Event_BAO_Participant();
128 $participant->copyValues($params);
130 if ($participant->find()) {
131 while ($participant->fetch()) {
132 $result[] = new CRM_Event_Cart_BAO_MerParticipant(clone($participant));
143 public static function get_by_id($id) {
144 $results = self
::find_all_by_params(array('id' => $id));
145 return array_pop($results);
148 function load_associations() {
149 $contact_details = CRM_Contact_BAO_Contact
::getContactDetails($this->contact_id
);
150 $this->email
= $contact_details[1];
156 function get_participant_index() {
158 $this->cart
= CRM_Event_Cart_BAO_Cart
::find_by_id($this->cart_id
);
159 $this->cart
->load_associations();
161 $index = $this->cart
->get_participant_index_from_id($this->id
);
170 static function billing_address_from_contact($contact) {
171 foreach ($contact->address
as $loc) {
172 if ($loc['is_billing']) {
176 foreach ($contact->address
as $loc) {
177 if ($loc['is_primary']) {
185 * @return CRM_Event_Cart_Form_MerParticipant
187 function get_form() {
188 return new CRM_Event_Cart_Form_MerParticipant($this);