3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2016
33 class CRM_Event_BAO_Participant
extends CRM_Event_DAO_Participant
{
36 * Static field for all the participant information that we can potentially import.
40 static $_importableFields = NULL;
43 * Static field for all the participant information that we can potentially export.
47 static $_exportableFields = NULL;
50 * Static array for valid status transitions rules.
54 static $_statusTransitionsRules = array(
55 'Pending from pay later' => array('Registered', 'Cancelled'),
56 'Pending from incomplete transaction' => array('Registered', 'Cancelled'),
57 'On waitlist' => array('Cancelled', 'Pending from waitlist'),
58 'Pending from waitlist' => array('Registered', 'Cancelled'),
59 'Awaiting approval' => array('Cancelled', 'Pending from approval'),
60 'Pending from approval' => array('Registered', 'Cancelled'),
65 public function __construct() {
66 parent
::__construct();
70 * Takes an associative array and creates a participant object.
72 * the function extract all the params it needs to initialize the create a
73 * participant object. the params array could contain additional unused name/value
76 * @param array $params
77 * (reference ) an assoc array of name/value pairs.
79 * @return CRM_Event_BAO_Participant
81 public static function &add(&$params) {
83 if (!empty($params['id'])) {
84 CRM_Utils_Hook
::pre('edit', 'Participant', $params['id'], $params);
87 CRM_Utils_Hook
::pre('create', 'Participant', NULL, $params);
90 // converting dates to mysql format
91 if (!empty($params['register_date'])) {
92 $params['register_date'] = CRM_Utils_Date
::isoToMysql($params['register_date']);
95 if (!empty($params['participant_fee_amount'])) {
96 $params['participant_fee_amount'] = CRM_Utils_Rule
::cleanMoney($params['participant_fee_amount']);
99 if (!empty($params['fee_amount'])) {
100 $params['fee_amount'] = CRM_Utils_Rule
::cleanMoney($params['fee_amount']);
103 // ensure that role ids are encoded as a string
104 if (isset($params['role_id']) && is_array($params['role_id'])) {
105 if (in_array(key($params['role_id']), CRM_Core_DAO
::acceptedSQLOperators(), TRUE)) {
106 $op = key($params['role_id']);
107 $params['role_id'] = $params['role_id'][$op];
110 $params['role_id'] = implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $params['role_id']);
114 $participantBAO = new CRM_Event_BAO_Participant();
115 if (!empty($params['id'])) {
116 $participantBAO->id
= CRM_Utils_Array
::value('id', $params);
117 $participantBAO->find(TRUE);
118 $participantBAO->register_date
= CRM_Utils_Date
::isoToMysql($participantBAO->register_date
);
121 $participantBAO->copyValues($params);
124 //1. If currency present, it should be valid one.
125 //2. We should have currency when amount is not null.
126 $currency = $participantBAO->fee_currency
;
128 !CRM_Utils_System
::isNull($participantBAO->fee_amount
)
130 if (!CRM_Utils_Rule
::currencyCode($currency)) {
131 $config = CRM_Core_Config
::singleton();
132 $currency = $config->defaultCurrency
;
135 $participantBAO->fee_currency
= $currency;
137 $participantBAO->save();
139 $session = CRM_Core_Session
::singleton();
141 CRM_Contact_BAO_GroupContactCache
::opportunisticCacheFlush();
143 if (!empty($params['id'])) {
144 CRM_Utils_Hook
::post('edit', 'Participant', $participantBAO->id
, $participantBAO);
147 CRM_Utils_Hook
::post('create', 'Participant', $participantBAO->id
, $participantBAO);
150 return $participantBAO;
154 * Given the list of params in the params array, fetch the object
155 * and store the values in the values array
157 * @param array $params
158 * Input parameters to find object.
159 * @param array $values
160 * Output values of the object.
164 * @return CRM_Event_BAO_Participant|null the found object or null
166 public static function getValues(&$params, &$values, &$ids) {
167 if (empty($params)) {
170 $participant = new CRM_Event_BAO_Participant();
171 $participant->copyValues($params);
172 $participant->find();
173 $participants = array();
174 while ($participant->fetch()) {
175 $ids['participant'] = $participant->id
;
176 CRM_Core_DAO
::storeValues($participant, $values[$participant->id
]);
177 $participants[$participant->id
] = $participant;
179 return $participants;
183 * Takes an associative array and creates a participant object.
185 * @param array $params
186 * (reference ) an assoc array of name/value pairs.
188 * @return CRM_Event_BAO_Participant
190 public static function create(&$params) {
192 $transaction = new CRM_Core_Transaction();
195 if (!empty($params['id'])) {
196 $status = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $params['id'], 'status_id');
199 $participant = self
::add($params);
201 if (is_a($participant, 'CRM_Core_Error')) {
202 $transaction->rollback();
206 if ((!CRM_Utils_Array
::value('id', $params)) ||
207 (isset($params['status_id']) && $params['status_id'] != $status)
209 CRM_Activity_BAO_Activity
::addActivity($participant);
214 if (self
::isPrimaryParticipant($participant->id
) && $status) {
215 self
::updateParticipantStatus($participant->id
, $status, $participant->status_id
);
218 $session = CRM_Core_Session
::singleton();
219 $id = $session->get('userID');
221 $id = CRM_Utils_Array
::value('contact_id', $params);
224 // add custom field values
225 if (!empty($params['custom']) &&
226 is_array($params['custom'])
228 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_participant', $participant->id
);
231 //process note, CRM-7634
233 if (!empty($params['id'])) {
234 $note = CRM_Core_BAO_Note
::getNote($params['id'], 'civicrm_participant');
235 $noteId = key($note);
238 $hasNoteField = FALSE;
243 if (array_key_exists($noteFld, $params)) {
244 $noteValue = $params[$noteFld];
245 $hasNoteField = TRUE;
249 if ($noteId ||
$noteValue) {
252 'entity_table' => 'civicrm_participant',
253 'note' => $noteValue,
254 'entity_id' => $participant->id
,
256 'modified_date' => date('Ymd'),
260 $noteIDs['id'] = $noteId;
262 CRM_Core_BAO_Note
::add($noteParams, $noteIDs);
264 elseif ($noteId && $hasNoteField) {
265 CRM_Core_BAO_Note
::del($noteId, FALSE);
269 // Log the information on successful add/edit of Participant data.
271 'entity_table' => 'civicrm_participant',
272 'entity_id' => $participant->id
,
273 'data' => CRM_Event_PseudoConstant
::participantStatus($participant->status_id
),
274 'modified_id' => $id,
275 'modified_date' => date('Ymd'),
278 CRM_Core_BAO_Log
::add($logParams);
280 $params['participant_id'] = $participant->id
;
282 $transaction->commit();
284 // do not add to recent items for import, CRM-4399
285 if (empty($params['skipRecentView'])) {
287 $url = CRM_Utils_System
::url('civicrm/contact/view/participant',
288 "action=view&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"
291 $recentOther = array();
292 if (CRM_Core_Permission
::check('edit event participants')) {
293 $recentOther['editUrl'] = CRM_Utils_System
::url('civicrm/contact/view/participant',
294 "action=update&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"
297 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
298 $recentOther['deleteUrl'] = CRM_Utils_System
::url('civicrm/contact/view/participant',
299 "action=delete&reset=1&id={$participant->id}&cid={$participant->contact_id}&context=home"
303 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
305 if ($participant->role_id
) {
306 $role = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $participant->role_id
);
308 foreach ($role as & $roleValue) {
309 if (isset($roleValue)) {
310 $roleValue = $participantRoles[$roleValue];
313 $roles = implode(', ', $role);
316 $roleString = empty($roles) ?
'' : $roles;
317 $eventTitle = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $participant->event_id
, 'title');
318 $title = CRM_Contact_BAO_Contact
::displayName($participant->contact_id
) . ' (' . $roleString . ' - ' . $eventTitle . ')';
320 // add the recently created Participant
321 CRM_Utils_Recent
::add($title,
325 $participant->contact_id
,
335 * Check whether the event is full for participation and return as.
338 * @param int $eventId
340 * @param bool $returnEmptySeats
341 * Are we require number if empty seats.
342 * @param bool $includeWaitingList
343 * Consider waiting list in event full.
344 * calculation or not. (it is for cron job purpose)
346 * @param bool $returnWaitingCount
347 * @param bool $considerTestParticipant
349 * @return bool|int|null|string
350 * 1. false => If event having some empty spaces.
352 public static function eventFull(
354 $returnEmptySeats = FALSE,
355 $includeWaitingList = TRUE,
356 $returnWaitingCount = FALSE,
357 $considerTestParticipant = FALSE
364 // consider event is full when.
365 // 1. (count(is_counted) >= event_size) or
366 // 2. (count(participants-with-status-on-waitlist) > 0)
367 // It might be case there are some empty spaces and still event
368 // is full, as waitlist might represent group require spaces > empty.
370 $participantRoles = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
371 $countedStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
372 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
373 $onWaitlistStatusId = array_search('On waitlist', $waitingStatuses);
375 //when we do require only waiting count don't consider counted.
376 if (!$returnWaitingCount && !empty($countedStatuses)) {
377 $allStatusIds = array_keys($countedStatuses);
380 $where = array(' event.id = %1 ');
381 if (!$considerTestParticipant) {
382 $where[] = ' ( participant.is_test = 0 OR participant.is_test IS NULL ) ';
384 if (!empty($participantRoles)) {
385 $escapedRoles = array();
386 foreach (array_keys($participantRoles) as $participantRole) {
387 $escapedRoles[] = CRM_Utils_Type
::escape($participantRole, 'String');
390 $where[] = " participant.role_id IN ( '" . implode("', '", $escapedRoles) . "' ) ";
393 $eventParams = array(1 => array($eventId, 'Positive'));
395 //in case any waiting, straight forward event is full.
396 if ($includeWaitingList && $onWaitlistStatusId) {
398 //build the where clause.
399 $whereClause = ' WHERE ' . implode(' AND ', $where);
400 $whereClause .= " AND participant.status_id = $onWaitlistStatusId ";
401 $eventSeatsWhere = implode(' AND ', $where) . " AND ( participant.status_id = $onWaitlistStatusId )";
404 SELECT participant.id id,
405 event.event_full_text as event_full_text
406 FROM civicrm_participant participant
407 INNER JOIN civicrm_event event ON ( event.id = participant.event_id )
410 $eventFullText = ts('This event is full.');
411 $participants = CRM_Core_DAO
::executeQuery($query, $eventParams);
412 while ($participants->fetch()) {
413 //oops here event is full and we don't want waiting count.
414 if ($returnWaitingCount) {
415 return CRM_Event_BAO_Event
::eventTotalSeats($eventId, $eventSeatsWhere);
418 return ($participants->event_full_text
) ?
$participants->event_full_text
: $eventFullText;
423 //consider only counted participants.
424 $where[] = ' participant.status_id IN ( ' . implode(', ', array_keys($countedStatuses)) . ' ) ';
425 $whereClause = ' WHERE ' . implode(' AND ', $where);
426 $eventSeatsWhere = implode(' AND ', $where);
429 SELECT participant.id id,
430 event.event_full_text as event_full_text,
431 event.max_participants as max_participants
432 FROM civicrm_participant participant
433 INNER JOIN civicrm_event event ON ( event.id = participant.event_id )
436 $eventMaxSeats = NULL;
437 $eventFullText = ts('This event is full.');
438 $participants = CRM_Core_DAO
::executeQuery($query, $eventParams);
439 while ($participants->fetch()) {
440 if ($participants->event_full_text
) {
441 $eventFullText = $participants->event_full_text
;
443 $eventMaxSeats = $participants->max_participants
;
444 //don't have limit for event seats.
445 if ($participants->max_participants
== NULL) {
450 //get the total event seats occupied by these participants.
451 $eventRegisteredSeats = CRM_Event_BAO_Event
::eventTotalSeats($eventId, $eventSeatsWhere);
453 if ($eventRegisteredSeats) {
454 if ($eventRegisteredSeats >= $eventMaxSeats) {
455 $result = $eventFullText;
457 elseif ($returnEmptySeats) {
458 $result = $eventMaxSeats - $eventRegisteredSeats;
464 SELECT event.event_full_text,
465 event.max_participants
466 FROM civicrm_event event
467 WHERE event.id = %1';
468 $event = CRM_Core_DAO
::executeQuery($query, $eventParams);
469 while ($event->fetch()) {
470 $eventFullText = $event->event_full_text
;
471 $eventMaxSeats = $event->max_participants
;
475 // no limit for registration.
476 if ($eventMaxSeats == NULL) {
479 if ($eventMaxSeats) {
480 return ($returnEmptySeats) ?
(int) $eventMaxSeats : FALSE;
483 return $eventFullText;
487 * Return the array of all price set field options,
488 * with total participant count that field going to carry.
490 * @param int $eventId
492 * @param array $skipParticipantIds
493 * An array of participant ids those we should skip.
494 * @param bool $considerCounted
495 * @param bool $considerWaiting
496 * @param bool $considerTestParticipants
499 * an array of each option id and total count
501 public static function priceSetOptionsCount(
503 $skipParticipantIds = array(),
504 $considerCounted = TRUE,
505 $considerWaiting = TRUE,
506 $considerTestParticipants = FALSE
508 $optionsCount = array();
510 return $optionsCount;
513 $allStatusIds = array();
514 if ($considerCounted) {
515 $countedStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
516 $allStatusIds = array_merge($allStatusIds, array_keys($countedStatuses));
518 if ($considerWaiting) {
519 $waitingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'");
520 $allStatusIds = array_merge($allStatusIds, array_keys($waitingStatuses));
522 $statusIdClause = NULL;
523 if (!empty($allStatusIds)) {
524 $statusIdClause = ' AND participant.status_id IN ( ' . implode(', ', array_values($allStatusIds)) . ')';
527 $isTestClause = NULL;
528 if (!$considerTestParticipants) {
529 $isTestClause = ' AND ( participant.is_test IS NULL OR participant.is_test = 0 )';
532 $skipParticipantClause = NULL;
533 if (is_array($skipParticipantIds) && !empty($skipParticipantIds)) {
534 $skipParticipantClause = ' AND participant.id NOT IN ( ' . implode(', ', $skipParticipantIds) . ')';
538 SELECT line.id as lineId,
539 line.entity_id as entity_id,
544 FROM civicrm_line_item line
545 INNER JOIN civicrm_participant participant ON ( line.entity_table = 'civicrm_participant'
546 AND participant.id = line.entity_id )
547 INNER JOIN civicrm_price_field_value value ON ( value.id = line.price_field_value_id )
548 INNER JOIN civicrm_price_field field ON ( value.price_field_id = field.id )
549 WHERE participant.event_id = %1
552 {$skipParticipantClause}";
554 $lineItem = CRM_Core_DAO
::executeQuery($sql, array(1 => array($eventId, 'Positive')));
555 while ($lineItem->fetch()) {
556 $count = $lineItem->count
;
560 if ($lineItem->html_type
== 'Text') {
561 $count *= $lineItem->qty
;
563 $optionsCount[$lineItem->valueId
] = $count + CRM_Utils_Array
::value($lineItem->valueId
, $optionsCount, 0);
566 return $optionsCount;
570 * Get the empty spaces for event those we can allocate
571 * to pending participant to become confirm.
573 * @param int $eventId
577 * $spaces Number of Empty Seats/null.
579 public static function pendingToConfirmSpaces($eventId) {
585 $positiveStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Positive'");
586 $statusIds = '(' . implode(',', array_keys($positiveStatuses)) . ')';
589 SELECT count(participant.id) as registered,
590 civicrm_event.max_participants
591 FROM civicrm_participant participant, civicrm_event
592 WHERE participant.event_id = {$eventId}
593 AND civicrm_event.id = participant.event_id
594 AND participant.status_id IN {$statusIds}
595 GROUP BY participant.event_id
597 $dao = CRM_Core_DAO
::executeQuery($query);
601 if ($dao->max_participants
== NULL ||
$dao->max_participants
<= 0) {
606 if ($dao->registered
>= $dao->max_participants
) {
611 return $dao->max_participants
- $dao->registered
;
614 //space in case no registeration yet.
615 return CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'max_participants');
619 * Combine all the importable fields from the lower levels object.
621 * @param string $contactType
622 * @param bool $status
623 * @param bool $onlyParticipant
624 * @param bool $checkPermission
625 * Is this a permissioned retrieval?
628 * array of importable Fields
630 public static function &importableFields($contactType = 'Individual', $status = TRUE, $onlyParticipant = FALSE, $checkPermission = TRUE) {
631 if (!self
::$_importableFields) {
632 if (!$onlyParticipant) {
634 $fields = array('' => array('title' => ts('- do not import -')));
637 $fields = array('' => array('title' => ts('- Participant Fields -')));
644 $tmpFields = CRM_Event_DAO_Participant
::import();
647 'participant_note' => array(
648 'title' => ts('Participant Note'),
649 'name' => 'participant_note',
650 'headerPattern' => '/(participant.)?note$/i',
654 // Split status and status id into 2 fields
655 // Fixme: it would be better to leave as 1 field and intelligently handle both during import
656 $participantStatus = array(
657 'participant_status' => array(
658 'title' => ts('Participant Status'),
659 'name' => 'participant_status',
660 'data_type' => CRM_Utils_Type
::T_STRING
,
663 $tmpFields['participant_status_id']['title'] = ts('Participant Status Id');
665 // Split role and role id into 2 fields
666 // Fixme: it would be better to leave as 1 field and intelligently handle both during import
667 $participantRole = array(
668 'participant_role' => array(
669 'title' => ts('Participant Role'),
670 'name' => 'participant_role',
671 'data_type' => CRM_Utils_Type
::T_STRING
,
674 $tmpFields['participant_role_id']['title'] = ts('Participant Role Id');
677 'event_type' => array(
678 'title' => ts('Event Type'),
679 'name' => 'event_type',
680 'data_type' => CRM_Utils_Type
::T_STRING
,
684 $tmpContactField = $contactFields = array();
685 $contactFields = array();
686 if (!$onlyParticipant) {
687 $contactFields = CRM_Contact_BAO_Contact
::importableFields($contactType, NULL);
689 // Using new Dedupe rule.
691 'contact_type' => $contactType,
692 'used' => 'Unsupervised',
694 $fieldsArray = CRM_Dedupe_BAO_Rule
::dedupeRuleFields($ruleParams);
696 if (is_array($fieldsArray)) {
697 foreach ($fieldsArray as $value) {
698 $customFieldId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField',
703 $value = $customFieldId ?
'custom_' . $customFieldId : $value;
704 $tmpContactField[trim($value)] = CRM_Utils_Array
::value(trim($value), $contactFields);
706 $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)';
709 $title = $tmpContactField[trim($value)]['title'];
712 $tmpContactField[trim($value)]['title'] = $title;
716 $extIdentifier = CRM_Utils_Array
::value('external_identifier', $contactFields);
717 if ($extIdentifier) {
718 $tmpContactField['external_identifier'] = $extIdentifier;
719 $tmpContactField['external_identifier']['title'] = CRM_Utils_Array
::value('title', $extIdentifier) . ' (match to contact)';
721 $tmpFields['participant_contact_id']['title'] = $tmpFields['participant_contact_id']['title'] . ' (match to contact)';
723 $fields = array_merge($fields, $tmpContactField);
724 $fields = array_merge($fields, $tmpFields);
725 $fields = array_merge($fields, $note, $participantStatus, $participantRole, $eventType);
726 $fields = array_merge($fields, CRM_Core_BAO_CustomField
::getFieldsForImport('Participant', FALSE, FALSE, FALSE, $checkPermission));
728 self
::$_importableFields = $fields;
731 return self
::$_importableFields;
735 * Combine all the exportable fields from the lower level objects.
737 * @param bool $checkPermission
740 * array of exportable Fields
742 public static function &exportableFields($checkPermission = TRUE) {
743 if (!self
::$_exportableFields) {
744 if (!self
::$_exportableFields) {
745 self
::$_exportableFields = array();
748 $participantFields = CRM_Event_DAO_Participant
::export();
749 $eventFields = CRM_Event_DAO_Event
::export();
751 'participant_note' => array(
752 'title' => 'Participant Note',
753 'name' => 'participant_note',
754 'type' => CRM_Utils_Type
::T_STRING
,
758 $participantStatus = array(
759 'participant_status' => array(
760 'title' => 'Participant Status',
761 'name' => 'participant_status',
762 'type' => CRM_Utils_Type
::T_STRING
,
766 $participantRole = array(
767 'participant_role' => array(
768 'title' => 'Participant Role',
769 'name' => 'participant_role',
770 'type' => CRM_Utils_Type
::T_STRING
,
774 $discountFields = CRM_Core_DAO_Discount
::export();
776 $fields = array_merge($participantFields, $participantStatus, $participantRole, $eventFields, $noteField, $discountFields);
779 $fields = array_merge($fields, CRM_Core_BAO_CustomField
::getFieldsForImport('Participant', FALSE, FALSE, FALSE, $checkPermission));
780 self
::$_exportableFields = $fields;
783 return self
::$_exportableFields;
787 * Get the event name/sort name for a particular participation / participant
789 * @param int $participantId
790 * Id of the participant.
793 * associated array with sort_name and event title
795 public static function participantDetails($participantId) {
797 SELECT civicrm_contact.sort_name as name, civicrm_event.title as title, civicrm_contact.id as cid
798 FROM civicrm_participant
799 LEFT JOIN civicrm_event ON (civicrm_participant.event_id = civicrm_event.id)
800 LEFT JOIN civicrm_contact ON (civicrm_participant.contact_id = civicrm_contact.id)
801 WHERE civicrm_participant.id = {$participantId}
803 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
806 while ($dao->fetch()) {
807 $details['name'] = $dao->name
;
808 $details['title'] = $dao->title
;
809 $details['cid'] = $dao->cid
;
816 * Get the values for pseudoconstants for name->value and reverse.
818 * @param array $defaults
819 * (reference) the default values, some of which need to be resolved.
820 * @param bool $reverse
821 * True if we want to resolve the values in the reverse direction (value -> name).
823 public static function resolveDefaults(&$defaults, $reverse = FALSE) {
824 self
::lookupValue($defaults, 'event', CRM_Event_PseudoConstant
::event(), $reverse);
825 self
::lookupValue($defaults, 'status', CRM_Event_PseudoConstant
::participantStatus(NULL, NULL, 'label'), $reverse);
826 self
::lookupValue($defaults, 'role', CRM_Event_PseudoConstant
::participantRole(), $reverse);
830 * Convert associative array names to values and vice-versa.
832 * This function is used by both the web form layer and the api. Note that
833 * the api needs the name => value conversion, also the view layer typically
834 * requires value => name conversion
836 * @param array $defaults
837 * @param string $property
838 * @param string $lookup
839 * @param bool $reverse
843 public static function lookupValue(&$defaults, $property, $lookup, $reverse) {
844 $id = $property . '_id';
846 $src = $reverse ?
$property : $id;
847 $dst = $reverse ?
$id : $property;
849 if (!array_key_exists($src, $defaults)) {
853 $look = $reverse ?
array_flip($lookup) : $lookup;
855 if (is_array($look)) {
856 if (!array_key_exists($defaults[$src], $look)) {
860 $defaults[$dst] = $look[$defaults[$src]];
865 * Delete the records that are associated with this participation.
868 * Id of the participation to delete.
870 * @return \CRM_Event_DAO_Participant
872 public static function deleteParticipant($id) {
873 CRM_Utils_Hook
::pre('delete', 'Participant', $id, CRM_Core_DAO
::$_nullArray);
875 $transaction = new CRM_Core_Transaction();
877 //delete activity record
879 'source_record_id' => $id,
880 // activity type id for event registration
881 'activity_type_id' => 5,
884 CRM_Activity_BAO_Activity
::deleteActivity($params);
886 // delete the participant payment record
887 // we need to do this since the cascaded constraints
888 // dont work with join tables
889 $p = array('participant_id' => $id);
890 CRM_Event_BAO_ParticipantPayment
::deleteParticipantPayment($p);
892 // cleanup line items.
893 $participantsId = array();
894 $participantsId = self
::getAdditionalParticipantIds($id);
895 $participantsId[] = $id;
896 CRM_Price_BAO_LineItem
::deleteLineItems($participantsId, 'civicrm_participant');
898 //delete note when participant deleted.
899 $note = CRM_Core_BAO_Note
::getNote($id, 'civicrm_participant');
900 $noteId = key($note);
902 CRM_Core_BAO_Note
::del($noteId, FALSE);
905 $participant = new CRM_Event_DAO_Participant();
906 $participant->id
= $id;
907 $participant->delete();
909 $transaction->commit();
911 CRM_Utils_Hook
::post('delete', 'Participant', $participant->id
, $participant);
913 // delete the recently created Participant
914 $participantRecent = array(
916 'type' => 'Participant',
919 CRM_Utils_Recent
::del($participantRecent);
925 * Checks duplicate participants.
927 * @param array $input
928 * An assosiative array of name /value pairs.
929 * from other function
930 * @param array $duplicates
931 * (reference ) an assoc array of name/value pairs.
933 * @return CRM_Contribute_BAO_Contribution
935 public static function checkDuplicate($input, &$duplicates) {
936 $eventId = CRM_Utils_Array
::value('event_id', $input);
937 $contactId = CRM_Utils_Array
::value('contact_id', $input);
943 $clause[] = "event_id = %1";
944 $input[1] = array($eventId, 'Integer');
948 $clause[] = "contact_id = %2";
949 $input[2] = array($contactId, 'Integer');
952 if (empty($clause)) {
956 $clause = implode(' AND ', $clause);
958 $query = "SELECT id FROM civicrm_participant WHERE $clause";
959 $dao = CRM_Core_DAO
::executeQuery($query, $input);
961 while ($dao->fetch()) {
962 $duplicates[] = $dao->id
;
969 * Fix the event level.
971 * When price sets are used as event fee, fee_level is set as ^A
972 * separated string. We need to change that string to comma
973 * separated string before using fee_level in view mode.
975 * @param string $eventLevel
976 * Event_level string from db.
978 public static function fixEventLevel(&$eventLevel) {
979 if ((substr($eventLevel, 0, 1) == CRM_Core_DAO
::VALUE_SEPARATOR
) &&
980 (substr($eventLevel, -1, 1) == CRM_Core_DAO
::VALUE_SEPARATOR
)
982 $eventLevel = implode(', ', explode(CRM_Core_DAO
::VALUE_SEPARATOR
, substr($eventLevel, 1, -1)));
983 $pos = strrpos($eventLevel, '(multiple participants)', 0);
985 $eventLevel = substr_replace($eventLevel, "", $pos - 3, 1);
988 elseif ((substr($eventLevel, 0, 1) == CRM_Core_DAO
::VALUE_SEPARATOR
)) {
989 $eventLevel = implode(', ', explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
990 substr($eventLevel, 0, 1)
993 elseif ((substr($eventLevel, -1, 1) == CRM_Core_DAO
::VALUE_SEPARATOR
)) {
994 $eventLevel = implode(', ', explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
995 substr($eventLevel, 0, -1)
1001 * Get the additional participant ids.
1003 * @param int $primaryParticipantId
1004 * Primary partycipant Id.
1005 * @param bool $excludeCancel
1006 * Do not include participant those are cancelled.
1008 * @param int $oldStatusId
1012 public static function getAdditionalParticipantIds($primaryParticipantId, $excludeCancel = TRUE, $oldStatusId = NULL) {
1013 $additionalParticipantIds = array();
1014 if (!$primaryParticipantId) {
1015 return $additionalParticipantIds;
1018 $where = "participant.registered_by_id={$primaryParticipantId}";
1019 if ($excludeCancel) {
1020 $cancelStatusId = 0;
1021 $negativeStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
1022 $cancelStatusId = array_search('Cancelled', $negativeStatuses);
1023 $where .= " AND participant.status_id != {$cancelStatusId}";
1027 $where .= " AND participant.status_id = {$oldStatusId}";
1031 SELECT participant.id
1032 FROM civicrm_participant participant
1035 $dao = CRM_Core_DAO
::executeQuery($query);
1036 while ($dao->fetch()) {
1037 $additionalParticipantIds[$dao->id
] = $dao->id
;
1039 return $additionalParticipantIds;
1043 * Get the event fee info for given participant ids
1044 * either from line item table / participant table.
1046 * @param array $participantIds
1048 * @param bool $hasLineItems
1049 * Do fetch from line items.
1053 public function getFeeDetails($participantIds, $hasLineItems = FALSE) {
1054 $feeDetails = array();
1055 if (!is_array($participantIds) ||
empty($participantIds)) {
1060 SELECT participant.id as id,
1061 participant.fee_level as fee_level,
1062 participant.fee_amount as fee_amount';
1063 $from = 'FROM civicrm_participant participant';
1064 if ($hasLineItems) {
1066 lineItem.id as lineId,
1067 lineItem.label as label,
1068 lineItem.qty as qty,
1069 lineItem.unit_price as unit_price,
1070 lineItem.line_total as line_total,
1071 field.label as field_title,
1072 field.html_type as html_type,
1073 field.id as price_field_id,
1074 value.id as price_field_value_id,
1075 value.description as description,
1076 IF( value.count, value.count, 0 ) as participant_count';
1078 INNER JOIN civicrm_line_item lineItem ON ( lineItem.entity_table = 'civicrm_participant'
1079 AND lineItem.entity_id = participant.id )
1080 INNER JOIN civicrm_price_field field ON ( field.id = lineItem.price_field_id )
1081 INNER JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id )
1084 $where = 'WHERE participant.id IN ( ' . implode(', ', $participantIds) . ' )';
1085 $query = "$select $from $where";
1087 $feeInfo = CRM_Core_DAO
::executeQuery($query);
1088 $feeProperties = array('fee_level', 'fee_amount');
1089 $lineProperties = array(
1098 'participant_count',
1099 'price_field_value_id',
1102 while ($feeInfo->fetch()) {
1103 if ($hasLineItems) {
1104 foreach ($lineProperties as $property) {
1105 $feeDetails[$feeInfo->id
][$feeInfo->lineId
][$property] = $feeInfo->$property;
1109 foreach ($feeProperties as $property) {
1110 $feeDetails[$feeInfo->id
][$property] = $feeInfo->$property;
1119 * Retrieve additional participants display-names and URL to view their participant records.
1120 * (excludes cancelled participants automatically)
1122 * @param int $primaryParticipantID
1123 * Id of primary participant record.
1126 * $displayName => $viewUrl
1128 public static function getAdditionalParticipants($primaryParticipantID) {
1129 $additionalParticipantIDs = array();
1130 $additionalParticipantIDs = self
::getAdditionalParticipantIds($primaryParticipantID);
1131 if (!empty($additionalParticipantIDs)) {
1132 foreach ($additionalParticipantIDs as $additionalParticipantID) {
1133 $additionalContactID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
1134 $additionalParticipantID,
1137 $additionalContactName = CRM_Contact_BAO_Contact
::displayName($additionalContactID);
1138 $pViewURL = CRM_Utils_System
::url('civicrm/contact/view/participant',
1139 "action=view&reset=1&id={$additionalParticipantID}&cid={$additionalContactID}"
1142 $additionalParticipants[$additionalContactName] = $pViewURL;
1145 return $additionalParticipants;
1149 * Function for update primary and additional participant status.
1151 * @param int $participantID
1152 * Primary participant's id.
1153 * @param int $oldStatusID
1154 * @param int $newStatusID
1155 * @param bool $updatePrimaryStatus
1159 public static function updateParticipantStatus($participantID, $oldStatusID, $newStatusID = NULL, $updatePrimaryStatus = FALSE) {
1160 if (!$participantID ||
!$oldStatusID) {
1164 if (!$newStatusID) {
1165 $newStatusID = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $participantID, 'status_id');
1167 elseif ($updatePrimaryStatus) {
1168 CRM_Core_DAO
::setFieldValue('CRM_Event_DAO_Participant', $participantID, 'status_id', $newStatusID);
1171 $cascadeAdditionalIds = self
::getValidAdditionalIds($participantID, $oldStatusID, $newStatusID);
1173 if (!empty($cascadeAdditionalIds)) {
1174 $cascadeAdditionalIds = implode(',', $cascadeAdditionalIds);
1175 $query = "UPDATE civicrm_participant cp SET cp.status_id = %1 WHERE cp.id IN ({$cascadeAdditionalIds})";
1176 $params = array(1 => array($newStatusID, 'Integer'));
1177 $dao = CRM_Core_DAO
::executeQuery($query, $params);
1184 * Function for update status for given participant ids.
1186 * @param int $participantIds
1187 * Array of participant ids.
1188 * @param int $statusId
1189 * Status id for participant.
1190 * @param bool $updateRegisterDate
1192 public static function updateStatus($participantIds, $statusId, $updateRegisterDate = FALSE) {
1193 if (!is_array($participantIds) ||
empty($participantIds) ||
!$statusId) {
1197 //lets update register date as we update status to keep track
1198 //when we did update status, useful for moving participant
1199 //from pending to expired.
1200 $setClause = "status_id = {$statusId}";
1201 if ($updateRegisterDate) {
1202 $setClause .= ", register_date = NOW()";
1205 $participantIdClause = '( ' . implode(',', $participantIds) . ' )';
1208 UPDATE civicrm_participant
1210 WHERE id IN {$participantIdClause}";
1212 $dao = CRM_Core_DAO
::executeQuery($query);
1216 * Function takes participant ids and statuses
1217 * update status from $fromStatusId to $toStatusId
1218 * and send mail + create activities.
1220 * @param array $participantIds
1222 * @param int $toStatusId
1224 * @param int $fromStatusId
1226 * @param bool $returnResult
1227 * @param bool $skipCascadeRule
1229 * @return array|NULL
1231 public static function transitionParticipants(
1232 $participantIds, $toStatusId,
1233 $fromStatusId = NULL, $returnResult = FALSE, $skipCascadeRule = FALSE
1235 if (!is_array($participantIds) ||
empty($participantIds) ||
!$toStatusId) {
1239 //thumb rule is if we triggering primary participant need to triggered additional
1240 $allParticipantIds = $primaryANDAdditonalIds = array();
1241 foreach ($participantIds as $id) {
1242 $allParticipantIds[] = $id;
1243 if (self
::isPrimaryParticipant($id)) {
1244 //filter additional as per status transition rules, CRM-5403
1245 if ($skipCascadeRule) {
1246 $additionalIds = self
::getAdditionalParticipantIds($id);
1249 $additionalIds = self
::getValidAdditionalIds($id, $fromStatusId, $toStatusId);
1251 if (!empty($additionalIds)) {
1252 $allParticipantIds = array_merge($allParticipantIds, $additionalIds);
1253 $primaryANDAdditonalIds[$id] = $additionalIds;
1258 //get the unique participant ids,
1259 $allParticipantIds = array_unique($allParticipantIds);
1261 //pull required participants, contacts, events data, if not in hand
1262 static $eventDetails = array();
1263 static $domainValues = array();
1264 static $contactDetails = array();
1266 $contactIds = $eventIds = $participantDetails = array();
1268 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
1269 $participantRoles = CRM_Event_PseudoConstant
::participantRole();
1270 $pendingStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL,
1274 //first thing is pull all necessory data from db.
1275 $participantIdClause = '(' . implode(',', $allParticipantIds) . ')';
1277 //get all participants data.
1278 $query = "SELECT * FROM civicrm_participant WHERE id IN {$participantIdClause}";
1279 $dao = CRM_Core_DAO
::executeQuery($query);
1280 while ($dao->fetch()) {
1281 $participantDetails[$dao->id
] = array(
1283 'role' => $participantRoles[$dao->role_id
],
1284 'is_test' => $dao->is_test
,
1285 'event_id' => $dao->event_id
,
1286 'status_id' => $dao->status_id
,
1287 'fee_amount' => $dao->fee_amount
,
1288 'contact_id' => $dao->contact_id
,
1289 'register_date' => $dao->register_date
,
1290 'registered_by_id' => $dao->registered_by_id
,
1292 if (!array_key_exists($dao->contact_id
, $contactDetails)) {
1293 $contactIds[$dao->contact_id
] = $dao->contact_id
;
1296 if (!array_key_exists($dao->event_id
, $eventDetails)) {
1297 $eventIds[$dao->event_id
] = $dao->event_id
;
1301 //get the domain values.
1302 if (empty($domainValues)) {
1303 // making all tokens available to templates.
1304 $domain = CRM_Core_BAO_Domain
::getDomain();
1306 'domain' => array('name', 'phone', 'address', 'email'),
1307 'contact' => CRM_Core_SelectValues
::contactTokens(),
1310 foreach ($tokens['domain'] as $token) {
1311 $domainValues[$token] = CRM_Utils_Token
::getDomainTokenReplacement($token, $domain);
1315 //get all required contacts detail.
1316 if (!empty($contactIds)) {
1317 // get the contact details.
1318 list($currentContactDetails) = CRM_Utils_Token
::getTokenDetails($contactIds, NULL,
1321 'CRM_Event_BAO_Participant'
1323 foreach ($currentContactDetails as $contactId => $contactValues) {
1324 $contactDetails[$contactId] = $contactValues;
1328 //get all required events detail.
1329 if (!empty($eventIds)) {
1330 foreach ($eventIds as $eventId) {
1331 //retrieve event information
1332 $eventParams = array('id' => $eventId);
1333 CRM_Event_BAO_Event
::retrieve($eventParams, $eventDetails[$eventId]);
1335 //get default participant role.
1336 $eventDetails[$eventId]['participant_role'] = CRM_Utils_Array
::value($eventDetails[$eventId]['default_role_id'], $participantRoles);
1338 //get the location info
1339 $locParams = array('entity_id' => $eventId, 'entity_table' => 'civicrm_event');
1340 $eventDetails[$eventId]['location'] = CRM_Core_BAO_Location
::getValues($locParams, TRUE);
1344 //now we are ready w/ all required data.
1345 //take a decision as per statuses.
1348 $toStatus = $statusTypes[$toStatusId];
1349 $fromStatus = CRM_Utils_Array
::value($fromStatusId, $statusTypes);
1351 switch ($toStatus) {
1352 case 'Pending from waitlist':
1353 case 'Pending from approval':
1354 switch ($fromStatus) {
1356 case 'Awaiting approval':
1357 $emailType = 'Confirm';
1363 //no matter from where u come send expired mail.
1364 $emailType = $toStatus;
1368 //no matter from where u come send cancel mail.
1369 $emailType = $toStatus;
1373 //as we process additional w/ primary, there might be case if user
1374 //select primary as well as additionals, so avoid double processing.
1375 $processedParticipantIds = array();
1376 $mailedParticipants = array();
1378 //send mails and update status.
1379 foreach ($participantDetails as $participantId => $participantValues) {
1380 $updateParticipantIds = array();
1381 if (in_array($participantId, $processedParticipantIds)) {
1385 //check is it primary and has additional.
1386 if (array_key_exists($participantId, $primaryANDAdditonalIds)) {
1387 foreach ($primaryANDAdditonalIds[$participantId] as $additonalId) {
1390 $mail = self
::sendTransitionParticipantMail($additonalId,
1391 $participantDetails[$additonalId],
1392 $eventDetails[$participantDetails[$additonalId]['event_id']],
1393 $contactDetails[$participantDetails[$additonalId]['contact_id']],
1398 //get the mail participant ids
1400 $mailedParticipants[$additonalId] = $contactDetails[$participantDetails[$additonalId]['contact_id']]['display_name'];
1403 $updateParticipantIds[] = $additonalId;
1404 $processedParticipantIds[] = $additonalId;
1408 //now send email appropriate mail to primary.
1410 $mail = self
::sendTransitionParticipantMail($participantId,
1412 $eventDetails[$participantValues['event_id']],
1413 $contactDetails[$participantValues['contact_id']],
1418 //get the mail participant ids
1420 $mailedParticipants[$participantId] = $contactDetails[$participantValues['contact_id']]['display_name'];
1424 //now update status of group/one at once.
1425 $updateParticipantIds[] = $participantId;
1427 //update the register date only when we,
1428 //move participant to pending class, CRM-6496
1429 $updateRegisterDate = FALSE;
1430 if (array_key_exists($toStatusId, $pendingStatuses)) {
1431 $updateRegisterDate = TRUE;
1433 self
::updateStatus($updateParticipantIds, $toStatusId, $updateRegisterDate);
1434 $processedParticipantIds[] = $participantId;
1437 //return result for cron.
1438 if ($returnResult) {
1440 'mailedParticipants' => $mailedParticipants,
1441 'updatedParticipantIds' => $processedParticipantIds,
1449 * Send mail and create activity
1450 * when participant status changed.
1452 * @param int $participantId
1454 * @param array $participantValues
1455 * Participant detail values. status id for participants.
1456 * @param array $eventDetails
1457 * Required event details.
1458 * @param array $contactDetails
1459 * Required contact details.
1460 * @param array $domainValues
1461 * Required domain values.
1462 * @param string $mailType
1463 * (eg 'approval', 'confirm', 'expired' ).
1467 public static function sendTransitionParticipantMail(
1478 //don't send confirmation mail to additional
1479 //since only primary able to confirm registration.
1480 if (!empty($participantValues['registered_by_id']) &&
1481 $mailType == 'Confirm'
1485 $toEmail = CRM_Utils_Array
::value('email', $contactDetails);
1488 $contactId = $participantValues['contact_id'];
1489 $participantName = $contactDetails['display_name'];
1491 //calculate the checksum value.
1492 $checksumValue = NULL;
1493 if ($mailType == 'Confirm' && !$participantValues['registered_by_id']) {
1494 $checksumLife = 'inf';
1495 $endDate = CRM_Utils_Array
::value('end_date', $eventDetails);
1497 $checksumLife = (CRM_Utils_Date
::unixTime($endDate) - time()) / (60 * 60);
1499 $checksumValue = CRM_Contact_BAO_Contact_Utils
::generateChecksum($contactId, NULL, $checksumLife);
1502 //take a receipt from as event else domain.
1503 $receiptFrom = $domainValues['name'] . ' <' . $domainValues['email'] . '>';
1504 if (!empty($eventDetails['confirm_from_name']) && !empty($eventDetails['confirm_from_email'])) {
1505 $receiptFrom = $eventDetails['confirm_from_name'] . ' <' . $eventDetails['confirm_from_email'] . '>';
1508 list($mailSent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate(
1510 'groupName' => 'msg_tpl_workflow_event',
1511 'valueName' => 'participant_' . strtolower($mailType),
1512 'contactId' => $contactId,
1513 'tplParams' => array(
1514 'contact' => $contactDetails,
1515 'domain' => $domainValues,
1516 'participant' => $participantValues,
1517 'event' => $eventDetails,
1518 'paidEvent' => CRM_Utils_Array
::value('is_monetary', $eventDetails),
1519 'isShowLocation' => CRM_Utils_Array
::value('is_show_location', $eventDetails),
1520 'isAdditional' => $participantValues['registered_by_id'],
1521 'isExpired' => $mailType == 'Expired',
1522 'isConfirm' => $mailType == 'Confirm',
1523 'checksumValue' => $checksumValue,
1525 'from' => $receiptFrom,
1526 'toName' => $participantName,
1527 'toEmail' => $toEmail,
1528 'cc' => CRM_Utils_Array
::value('cc_confirm', $eventDetails),
1529 'bcc' => CRM_Utils_Array
::value('bcc_confirm', $eventDetails),
1533 // 3. create activity record.
1535 $now = date('YmdHis');
1536 $activityType = 'Event Registration';
1537 $activityParams = array(
1538 'subject' => $subject,
1539 'source_contact_id' => $contactId,
1540 'source_record_id' => $participantId,
1541 'activity_type_id' => CRM_Core_OptionGroup
::getValue('activity_type',
1545 'activity_date_time' => CRM_Utils_Date
::isoToMysql($now),
1546 'due_date_time' => CRM_Utils_Date
::isoToMysql($participantValues['register_date']),
1547 'is_test' => $participantValues['is_test'],
1551 if (is_a(CRM_Activity_BAO_Activity
::create($activityParams), 'CRM_Core_Error')) {
1552 CRM_Core_Error
::fatal('Failed creating Activity for expiration mail');
1561 * Get participant status change message.
1563 * @param int $participantId
1564 * @param $statusChangeTo
1565 * @param int $fromStatusId
1569 public function updateStatusMessage($participantId, $statusChangeTo, $fromStatusId) {
1571 $results = self
::transitionParticipants(array($participantId),
1572 $statusChangeTo, $fromStatusId, TRUE
1575 $allStatuses = CRM_Event_PseudoConstant
::participantStatus();
1576 //give user message only when mail has sent.
1577 if (is_array($results) && !empty($results)) {
1578 if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
1579 foreach ($results['updatedParticipantIds'] as $processedId) {
1580 if (is_array($results['mailedParticipants']) &&
1581 array_key_exists($processedId, $results['mailedParticipants'])
1583 $statusMsg .= '<br /> ' . ts("Participant status has been updated to '%1'. An email has been sent to %2.",
1585 1 => $allStatuses[$statusChangeTo],
1586 2 => $results['mailedParticipants'][$processedId],
1598 * Get event full and waiting list message.
1600 * @param int $eventId
1601 * @param int $participantId
1605 public static function eventFullMessage($eventId, $participantId = NULL) {
1606 $eventfullMsg = $dbStatusId = NULL;
1607 $checkEventFull = TRUE;
1608 if ($participantId) {
1609 $dbStatusId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id');
1610 if (array_key_exists($dbStatusId, CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1'))) {
1611 //participant already in counted status no need to check for event full messages.
1612 $checkEventFull = FALSE;
1617 if (!$eventId ||
!$checkEventFull) {
1618 return $eventfullMsg;
1621 //event is truly full.
1622 $emptySeats = self
::eventFull($eventId, FALSE, FALSE);
1623 if (is_string($emptySeats) && $emptySeats !== NULL) {
1624 $maxParticipants = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $eventId, 'max_participants');
1625 $eventfullMsg = ts("This event currently has the maximum number of participants registered (%1). However, you can still override this limit and register additional participants using this form.", array(
1626 1 => $maxParticipants,
1630 $hasWaiting = FALSE;
1631 $waitListedCount = self
::eventFull($eventId, FALSE, TRUE, TRUE);
1632 if (is_numeric($waitListedCount)) {
1634 //only current processing participant is on waitlist.
1635 if ($waitListedCount == 1 && CRM_Event_PseudoConstant
::participantStatus($dbStatusId) == 'On waitlist') {
1636 $hasWaiting = FALSE;
1641 $waitingStatusId = array_search('On waitlist',
1642 CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Waiting'")
1644 $viewWaitListUrl = CRM_Utils_System
::url('civicrm/event/search',
1645 "reset=1&force=1&event={$eventId}&status={$waitingStatusId}"
1648 $eventfullMsg .= ts("There are %2 people currently on the waiting list for this event. You can <a href='%1'>view waitlisted registrations here</a>, or you can continue and register additional participants using this form.",
1650 1 => $viewWaitListUrl,
1651 2 => $waitListedCount,
1656 return $eventfullMsg;
1660 * Check for whether participant is primary or not.
1662 * @param int $participantId
1665 * true if participant is primary
1667 public static function isPrimaryParticipant($participantId) {
1669 $participant = new CRM_Event_DAO_Participant();
1670 $participant->registered_by_id
= $participantId;
1672 if ($participant->find(TRUE)) {
1679 * Get additional participant Ids for cascading with primary participant status.
1681 * @param int $participantId
1683 * @param int $oldStatusId
1685 * @param int $newStatusId
1691 public static function getValidAdditionalIds($participantId, $oldStatusId, $newStatusId) {
1693 $additionalParticipantIds = array();
1695 static $participantStatuses = array();
1697 if (empty($participantStatuses)) {
1698 $participantStatuses = CRM_Event_PseudoConstant
::participantStatus();
1701 if (CRM_Utils_Array
::value($participantStatuses[$oldStatusId], self
::$_statusTransitionsRules) &&
1702 in_array($participantStatuses[$newStatusId], self
::$_statusTransitionsRules[$participantStatuses[$oldStatusId]])
1704 $additionalParticipantIds = self
::getAdditionalParticipantIds($participantId, TRUE, $oldStatusId);
1707 return $additionalParticipantIds;
1711 * Get participant record count for a Contact.
1713 * @param int $contactID
1716 * count of participant records
1718 public static function getContactParticipantCount($contactID) {
1719 $query = "SELECT count(*)
1720 FROM civicrm_participant
1721 WHERE civicrm_participant.contact_id = {$contactID} AND
1722 civicrm_participant.is_test = 0";
1723 return CRM_Core_DAO
::singleValueQuery($query);
1727 * Get participant ids by contribution id.
1729 * @param int $contributionId
1731 * @param bool $excludeCancelled
1732 * Exclude cancelled additional participant.
1736 public static function getParticipantIds($contributionId, $excludeCancelled = FALSE) {
1739 if (!$contributionId) {
1743 // get primary participant id
1744 $query = "SELECT participant_id FROM civicrm_participant_payment WHERE contribution_id = {$contributionId}";
1745 $participantId = CRM_Core_DAO
::singleValueQuery($query);
1747 // get additional participant ids (including cancelled)
1748 if ($participantId) {
1749 $ids = array_merge(array(
1751 ), self
::getAdditionalParticipantIds($participantId,
1760 * Get additional Participant edit & view url .
1762 * @param array $participantIds
1763 * An array of additional participant ids.
1768 public static function getAdditionalParticipantUrl($participantIds) {
1769 foreach ($participantIds as $value) {
1771 $details = self
::participantDetails($value);
1772 $viewUrl = CRM_Utils_System
::url('civicrm/contact/view/participant',
1773 "action=view&reset=1&id={$value}&cid={$details['cid']}"
1775 $editUrl = CRM_Utils_System
::url('civicrm/contact/view/participant',
1776 "action=update&reset=1&id={$value}&cid={$details['cid']}"
1778 $links[] = "<td><a href='{$viewUrl}'>" . $details['name'] . "</a></td><td></td><td><a href='{$editUrl}'>" . ts('Edit') . "</a></td>";
1779 $links = "<table><tr>" . implode("</tr><tr>", $links) . "</tr></table>";
1785 * create trxn entry if an event has discount.
1787 * @param int $eventID
1789 * @param array $contributionParams
1790 * Contribution params.
1795 public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel) {
1797 $checkDiscount = CRM_Core_BAO_Discount
::findSet($eventID, 'civicrm_event');
1798 if (!empty($checkDiscount)) {
1799 $feeLevel = current($feeLevel);
1800 $priceSetId = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $eventID, NULL);
1801 $query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv
1802 LEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id
1803 WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
1805 1 => array($priceSetId, 'Integer'),
1806 2 => array($feeLevel, 'String'),
1808 $mainAmount = CRM_Core_DAO
::singleValueQuery($query, $params);
1809 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
1810 $contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant
::financialAccountType(
1811 $contributionParams['contribution']->financial_type_id
, $relationTypeId);
1812 if (!empty($contributionParams['trxnParams']['from_financial_account_id'])) {
1813 $contributionParams['trxnParams']['total_amount'] = $mainAmount - $contributionParams['total_amount'];
1814 $contributionParams['trxnParams']['payment_processor_id'] = NULL;
1815 $contributionParams['trxnParams']['payment_instrument_id'] = NULL;
1816 $contributionParams['trxnParams']['check_number'] = NULL;
1817 $contributionParams['trxnParams']['trxn_id'] = NULL;
1818 $contributionParams['trxnParams']['net_amount'] = NULL;
1819 $contributionParams['trxnParams']['fee_amount'] = NULL;
1821 CRM_Core_BAO_FinancialTrxn
::create($contributionParams['trxnParams']);
1827 * Delete participants of contact.
1831 * @param int $contactId
1835 public static function deleteContactParticipant($contactId) {
1836 $participant = new CRM_Event_DAO_Participant();
1837 $participant->contact_id
= $contactId;
1838 $participant->find();
1839 while ($participant->fetch()) {
1840 self
::deleteParticipant($participant->id
);
1845 * @param array $params
1846 * @param int $participantId
1847 * @param int $contributionId
1849 * @param array $lineItems
1850 * @param $paidAmount
1851 * @param int $priceSetId
1853 public static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId) {
1854 $contributionStatuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
1855 $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
1856 $pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
1857 $previousLineItems = CRM_Price_BAO_LineItem
::getLineItems($participantId, 'participant');
1858 CRM_Price_BAO_PriceSet
::processAmount($feeBlock,
1862 // get the submitted
1863 foreach ($feeBlock as $id => $values) {
1864 CRM_Price_BAO_LineItem
::format($id, $params, $values, $submittedLineItems);
1865 $submittedFieldId[] = CRM_Utils_Array
::retrieveValueRecursive($submittedLineItems, 'price_field_id');
1867 if (!empty($submittedLineItems)) {
1868 $insertLines = $submittedLineItems;
1870 $submittedFieldValueIds = array_keys($submittedLineItems);
1871 $updateLines = array();
1872 foreach ($previousLineItems as $id => $previousLineItem) {
1873 // check through the submitted items if the previousItem exists,
1874 // if found in submitted items, do not use it for new item creations
1875 if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
1876 // if submitted line items are existing don't fire INSERT query
1877 unset($insertLines[$previousLineItem['price_field_value_id']]);
1878 // for updating the line items i.e. use-case - once deselect-option selecting again
1879 if (($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) ||
1880 ($submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] == 0 && $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'] == 1) ||
1881 ($previousLineItem['qty'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'])
1883 $updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
1884 $updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
1889 $submittedFields = implode(', ', $submittedFieldId);
1890 $submittedFieldValues = implode(', ', $submittedFieldValueIds);
1892 if (!empty($submittedFields) && !empty($submittedFieldValues)) {
1893 $updateLineItem = "UPDATE civicrm_line_item li
1894 INNER JOIN civicrm_financial_item fi
1895 ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')
1897 li.line_total = 0.00,
1898 li.tax_amount = NULL
1899 WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND
1900 (price_field_value_id NOT IN ({$submittedFieldValues}))
1902 CRM_Core_DAO
::executeQuery($updateLineItem);
1904 // gathering necessary info to record negative (deselected) financial_item
1905 $updateFinancialItem = "
1906 SELECT fi.*, SUM(fi.amount) as differenceAmt, price_field_value_id, financial_type_id, tax_amount
1907 FROM civicrm_financial_item fi LEFT JOIN civicrm_line_item li ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')
1908 WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})
1909 GROUP BY li.entity_table, li.entity_id, price_field_value_id
1911 $updateFinancialItemInfoDAO = CRM_Core_DAO
::executeQuery($updateFinancialItem);
1912 $trxn = CRM_Core_BAO_FinancialTrxn
::getFinancialTrxnId($contributionId, 'DESC', TRUE);
1913 $trxnId['id'] = $trxn['financialTrxnId'];
1914 $invoiceSettings = Civi
::settings()->get('contribution_invoice_settings');
1915 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
1916 $updateFinancialItemInfoValues = array();
1917 $financialItemsArray = array();
1918 while ($updateFinancialItemInfoDAO->fetch()) {
1919 $updateFinancialItemInfoValues = (array) $updateFinancialItemInfoDAO;
1920 $updateFinancialItemInfoValues['transaction_date'] = date('YmdHis');
1921 // the below params are not needed
1922 unset($updateFinancialItemInfoValues['id']);
1923 unset($updateFinancialItemInfoValues['created_date']);
1924 // if not submitted and difference is not 0 make it negative
1925 if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
1926 // INSERT negative financial_items
1927 $updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
1928 if ($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']) {
1929 $updateFinancialItemInfoValues['tax']['amount'] = -($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']);
1930 $updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
1931 if ($updateFinancialItemInfoValues['financial_type_id']) {
1932 $updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution
::getFinancialAccountId($updateFinancialItemInfoValues['financial_type_id']);
1935 // INSERT negative financial_items for tax amount
1936 $financialItemsArray[] = $updateFinancialItemInfoValues;
1938 // if submitted and difference is 0 add a positive entry again
1939 elseif (in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] == 0) {
1940 $updateFinancialItemInfoValues['amount'] = $updateFinancialItemInfoValues['amount'];
1941 // INSERT financial_items for tax amount
1942 if ($updateFinancialItemInfoValues['entity_id'] == $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['id'] &&
1943 isset($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'])
1945 $updateFinancialItemInfoValues['tax']['amount'] = $updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['tax_amount'];
1946 $updateFinancialItemInfoValues['tax']['description'] = $taxTerm;
1947 if ($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']) {
1948 $updateFinancialItemInfoValues['tax']['financial_account_id'] = CRM_Contribute_BAO_Contribution
::getFinancialAccountId($updateLines[$updateFinancialItemInfoValues['price_field_value_id']]['financial_type_id']);
1951 $financialItemsArray[] = $updateFinancialItemInfoValues;
1955 elseif (empty($submittedFields) && empty($submittedFieldValues)) {
1956 $updateLineItem = "UPDATE civicrm_line_item li
1957 INNER JOIN civicrm_financial_item fi
1958 ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')
1960 li.line_total = 0.00,
1961 li.tax_amount = NULL
1962 WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})";
1963 CRM_Core_DAO
::executeQuery($updateLineItem);
1965 $amountLevel = array();
1966 $totalParticipant = $participantCount = 0;
1967 if (!empty($updateLines)) {
1968 foreach ($updateLines as $valueId => $vals) {
1969 $taxAmount = "NULL";
1970 if (isset($vals['tax_amount'])) {
1971 $taxAmount = $vals['tax_amount'];
1973 $amountLevel[] = $vals['label'] . ' - ' . (float) $vals['qty'];
1974 if (isset($vals['participant_count'])) {
1975 $participantCount = $vals['participant_count'];
1976 $totalParticipant +
= $vals['participant_count'];
1979 UPDATE civicrm_line_item li
1980 SET li.qty = {$vals['qty']},
1981 li.line_total = {$vals['line_total']},
1982 li.tax_amount = {$taxAmount},
1983 li.unit_price = {$vals['unit_price']},
1984 li.participant_count = {$participantCount},
1986 WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId}) AND
1987 (price_field_value_id = {$valueId})
1989 CRM_Core_DAO
::executeQuery($updateLineItem, array(1 => array($vals['label'], 'String')));
1992 // insert new 'adjusted amount' transaction entry and update contribution entry.
1993 // ensure entity_financial_trxn table has a linking of it.
1994 // insert new line items
1995 if (!empty($insertLines)) {
1996 foreach ($insertLines as $valueId => $lineParams) {
1997 $lineParams['entity_table'] = 'civicrm_participant';
1998 $lineParams['entity_id'] = $participantId;
1999 $lineParams['contribution_id'] = $contributionId;
2000 $lineObj = CRM_Price_BAO_LineItem
::create($lineParams);
2004 // the recordAdjustedAmt code would execute over here
2005 $ids = CRM_Event_BAO_Participant
::getParticipantIds($contributionId);
2006 if (count($ids) > 1) {
2008 foreach ($ids as $val) {
2009 $total +
= CRM_Price_BAO_LineItem
::getLineTotal($val, 'civicrm_participant');
2011 $updatedAmount = $total;
2014 $updatedAmount = $params['amount'];
2016 if (strlen($params['tax_amount']) != 0) {
2017 $taxAmount = $params['tax_amount'];
2020 $taxAmount = "NULL";
2022 $displayParticipantCount = '';
2023 if ($totalParticipant > 0) {
2024 $displayParticipantCount = ' Participant Count -' . $totalParticipant;
2026 $updateAmountLevel = NULL;
2027 if (!empty($amountLevel)) {
2028 $updateAmountLevel = CRM_Core_DAO
::VALUE_SEPARATOR
. implode(CRM_Core_DAO
::VALUE_SEPARATOR
, $amountLevel) . $displayParticipantCount . CRM_Core_DAO
::VALUE_SEPARATOR
;
2030 $trxn = self
::recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount, $updateAmountLevel);
2033 $trxnId['id'] = $trxn->id
;
2034 foreach ($financialItemsArray as $updateFinancialItemInfoValues) {
2035 CRM_Financial_BAO_FinancialItem
::create($updateFinancialItemInfoValues, NULL, $trxnId);
2036 if (!empty($updateFinancialItemInfoValues['tax'])) {
2037 $updateFinancialItemInfoValues['tax']['amount'] = $updateFinancialItemInfoValues['amount'];
2038 $updateFinancialItemInfoValues['tax']['description'] = $updateFinancialItemInfoValues['description'];
2039 if (!empty($updateFinancialItemInfoValues['financial_account_id'])) {
2040 $updateFinancialItemInfoValues['financial_account_id'] = $updateFinancialItemInfoValues['tax']['financial_account_id'];
2042 CRM_Financial_BAO_FinancialItem
::create($updateFinancialItemInfoValues, NULL, $trxnId);
2046 $fetchCon = array('id' => $contributionId);
2047 $updatedContribution = CRM_Contribute_BAO_Contribution
::retrieve($fetchCon, CRM_Core_DAO
::$_nullArray, CRM_Core_DAO
::$_nullArray);
2048 // insert financial items
2049 if (!empty($insertLines)) {
2050 foreach ($insertLines as $valueId => $lineParams) {
2051 $lineParams['entity_table'] = 'civicrm_participant';
2052 $lineParams['entity_id'] = $participantId;
2053 $lineObj = CRM_Price_BAO_LineItem
::retrieve($lineParams, CRM_Core_DAO
::$_nullArray);
2054 // insert financial items
2055 // ensure entity_financial_trxn table has a linking of it.
2056 $prevItem = CRM_Financial_BAO_FinancialItem
::add($lineObj, $updatedContribution, NULL, $trxnId);
2057 if (isset($lineObj->tax_amount
)) {
2058 CRM_Financial_BAO_FinancialItem
::add($lineObj, $updatedContribution, TRUE, $trxnId);
2063 // update participant fee_amount column
2064 $partUpdateFeeAmt['id'] = $participantId;
2065 $getUpdatedLineItems = "SELECT *
2066 FROM civicrm_line_item
2067 WHERE (entity_table = 'civicrm_participant' AND entity_id = {$participantId} AND qty > 0)";
2068 $getUpdatedLineItemsDAO = CRM_Core_DAO
::executeQuery($getUpdatedLineItems);
2069 while ($getUpdatedLineItemsDAO->fetch()) {
2070 $line[$getUpdatedLineItemsDAO->price_field_value_id
] = $getUpdatedLineItemsDAO->label
. ' - ' . (float) $getUpdatedLineItemsDAO->qty
;
2073 $partUpdateFeeAmt['fee_level'] = implode(', ', $line);
2074 $partUpdateFeeAmt['fee_amount'] = $params['amount'];
2075 self
::add($partUpdateFeeAmt);
2078 self
::addActivityForSelection($participantId, 'Change Registration');
2082 * Record adjusted amount.
2084 * @param int $updatedAmount
2085 * @param int $paidAmount
2086 * @param int $contributionId
2088 * @param int $taxAmount
2089 * @param bool $updateAmountLevel
2091 * @return bool|\CRM_Core_BAO_FinancialTrxn
2093 public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL, $updateAmountLevel = NULL) {
2094 $pendingAmount = CRM_Core_BAO_FinancialTrxn
::getBalanceTrxnAmt($contributionId);
2095 $pendingAmount = CRM_Utils_Array
::value('total_amount', $pendingAmount, 0);
2096 $balanceAmt = $updatedAmount - $paidAmount;
2097 if ($paidAmount != $pendingAmount) {
2098 $balanceAmt -= $pendingAmount;
2101 $contributionStatuses = CRM_Contribute_PseudoConstant
::contributionStatus(NULL, 'name');
2102 $partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
2103 $pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
2104 $completedStatusId = array_search('Completed', $contributionStatuses);
2106 $updatedContributionDAO = new CRM_Contribute_BAO_Contribution();
2107 $adjustedTrxn = $skip = FALSE;
2109 if ($balanceAmt > 0 && $paidAmount != 0) {
2110 $contributionStatusVal = $partiallyPaidStatusId;
2112 elseif ($balanceAmt < 0 && $paidAmount != 0) {
2113 $contributionStatusVal = $pendingRefundStatusId;
2115 elseif ($paidAmount == 0) {
2116 //skip updating the contribution status if no payment is made
2118 $updatedContributionDAO->cancel_date
= 'null';
2119 $updatedContributionDAO->cancel_reason
= NULL;
2121 // update contribution status and total amount without trigger financial code
2122 // as this is handled in current BAO function used for change selection
2123 $updatedContributionDAO->id
= $contributionId;
2125 $updatedContributionDAO->contribution_status_id
= $contributionStatusVal;
2127 $updatedContributionDAO->total_amount
= $updatedContributionDAO->net_amount
= $updatedAmount;
2128 $updatedContributionDAO->fee_amount
= 0;
2129 $updatedContributionDAO->tax_amount
= $taxAmount;
2130 if (!empty($updateAmountLevel)) {
2131 $updatedContributionDAO->amount_level
= $updateAmountLevel;
2133 $updatedContributionDAO->save();
2134 // adjusted amount financial_trxn creation
2135 $updatedContribution = CRM_Contribute_BAO_Contribution
::getValues(
2136 array('id' => $contributionId),
2137 CRM_Core_DAO
::$_nullArray,
2138 CRM_Core_DAO
::$_nullArray
2140 $relationTypeId = key(CRM_Core_PseudoConstant
::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Accounts Receivable Account is' "));
2141 $toFinancialAccount = CRM_Contribute_PseudoConstant
::financialAccountType($updatedContribution->financial_type_id
, $relationTypeId);
2142 $adjustedTrxnValues = array(
2143 'from_financial_account_id' => NULL,
2144 'to_financial_account_id' => $toFinancialAccount,
2145 'total_amount' => $balanceAmt,
2146 'status_id' => $completedStatusId,
2147 'payment_instrument_id' => $updatedContribution->payment_instrument_id
,
2148 'contribution_id' => $updatedContribution->id
,
2149 'trxn_date' => date('YmdHis'),
2150 'currency' => $updatedContribution->currency
,
2152 $adjustedTrxn = CRM_Core_BAO_FinancialTrxn
::create($adjustedTrxnValues);
2154 return $adjustedTrxn;
2158 * @param int $participantId
2159 * @param $activityType
2161 * @throws CRM_Core_Exception
2163 public static function addActivityForSelection($participantId, $activityType) {
2164 $eventId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $participantId, 'event_id');
2165 $contactId = CRM_Core_DAO
::getFieldValue('CRM_Event_BAO_Participant', $participantId, 'contact_id');
2167 $date = CRM_Utils_Date
::currentDBDate();
2168 $event = CRM_Event_BAO_Event
::getEvents(0, $eventId);
2169 $eventTitle = $event[$eventId];
2170 $subject = "Registration selections changed for $eventTitle";
2171 $targetCid = $contactId;
2172 $srcRecId = $participantId;
2175 $activityParams = array(
2176 'source_contact_id' => $targetCid,
2177 'source_record_id' => $srcRecId,
2178 'activity_type_id' => CRM_Core_OptionGroup
::getValue('activity_type',
2182 'subject' => $subject,
2183 'activity_date_time' => $date,
2184 'status_id' => CRM_Core_OptionGroup
::getValue('activity_status',
2188 'skipRecentView' => TRUE,
2191 // create activity with target contacts
2192 $session = CRM_Core_Session
::singleton();
2193 $id = $session->get('userID');
2195 $activityParams['source_contact_id'] = $id;
2196 $activityParams['target_contact_id'][] = $targetCid;
2198 CRM_Activity_BAO_Activity
::create($activityParams);
2202 * Get options for a given field.
2203 * @see CRM_Core_DAO::buildOptions
2205 * @param string $fieldName
2206 * @param string $context
2207 * @see CRM_Core_DAO::buildOptionsContext
2208 * @param array $props
2209 * whatever is known about this dao object.
2211 * @return array|bool
2213 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
2214 $params = array('condition' => array());
2216 if ($fieldName == 'status_id' && $context != 'validate') {
2217 // Get rid of cart-related option if disabled
2218 // FIXME: Why does this option even exist if cart is disabled?
2219 if (!Civi
::settings()->get('enable_cart')) {
2220 $params['condition'][] = "name <> 'Pending in cart'";
2224 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);
2228 * CRM-17797 -- Format fields and setDefaults for primary and additional participants profile
2229 * @param int $contactId
2230 * @param CRM_Core_Form $form
2232 public static function formatFieldsAndSetProfileDefaults($contactId, &$form) {
2237 if (!empty($form->_fields
)) {
2238 $removeCustomFieldTypes = array('Participant');
2240 foreach ($form->_fields
as $name => $dontCare) {
2241 if ((substr($name, 0, 7) == 'custom_' && !$form->_allowConfirmation
2242 && !CRM_Core_BAO_CustomGroup
::checkCustomField(substr($name, 7), $removeCustomFieldTypes))
2243 ||
substr($name, 0, 12) == 'participant_') {
2249 if (!empty($fields)) {
2250 CRM_Core_BAO_UFGroup
::setProfileDefaults($contactId, $fields, $form->_defaults
);