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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
35 class CRM_Event_BAO_Event
extends CRM_Event_DAO_Event
{
40 function __construct() {
41 parent
::__construct();
45 * Takes a bunch of params that are needed to match certain criteria and
46 * retrieves the relevant objects. Typically the valid params are only
47 * contact_id. We'll tweak this function to be more full featured over a period
48 * of time. This is the inverse function of create. It also stores all the retrieved
49 * values in the default array
51 * @param array $params (reference ) an assoc array of name/value pairs
52 * @param array $defaults (reference ) an assoc array to hold the flattened values
54 * @return object CRM_Event_BAO_ManageEvent object
58 static function retrieve(&$params, &$defaults) {
59 $event = new CRM_Event_DAO_Event();
60 $event->copyValues($params);
61 if ($event->find(TRUE)) {
62 CRM_Core_DAO
::storeValues($event, $defaults);
69 * update the is_active flag in the db
71 * @param int $id id of the database record
72 * @param boolean $is_active value we want to set the is_active field
74 * @return Object DAO object on sucess, null otherwise
77 static function setIsActive($id, $is_active) {
78 return CRM_Core_DAO
::setFieldValue('CRM_Event_DAO_Event', $id, 'is_active', $is_active);
82 * function to add the event
84 * @param array $params reference array contains the values submitted by the form
91 static function add(&$params) {
92 CRM_Utils_System
::flushCache();
93 $financialTypeId = NULL;
94 if (!empty($params['id'])) {
95 CRM_Utils_Hook
::pre('edit', 'Event', $params['id'], $params);
96 if (empty($params['skipFinancialType'])) {
97 $financialTypeId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event', $params['id'], 'financial_type_id');
101 CRM_Utils_Hook
::pre('create', 'Event', NULL, $params);
104 $event = new CRM_Event_DAO_Event();
106 $event->copyValues($params);
107 $result = $event->save();
109 if (!empty($params['id'])) {
110 CRM_Utils_Hook
::post('edit', 'Event', $event->id
, $event);
113 CRM_Utils_Hook
::post('create', 'Event', $event->id
, $event);
115 if ($financialTypeId && !empty($params['financial_type_id']) && $financialTypeId != $params['financial_type_id']) {
116 CRM_Price_BAO_PriceFieldValue
::updateFinancialType($params['id'], 'civicrm_event', $params['financial_type_id']);
122 * function to create the event
124 * @param array $params reference array contains the values submitted by the form
131 public static function create(&$params) {
132 $transaction = new CRM_Core_Transaction();
133 if (empty($params['is_template'])) {
134 $params['is_template'] = 0;
136 // check if new event, if so set the created_id (if not set)
137 // and always set created_date to now
138 if (empty($params['id'])) {
139 if (empty($params['created_id'])) {
140 $session = CRM_Core_Session
::singleton();
141 $params['created_id'] = $session->get('userID');
143 $params['created_date'] = date('YmdHis');
146 $event = self
::add($params);
147 CRM_Price_BAO_PriceSet
::setPriceSets($params, $event, 'event');
148 if (is_a($event, 'CRM_Core_Error')) {
149 CRM_Core_DAO
::transaction('ROLLBACK');
153 $session = CRM_Core_Session
::singleton();
154 $contactId = $session->get('userID');
156 $contactId = CRM_Utils_Array
::value('contact_id', $params);
159 // Log the information on successful add/edit of Event
161 'entity_table' => 'civicrm_event',
162 'entity_id' => $event->id
,
163 'modified_id' => $contactId,
164 'modified_date' => date('Ymd'),
167 CRM_Core_BAO_Log
::add($logParams);
169 if (!empty($params['custom']) &&
170 is_array($params['custom'])
172 CRM_Core_BAO_CustomValueTable
::store($params['custom'], 'civicrm_event', $event->id
);
175 $transaction->commit();
181 * Function to delete the event
183 * @param int $id event id
190 static function del($id) {
195 CRM_Utils_Hook
::pre('delete', 'Event', $id, CRM_Core_DAO
::$_nullArray);
197 $extends = array('event');
198 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
199 foreach ($groupTree as $values) {
200 $query = "DELETE FROM " . $values['table_name'] . " WHERE entity_id = " . $id;
202 $params = array(1 => array($values['table_name'], 'string'),
203 2 => array($id, 'integer'),
206 CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
209 // price set cleanup, CRM-5527
210 CRM_Price_BAO_PriceSet
::removeFrom('civicrm_event', $id);
212 $event = new CRM_Event_DAO_Event();
215 if ($event->find(TRUE)) {
216 $locBlockId = $event->loc_block_id
;
217 $result = $event->delete();
219 if (!is_null($locBlockId)) {
220 self
::deleteEventLocBlock($locBlockId, $id);
223 CRM_Utils_Hook
::post('delete', 'Event', $id, $event);
231 * Function to delete the location block associated with an event,
232 * if not being used by any other event.
235 * @param null $eventId
237 * @internal param int $loc_block_id location block id to be deleted
238 * @internal param int $eventid event id with which loc block is associated
243 static function deleteEventLocBlock($locBlockId, $eventId = NULL) {
244 $query = "SELECT count(ce.id) FROM civicrm_event ce WHERE ce.loc_block_id = $locBlockId";
247 $query .= " AND ce.id != $eventId;";
250 $locCount = CRM_Core_DAO
::singleValueQuery($query);
252 if ($locCount == 0) {
253 CRM_Core_BAO_Location
::deleteLocBlock($locBlockId);
258 * Function to get current/future Events
260 * @param $all int 0 returns current and future events
261 * 1 if events all are required
262 * 2 returns events since 3 months ago
263 * @param bool|int $id int id of a specific event to return
264 * @param $isActive boolean true if you need only active events
265 * @param $checkPermission boolean true if you need to check permission else false
270 static function getEvents($all = 0,
273 $checkPermission = TRUE
276 SELECT `id`, `title`, `start_date`
278 WHERE ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
281 $query .= " AND `id` = {$id}";
284 // find only events ending in the future
285 $endDate = date('YmdHis');
287 AND ( `end_date` >= {$endDate} OR
289 ( end_date IS NULL OR end_date = '' ) AND start_date >= {$endDate}
294 // find only events starting in the last 3 months
295 $startDate = date('YmdHis', strtotime('3 months ago'));
296 $query .= " AND ( `start_date` >= {$startDate} OR start_date IS NULL )";
299 $query .= " AND civicrm_event.is_active = 1";
302 $query .= " ORDER BY title asc";
305 $dao = CRM_Core_DAO
::executeQuery($query);
306 while ($dao->fetch()) {
307 if ((!$checkPermission ||
308 CRM_Event_BAO_Event
::checkPermission($dao->id
)
312 $events[$dao->id
] = $dao->title
. ' - ' . CRM_Utils_Date
::customFormat($dao->start_date
);
320 * Function to get events Summary
324 * @return array Array of event summary values
326 static function getEventSummary() {
327 $eventSummary = $eventIds = array();
328 $config = CRM_Core_Config
::singleton();
330 // get permission and include them here
331 // does not scale, but rearranging code for now
332 // FIXME in a future release
333 $permissions = CRM_Event_BAO_Event
::checkPermission();
335 if (empty($permissions[CRM_Core_Permission
::VIEW
])) {
336 $eventSummary['total_events'] = 0;
337 return $eventSummary;
340 $validEventIDs = " AND civicrm_event.id IN ( " . implode(',', array_values($permissions[CRM_Core_Permission
::VIEW
])) . " ) ";
343 // We're fetching recent and upcoming events (where start date is 7 days ago OR later)
345 SELECT count(id) as total_events
347 WHERE civicrm_event.is_active = 1 AND
348 ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND
349 civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )
352 $dao = CRM_Core_DAO
::executeQuery($query);
355 $eventSummary['total_events'] = $dao->total_events
;
358 if (empty($eventSummary) ||
359 $dao->total_events
== 0
361 return $eventSummary;
364 //get the participant status type values.
365 $cpstObject = new CRM_Event_DAO_ParticipantStatusType();
366 $cpst = $cpstObject->getTableName();
367 $query = "SELECT id, name, label, class FROM $cpst";
368 $status = CRM_Core_DAO
::executeQuery($query);
369 $statusValues = array();
370 while ($status->fetch()) {
371 $statusValues[$status->id
]['id'] = $status->id
;
372 $statusValues[$status->id
]['name'] = $status->name
;
373 $statusValues[$status->id
]['label'] = $status->label
;
374 $statusValues[$status->id
]['class'] = $status->class;
377 // Get the Id of Option Group for Event Types
378 $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
379 $optionGroupDAO->name
= 'event_type';
380 $optionGroupId = NULL;
381 if ($optionGroupDAO->find(TRUE)) {
382 $optionGroupId = $optionGroupDAO->id
;
384 // Get the event summary display preferences
385 $show_max_events = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
388 // default to 10 if no option is set
389 if (is_null($show_max_events)) {
390 $show_max_events = 10;
392 // show all events if show_events is set to a negative value
393 if ($show_max_events >= 0) {
394 $event_summary_limit = "LIMIT 0, $show_max_events";
397 $event_summary_limit = "";
401 SELECT civicrm_event.id as id, civicrm_event.title as event_title, civicrm_event.is_public as is_public,
402 civicrm_event.max_participants as max_participants, civicrm_event.start_date as start_date,
403 civicrm_event.end_date as end_date, civicrm_event.is_online_registration, civicrm_event.is_monetary, civicrm_event.is_show_location,civicrm_event.is_map as is_map, civicrm_option_value.label as event_type, civicrm_tell_friend.is_active as is_friend_active,
404 civicrm_event.slot_label_id,
405 civicrm_event.summary as summary,
406 civicrm_pcp_block.id as is_pcp_enabled
408 LEFT JOIN civicrm_option_value ON (
409 civicrm_event.event_type_id = civicrm_option_value.value AND
410 civicrm_option_value.option_group_id = %1 )
411 LEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_event.id AND civicrm_tell_friend.entity_table = 'civicrm_event' )
412 LEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_event.id AND civicrm_pcp_block.entity_table = 'civicrm_event')
413 WHERE civicrm_event.is_active = 1 AND
414 ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND
415 civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )
417 GROUP BY civicrm_event.id
418 ORDER BY civicrm_event.start_date ASC
421 $eventParticipant = array();
425 'eventTitle' => 'event_title',
426 'isPublic' => 'is_public',
427 'maxParticipants' => 'max_participants',
428 'startDate' => 'start_date',
429 'endDate' => 'end_date',
430 'eventType' => 'event_type',
432 'participants' => 'participants',
433 'notCountedDueToRole' => 'notCountedDueToRole',
434 'notCountedDueToStatus' => 'notCountedDueToStatus',
435 'notCountedParticipants' => 'notCountedParticipants',
438 $params = array(1 => array($optionGroupId, 'Integer'));
439 $mappingID = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', 'civicrm_event', 'id', 'entity_value');
440 $dao = CRM_Core_DAO
::executeQuery($query, $params);
441 while ($dao->fetch()) {
442 foreach ($properties as $property => $name) {
452 $eventSummary['events'][$dao->id
][$property] = $set;
456 if ($dao->$name && $config->mapAPIKey
) {
459 $params = array('entity_id' => $dao->id
, 'entity_table' => 'civicrm_event');
460 $values['location'] = CRM_Core_BAO_Location
::getValues($params, TRUE);
461 if (is_numeric(CRM_Utils_Array
::value('geo_code_1', $values['location']['address'][1])) ||
462 ($config->mapGeoCoding
&&
463 !empty($values['location']['address'][1]['city']) &&
464 !empty($values['location']['address'][1]['state_province_id'])
467 $set = CRM_Utils_System
::url('civicrm/contact/map/event', "reset=1&eid={$dao->id}");
471 $eventSummary['events'][$dao->id
][$property] = $set;
472 if (in_array($dao->id
, $permissions[CRM_Core_Permission
::EDIT
])) {
473 $eventSummary['events'][$dao->id
]['configure'] = CRM_Utils_System
::url('civicrm/admin/event', "action=update&id=$dao->id&reset=1");
479 $eventSummary['events'][$dao->id
][$property] = CRM_Utils_Date
::customFormat($dao->$name,
485 case 'notCountedDueToRole':
486 case 'notCountedDueToStatus':
487 case 'notCountedParticipants':
490 if ($name == 'participants') {
491 $propertyCnt = self
::getParticipantCount($dao->id
);
493 $set = CRM_Utils_System
::url('civicrm/event/search',
494 "reset=1&force=1&event=$dao->id&status=true&role=true"
498 elseif ($name == 'notCountedParticipants') {
499 $propertyCnt = self
::getParticipantCount($dao->id
, TRUE, FALSE, TRUE, FALSE);
501 // FIXME : selector fail to search w/ OR operator.
502 // $set = CRM_Utils_System::url( 'civicrm/event/search',
503 // "reset=1&force=1&event=$dao->id&status=false&role=false" );
506 elseif ($name == 'notCountedDueToStatus') {
507 $propertyCnt = self
::getParticipantCount($dao->id
, TRUE, FALSE, FALSE, FALSE);
509 $set = CRM_Utils_System
::url('civicrm/event/search',
510 "reset=1&force=1&event=$dao->id&status=false"
515 $propertyCnt = self
::getParticipantCount($dao->id
, FALSE, FALSE, TRUE, FALSE);
517 $set = CRM_Utils_System
::url('civicrm/event/search',
518 "reset=1&force=1&event=$dao->id&role=false"
523 $eventSummary['events'][$dao->id
][$property] = $propertyCnt;
524 $eventSummary['events'][$dao->id
][$name . '_url'] = $set;
528 $eventSummary['events'][$dao->id
][$property] = $dao->$name;
533 // prepare the area for per-status participant counts
534 $statusClasses = array('Positive', 'Pending', 'Waiting', 'Negative');
535 $eventSummary['events'][$dao->id
]['statuses'] = array_fill_keys($statusClasses, array());
537 $eventSummary['events'][$dao->id
]['friend'] = $dao->is_friend_active
;
538 $eventSummary['events'][$dao->id
]['is_monetary'] = $dao->is_monetary
;
539 $eventSummary['events'][$dao->id
]['is_online_registration'] = $dao->is_online_registration
;
540 $eventSummary['events'][$dao->id
]['is_show_location'] = $dao->is_show_location
;
541 $eventSummary['events'][$dao->id
]['is_subevent'] = $dao->slot_label_id
;
542 $eventSummary['events'][$dao->id
]['is_pcp_enabled'] = $dao->is_pcp_enabled
;
543 $eventSummary['events'][$dao->id
]['reminder'] = CRM_Core_BAO_ActionSchedule
::isConfigured($dao->id
, $mappingID);
545 $statusTypes = CRM_Event_PseudoConstant
::participantStatus();
546 foreach ($statusValues as $statusId => $statusValue) {
547 if (!array_key_exists($statusId, $statusTypes)) {
550 $class = $statusValue['class'];
551 $statusCount = self
::eventTotalSeats($dao->id
, "( participant.status_id = {$statusId} )");
553 $urlString = "reset=1&force=1&event={$dao->id}&status=$statusId";
554 $statusInfo = array('url' => CRM_Utils_System
::url('civicrm/event/search', $urlString),
555 'name' => $statusValue['name'],
556 'label' => $statusValue['label'],
557 'count' => $statusCount,
559 $eventSummary['events'][$dao->id
]['statuses'][$class][] = $statusInfo;
564 $countedRoles = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
565 $nonCountedRoles = CRM_Event_PseudoConstant
::participantRole(NULL, '( filter = 0 OR filter IS NULL )');
566 $countedStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
567 $nonCountedStatus = CRM_Event_PseudoConstant
::participantStatus(NULL, '( is_counted = 0 OR is_counted IS NULL )');
569 $countedStatusANDRoles = array_merge($countedStatus, $countedRoles);
570 $nonCountedStatusANDRoles = array_merge($nonCountedStatus, $nonCountedRoles);
572 $eventSummary['nonCountedRoles'] = implode('/', array_values($nonCountedRoles));
573 $eventSummary['nonCountedStatus'] = implode('/', array_values($nonCountedStatus));
574 $eventSummary['countedStatusANDRoles'] = implode('/', array_values($countedStatusANDRoles));
575 $eventSummary['nonCountedStatusANDRoles'] = implode('/', array_values($nonCountedStatusANDRoles));
577 return $eventSummary;
581 * Function to get participant count
584 * @param boolean $considerStatus consider status for participant count.
585 * @param boolean $status consider counted participant.
586 * @param boolean $considerRole consider role for participant count.
587 * @param boolean $role consider counted( is filter role) participant.
589 * @internal param array $eventIds consider participants from given events.
590 * @internal param bool $countWithStatus retrieve participant count w/ each participant status.
594 * @return array array with count of participants for each event based on status/role
596 public static function getParticipantCount($eventId,
597 $considerStatus = TRUE,
599 $considerRole = TRUE,
603 // consider both role and status for counted participants, CRM-4924.
605 // not counted participant.
606 if ($considerStatus && $considerRole && !$status && !$role) {
610 if ($considerStatus) {
611 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
612 $statusClause = 'NOT IN';
614 $statusClause = 'IN';
616 $status = implode(',', array_keys($statusTypes));
617 if (empty($status)) {
620 $clause[] = "participant.status_id {$statusClause} ( {$status} ) ";
624 $roleTypes = CRM_Event_PseudoConstant
::participantRole(NULL, 'filter = 1');
625 $roleClause = 'NOT IN';
629 $roles = implode(',', array_keys($roleTypes));
633 $clause[] = "participant.role_id {$roleClause} ( $roles )";
637 if (!empty($clause)) {
638 $sqlClause = ' ( ' . implode($operator, $clause) . ' )';
641 return self
::eventTotalSeats($eventId, $sqlClause);
645 * function to get the information to map a event
649 * @internal param array $ids the list of ids for which we want map info
651 * @return null|string title of the event
655 static function &getMapInfo(&$id) {
659 civicrm_event.id AS event_id,
660 civicrm_event.title AS display_name,
661 civicrm_address.street_address AS street_address,
662 civicrm_address.city AS city,
663 civicrm_address.postal_code AS postal_code,
664 civicrm_address.postal_code_suffix AS postal_code_suffix,
665 civicrm_address.geo_code_1 AS latitude,
666 civicrm_address.geo_code_2 AS longitude,
667 civicrm_state_province.abbreviation AS state,
668 civicrm_country.name AS country,
669 civicrm_location_type.name AS location_type
672 LEFT JOIN civicrm_loc_block ON ( civicrm_event.loc_block_id = civicrm_loc_block.id )
673 LEFT JOIN civicrm_address ON ( civicrm_loc_block.address_id = civicrm_address.id )
674 LEFT JOIN civicrm_state_province ON ( civicrm_address.state_province_id = civicrm_state_province.id )
675 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
676 LEFT JOIN civicrm_location_type ON ( civicrm_location_type.id = civicrm_address.location_type_id )
677 WHERE civicrm_address.geo_code_1 IS NOT NULL
678 AND civicrm_address.geo_code_2 IS NOT NULL
679 AND civicrm_event.id = " . CRM_Utils_Type
::escape($id, 'Integer');
681 $dao = new CRM_Core_DAO();
684 $locations = array();
686 $config = CRM_Core_Config
::singleton();
688 while ($dao->fetch()) {
691 $location['displayName'] = addslashes($dao->display_name
);
692 $location['lat'] = $dao->latitude
;
693 $location['marker_class'] = 'Event';
694 $location['lng'] = $dao->longitude
;
696 $params = array('entity_id' => $id, 'entity_table' => 'civicrm_event');
697 $addressValues = CRM_Core_BAO_Location
::getValues($params, TRUE);
698 $location['address'] = str_replace(array("\r", "\n"), '', addslashes(nl2br($addressValues['address'][1]['display_text'])));
700 $location['url'] = CRM_Utils_System
::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id
);
701 $location['location_type'] = $dao->location_type
;
702 $eventImage = '<img src="' . $config->resourceBase
. 'i/contact_org.gif" alt="Organization " height="20" width="15" />';
703 $location['image'] = $eventImage;
704 $location['displayAddress'] = str_replace('<br />', ', ', $location['address']);
705 $locations[] = $location;
711 * function to get the complete information for one or more events
713 * @param date $start get events with start date >= this date
714 * @param integer $type get events on the a specific event type (by event_type_id)
715 * @param integer $eventId return a single event - by event id
716 * @param date $end also get events with end date >= this date
717 * @param boolean $onlyPublic include public events only, default TRUE
719 * @return array $all array of all the events that are searched
723 static function &getCompleteInfo(
730 $publicCondition = NULL;
732 $publicCondition = " AND civicrm_event.is_public = 1";
736 // if start and end date are NOT passed, return all events with start_date OR end_date >= today CRM-5133
738 // get events with start_date >= requested start
739 $startDate = CRM_Utils_Type
::escape($start, 'Date');
740 $dateCondition .= " AND ( civicrm_event.start_date >= {$startDate} )";
744 // also get events with end_date <= requested end
745 $endDate = CRM_Utils_Type
::escape($end, 'Date');
746 $dateCondition .= " AND ( civicrm_event.end_date <= '{$endDate}' ) ";
749 // CRM-9421 and CRM-8620 Default mode for ical/rss feeds. No start or end filter passed.
750 // Need to exclude old events with only start date
751 // and not exclude events in progress (start <= today and end >= today). DGG
752 if (empty($start) && empty($end)) {
753 // get events with end date >= today, not sure of this logic
754 // but keeping this for backward compatibility as per issue CRM-5133
755 $today = date("Y-m-d G:i:s");
756 $dateCondition .= " AND ( civicrm_event.end_date >= '{$today}' OR civicrm_event.start_date >= '{$today}' ) ";
760 $typeCondition = " AND civicrm_event.event_type_id = " . CRM_Utils_Type
::escape($type, 'Integer');
763 // Get the Id of Option Group for Event Types
764 $optionGroupDAO = new CRM_Core_DAO_OptionGroup();
765 $optionGroupDAO->name
= 'event_type';
766 $optionGroupId = NULL;
767 if ($optionGroupDAO->find(TRUE)) {
768 $optionGroupId = $optionGroupDAO->id
;
773 civicrm_event.id as event_id,
774 civicrm_email.email as email,
775 civicrm_event.title as title,
776 civicrm_event.summary as summary,
777 civicrm_event.start_date as start,
778 civicrm_event.end_date as end,
779 civicrm_event.description as description,
780 civicrm_event.is_show_location as is_show_location,
781 civicrm_event.is_online_registration as is_online_registration,
782 civicrm_event.registration_link_text as registration_link_text,
783 civicrm_event.registration_start_date as registration_start_date,
784 civicrm_event.registration_end_date as registration_end_date,
785 civicrm_option_value.label as event_type,
786 civicrm_address.name as address_name,
787 civicrm_address.street_address as street_address,
788 civicrm_address.supplemental_address_1 as supplemental_address_1,
789 civicrm_address.supplemental_address_2 as supplemental_address_2,
790 civicrm_address.city as city,
791 civicrm_address.postal_code as postal_code,
792 civicrm_address.postal_code_suffix as postal_code_suffix,
793 civicrm_state_province.abbreviation as state,
794 civicrm_country.name AS country
796 LEFT JOIN civicrm_loc_block ON civicrm_event.loc_block_id = civicrm_loc_block.id
797 LEFT JOIN civicrm_address ON civicrm_loc_block.address_id = civicrm_address.id
798 LEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id
799 LEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id
800 LEFT JOIN civicrm_email ON civicrm_loc_block.email_id = civicrm_email.id
801 LEFT JOIN civicrm_option_value ON (
802 civicrm_event.event_type_id = civicrm_option_value.value AND
803 civicrm_option_value.option_group_id = %1 )
804 WHERE civicrm_event.is_active = 1
805 AND (is_template = 0 OR is_template IS NULL)
809 if (isset($typeCondition)) {
810 $query .= $typeCondition;
813 if (isset($eventId)) {
814 $query .= " AND civicrm_event.id =$eventId ";
816 $query .= " ORDER BY civicrm_event.start_date ASC";
819 $params = array(1 => array($optionGroupId, 'Integer'));
820 $dao = CRM_Core_DAO
::executeQuery($query, $params);
822 $config = CRM_Core_Config
::singleton();
824 $baseURL = parse_url($config->userFrameworkBaseURL
);
825 $url = "@" . $baseURL['host'];
826 if (!empty($baseURL['path'])) {
827 $url .= substr($baseURL['path'], 0, -1);
830 // check 'view event info' permission
831 //@todo - per CRM-14626 we have resolved that 'view event info' means 'view ALL event info'
832 // and passing in the specific permission here will short-circuit the evaluation of permission to
833 // see specific events (doesn't seem relevant to this call
834 // however, since this function is accessed only by a convoluted call from a joomla block function
835 // it seems safer not to touch here. Suggestion is that CRM_Core_Permission::check(array or relevant permissions) would
836 // be clearer & safer here
837 $permissions = CRM_Core_Permission
::event(CRM_Core_Permission
::VIEW
);
839 // check if we're in shopping cart mode for events
840 $enable_cart = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::EVENT_PREFERENCES_NAME
,
844 while ($dao->fetch()) {
845 if (!empty($permissions) && in_array($dao->event_id
, $permissions)) {
847 $info['uid'] = "CiviCRM_EventID_{$dao->event_id}_" . md5($config->userFrameworkBaseURL
) . $url;
849 $info['title'] = $dao->title
;
850 $info['event_id'] = $dao->event_id
;
851 $info['summary'] = $dao->summary
;
852 $info['description'] = $dao->description
;
853 $info['start_date'] = $dao->start
;
854 $info['end_date'] = $dao->end
;
855 $info['contact_email'] = $dao->email
;
856 $info['event_type'] = $dao->event_type
;
857 $info['is_show_location'] = $dao->is_show_location
;
858 $info['is_online_registration'] = $dao->is_online_registration
;
859 $info['registration_link_text'] = $dao->registration_link_text
;
860 $info['registration_start_date'] = $dao->registration_start_date
;
861 $info['registration_end_date'] = $dao->registration_end_date
;
866 'address_name' => $dao->address_name
,
867 'street_address' => $dao->street_address
,
868 'supplemental_address_1' => $dao->supplemental_address_1
,
869 'supplemental_address_2' => $dao->supplemental_address_2
,
870 'city' => $dao->city
,
871 'state_province' => $dao->state
,
872 'postal_code' => $dao->postal_code
,
873 'postal_code_suffix' => $dao->postal_code_suffix
,
874 'country' => $dao->country
,
878 CRM_Utils_String
::append($address, ', ',
879 CRM_Utils_Address
::format($addrFields)
881 $info['location'] = $address;
882 $info['url'] = CRM_Utils_System
::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id
, TRUE, NULL, FALSE);
885 $reg = CRM_Event_Cart_BAO_EventInCart
::get_registration_link($dao->event_id
);
886 $info['registration_link'] = CRM_Utils_System
::url($reg['path'], $reg['query'], TRUE);
887 $info['registration_link_text'] = $reg['label'];
898 * This function is to make a copy of a Event, including
899 * all the fields in the event Wizard
901 * @param int $id the event id to copy
902 * obj $newEvent object of CRM_Event_DAO_Event
903 * boolean $afterCreate call to copy after the create function
904 * @param null $newEvent
905 * @param bool $afterCreate
910 static function copy($id, $newEvent = NULL, $afterCreate = FALSE) {
912 $defaults = $eventValues = array();
914 //get the require event values.
915 $eventParams = array('id' => $id);
916 $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id', 'is_template');
918 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
920 // since the location is sharable, lets use the same loc_block_id.
921 $locBlockId = CRM_Utils_Array
::value('loc_block_id', $eventValues);
923 $fieldsFix = ($afterCreate) ?
array( ) : array('prefix' => array('title' => ts('Copy of') . ' '));
924 if (empty($eventValues['is_show_location'])) {
925 $fieldsFix['prefix']['is_show_location'] = 0;
928 if ($newEvent && is_a($newEvent, 'CRM_Event_DAO_Event')) {
929 $copyEvent = $newEvent;
932 if (!isset($copyEvent)) {
933 $copyEvent = &CRM_Core_DAO
::copyGeneric('CRM_Event_DAO_Event',
937 ($locBlockId) ?
$locBlockId : NULL,
942 CRM_Price_BAO_PriceSet
::copyPriceSet('civicrm_event', $id, $copyEvent->id
);
943 $copyUF = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_UFJoin',
946 'entity_table' => 'civicrm_event',
948 array('entity_id' => $copyEvent->id
)
951 $copyTellFriend = &CRM_Core_DAO
::copyGeneric('CRM_Friend_DAO_Friend',
954 'entity_table' => 'civicrm_event',
956 array('entity_id' => $copyEvent->id
)
959 $copyPCP = &CRM_Core_DAO
::copyGeneric('CRM_PCP_DAO_PCPBlock',
962 'entity_table' => 'civicrm_event',
964 array('entity_id' => $copyEvent->id
),
965 array('replace' => array('target_entity_id' => $copyEvent->id
))
968 if ($eventValues['is_template']) {
969 $field = 'event_template';
972 $field = 'civicrm_event';
974 $mappingId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
975 $oldData = array('entity_value' => $id, 'mapping_id' => $mappingId);
976 if ($copyEvent->is_template
== 1) {
977 $field = 'event_template';
980 $field = 'civicrm_event';
982 $copyMappingId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_ActionMapping', $field, 'id', 'entity_value');
983 $newData = array('entity_value' => $copyEvent->id
, 'mapping_id' => $copyMappingId);
984 $copyReminder = &CRM_Core_DAO
::copyGeneric('CRM_Core_DAO_ActionSchedule',
991 $extends = array('event');
992 $groupTree = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, NULL, $extends);
994 foreach ($groupTree as $groupID => $group) {
995 $table[$groupTree[$groupID]['table_name']] = array('entity_id');
996 foreach ($group['fields'] as $fieldID => $field) {
997 $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
1001 foreach ($table as $tableName => $tableColumns) {
1002 $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
1003 $tableColumns[0] = $copyEvent->id
;
1004 $select = 'SELECT ' . implode(', ', $tableColumns);
1005 $from = ' FROM ' . $tableName;
1006 $where = " WHERE {$tableName}.entity_id = {$id}";
1007 $query = $insert . $select . $from . $where;
1008 $dao = CRM_Core_DAO
::executeQuery($query, CRM_Core_DAO
::$_nullArray);
1014 CRM_Utils_System
::flushCache();
1015 if (!$afterCreate) {
1016 CRM_Utils_Hook
::copy('Event', $copyEvent);
1022 * This is sometimes called in a loop (during event search)
1023 * hence we cache the values to prevent repeated calls to the db
1025 static function isMonetary($id) {
1026 static $isMonetary = array();
1027 if (!array_key_exists($id, $isMonetary)) {
1028 $isMonetary[$id] = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Event',
1033 return $isMonetary[$id];
1037 * This is sometimes called in a loop (during event search)
1038 * hence we cache the values to prevent repeated calls to the db
1040 static function usesPriceSet($id) {
1041 static $usesPriceSet = array();
1042 if (!array_key_exists($id, $usesPriceSet)) {
1043 $usesPriceSet[$id] = CRM_Price_BAO_PriceSet
::getFor('civicrm_event', $id);
1045 return $usesPriceSet[$id];
1049 * Process that send e-mails
1053 * @param $participantId
1054 * @param bool $isTest
1055 * @param bool $returnMessageText
1060 static function sendMail($contactID, &$values, $participantId, $isTest = FALSE, $returnMessageText = FALSE) {
1062 $template = CRM_Core_Smarty
::singleton();
1064 'custom_pre_id' => $values['custom_pre_id'],
1065 'custom_post_id' => $values['custom_post_id'],
1068 //get the params submitted by participant.
1069 $participantParams = CRM_Utils_Array
::value($participantId, $values['params'], array());
1071 if (!$returnMessageText) {
1072 //send notification email if field values are set (CRM-1941)
1073 foreach ($gIds as $key => $gIdValues) {
1075 if (!is_array($gIdValues)) {
1076 $gIdValues = array( $gIdValues );
1079 foreach ($gIdValues as $gId) {
1080 $email = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', $gId, 'notify');
1082 //get values of corresponding profile fields for notification
1083 list($profileValues) = self
::buildCustomDisplay($gId,
1092 list($profileValues) = $profileValues;
1095 'values' => $profileValues,
1098 CRM_Core_BAO_UFGroup
::commonSendMail($contactID, $val);
1105 if ($values['event']['is_email_confirm'] ||
$returnMessageText) {
1106 list($displayName, $email) = CRM_Contact_BAO_Contact_Location
::getEmailDetails($contactID);
1108 //send email only when email is present
1109 if (isset($email) ||
$returnMessageText) {
1110 $preProfileID = CRM_Utils_Array
::value('custom_pre_id', $values);
1111 $postProfileID = CRM_Utils_Array
::value('custom_post_id', $values);
1113 if (!empty($values['params']['additionalParticipant'])) {
1114 $preProfileID = CRM_Utils_Array
::value('additional_custom_pre_id', $values, $preProfileID );
1115 $postProfileID = CRM_Utils_Array
::value('additional_custom_post_id', $values, $postProfileID );
1118 self
::buildCustomDisplay($preProfileID,
1128 self
::buildCustomDisplay($postProfileID,
1138 $sessions = CRM_Event_Cart_BAO_Conference
::get_participant_sessions($participantId);
1140 $tplParams = array_merge($values, $participantParams, array(
1142 'confirm_email_text' => CRM_Utils_Array
::value('confirm_email_text', $values['event']),
1143 'isShowLocation' => CRM_Utils_Array
::value('is_show_location', $values['event']),
1144 'contributeMode' => CRM_Utils_Array
::value('contributeMode', $template->_tpl_vars
),
1145 'participantID' => $participantId,
1146 'conference_sessions' => $sessions,
1147 'credit_card_number' =>
1148 CRM_Utils_System
::mungeCreditCard(
1149 CRM_Utils_Array
::value('credit_card_number', $participantParams)),
1150 'credit_card_exp_date' =>
1151 CRM_Utils_Date
::mysqlToIso(
1152 CRM_Utils_Date
::format(
1153 CRM_Utils_Array
::value('credit_card_exp_date', $participantParams))),
1156 // CRM-13890 : NOTE wait list condition need to be given so that
1157 // wait list message is shown properly in email i.e. WRT online event registration template
1158 if (empty($tplParams['participant_status']) && empty($values['params']['isOnWaitlist'])) {
1159 $statusId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant', $participantId, 'status_id', 'id');
1160 $tplParams['participant_status'] = CRM_Event_PseudoConstant
::participantStatus($statusId, NULL, 'label');
1163 $sendTemplateParams = array(
1164 'groupName' => 'msg_tpl_workflow_event',
1165 'valueName' => 'event_online_receipt',
1166 'contactId' => $contactID,
1167 'isTest' => $isTest,
1168 'tplParams' => $tplParams,
1169 'PDFFilename' => ts('confirmation').'.pdf',
1172 // address required during receipt processing (pdf and email receipt)
1173 if ($displayAddress = CRM_Utils_Array
::value('address', $values)) {
1174 $sendTemplateParams['tplParams']['address'] = $displayAddress;
1175 $sendTemplateParams['tplParams']['contributeMode'] = NULL;
1178 // set lineItem details
1179 if ($lineItem = CRM_Utils_Array
::value('lineItem', $values)) {
1180 // check if additional prticipant, if so filter only to relevant ones
1182 if (!empty($values['params']['additionalParticipant'])) {
1183 $ownLineItems = array( );
1184 foreach ( $lineItem as $liKey => $liValue ) {
1185 $firstElement = array_pop( $liValue );
1186 if ( $firstElement['entity_id'] == $participantId ) {
1187 $ownLineItems[0] = $lineItem[$liKey];
1191 if ( ! empty( $ownLineItems ) ) {
1192 $sendTemplateParams['tplParams']['lineItem'] = $ownLineItems;
1196 $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
1200 if ($returnMessageText) {
1201 list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1203 'subject' => $subject,
1205 'to' => $displayName,
1210 $sendTemplateParams['from'] = CRM_Utils_Array
::value('confirm_from_name', $values['event']) . " <" . CRM_Utils_Array
::value('confirm_from_email', $values['event']) . ">";
1211 $sendTemplateParams['toName'] = $displayName;
1212 $sendTemplateParams['toEmail'] = $email;
1213 $sendTemplateParams['autoSubmitted'] = TRUE;
1214 $sendTemplateParams['cc'] = CRM_Utils_Array
::value('cc_confirm',
1217 $sendTemplateParams['bcc'] = CRM_Utils_Array
::value('bcc_confirm',
1220 CRM_Core_BAO_MessageTemplate
::sendTemplate($sendTemplateParams);
1227 * Function to add the custom fields OR array of participant's
1234 * @param $participantId
1236 * @param bool $isCustomProfile
1237 * @param array $participantParams
1242 static function buildCustomDisplay($id,
1248 $isCustomProfile = FALSE,
1249 $participantParams = array()
1252 return array(NULL, NULL);
1255 if (!is_array($id)) {
1256 $id = CRM_Utils_Type
::escape($id, 'Positive');
1257 $profileIds = array($id);
1263 foreach ($profileIds as $gid) {
1264 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $cid)) {
1266 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
,
1267 NULL, NULL, FALSE, NULL,
1268 FALSE, NULL, CRM_Core_Permission
::CREATE
,
1272 //this condition is added, since same contact can have multiple event registrations..
1273 $params = array(array('participant_id', '=', $participantId, 0, 0));
1275 //add participant id
1276 $fields['participant_id'] = array(
1277 'name' => 'participant_id',
1278 'title' => 'Participant Id',
1280 //check whether its a text drive
1282 $params[] = array('participant_test', '=', 1, 0, 0);
1285 //display campaign on thankyou page.
1286 if (array_key_exists('participant_campaign_id', $fields)) {
1287 if ($participantId) {
1288 $campaignId = CRM_Core_DAO
::getFieldValue('CRM_Event_DAO_Participant',
1292 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($campaignId);
1293 $values[$fields['participant_campaign_id']['title']] = CRM_Utils_Array
::value($campaignId,
1297 unset($fields['participant_campaign_id']);
1301 foreach ($fields as $k => $v) {
1303 $groupTitle = $v['groupTitle'];
1305 // suppress all file fields from display
1307 CRM_Utils_Array
::value('data_type', $v, '') == 'File' ||
1308 CRM_Utils_Array
::value('name', $v, '') == 'image_URL' ||
1309 CRM_Utils_Array
::value('field_type', $v) == 'Formatting'
1316 $groupTitles[] = $groupTitle;
1318 //display profile groups those are subscribed by participant.
1319 if (($groups = CRM_Utils_Array
::value('group', $participantParams)) &&
1323 foreach ($groups as $grpId => $isSelected) {
1328 if (!empty($grpIds)) {
1329 //get the group titles.
1330 $grpTitles = array();
1331 $query = 'SELECT title FROM civicrm_group where id IN ( ' . implode(',', $grpIds) . ' )';
1332 $grp = CRM_Core_DAO
::executeQuery($query);
1333 while ($grp->fetch()) {
1334 $grpTitles[] = $grp->title
;
1336 if (!empty($grpTitles) &&
1337 CRM_Utils_Array
::value('title', CRM_Utils_Array
::value('group', $fields))
1339 $values[$fields['group']['title']] = implode(', ', $grpTitles);
1341 unset($fields['group']);
1345 CRM_Core_BAO_UFGroup
::getValues($cid, $fields, $values, FALSE, $params);
1347 if (isset($fields['participant_status_id']['title']) &&
1348 isset($values[$fields['participant_status_id']['title']]) &&
1349 is_numeric($values[$fields['participant_status_id']['title']])
1352 $status = CRM_Event_PseudoConstant
::participantStatus();
1353 $values[$fields['participant_status_id']['title']] = $status[$values[$fields['participant_status_id']['title']]];
1356 if (isset($fields['participant_role_id']['title']) &&
1357 isset($values[$fields['participant_role_id']['title']]) &&
1358 is_numeric($values[$fields['participant_role_id']['title']])
1361 $roles = CRM_Event_PseudoConstant
::participantRole();
1362 $values[$fields['participant_role_id']['title']] = $roles[$values[$fields['participant_role_id']['title']]];
1365 if (isset($fields['participant_register_date']['title']) &&
1366 isset($values[$fields['participant_register_date']['title']])
1368 $values[$fields['participant_register_date']['title']] = CRM_Utils_Date
::customFormat($values[$fields['participant_register_date']['title']]);
1371 //handle fee_level for price set
1372 if (isset($fields['participant_fee_level']['title']) &&
1373 isset($values[$fields['participant_fee_level']['title']])
1375 $feeLevel = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
1376 $values[$fields['participant_fee_level']['title']]
1378 foreach ($feeLevel as $key => $value) {
1380 unset($feeLevel[$key]);
1383 $values[$fields['participant_fee_level']['title']] = implode(',', $feeLevel);
1386 unset($values[$fields['participant_id']['title']]);
1393 $template->assign($name, $val);
1396 if (count($groupTitles)) {
1397 $template->assign($name . '_grouptitle', $groupTitles);
1400 //return if we only require array of participant's info.
1401 if ($isCustomProfile) {
1403 return array($val, $groupTitles);
1412 * Function to build the array for display the profile fields
1414 * @param array $params key value.
1415 * @param int $gid profile Id
1416 * @param array $groupTitle Profile Group Title.
1417 * @param array $values formatted array of key value
1419 * @param array $profileFields
1425 static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = array()) {
1427 $config = CRM_Core_Config
::singleton();
1428 $session = CRM_Core_Session
::singleton();
1429 $contactID = $session->get('userID');
1431 if (CRM_Core_BAO_UFGroup
::filterUFGroups($gid, $contactID)) {
1432 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::VIEW
);
1436 $fields = CRM_Core_BAO_UFGroup
::getFields($gid, FALSE, CRM_Core_Action
::ADD
);
1439 foreach ($fields as $v) {
1440 if (!empty($v['groupTitle'])) {
1441 $groupTitle['groupTitle'] = $v['groupTitle'];
1446 $imProviders = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_IM', 'provider_id');
1447 //start of code to set the default values
1448 foreach ($fields as $name => $field) {
1450 // skip fields that should not be displayed separately
1451 if ($field['skipDisplay']) {
1455 $index = $field['title'];
1456 if ($name === 'organization_name') {
1457 $values[$index] = $params[$name];
1460 if ('state_province' == substr($name, 0, 14)) {
1461 if ($params[$name]) {
1462 $values[$index] = CRM_Core_PseudoConstant
::stateProvince($params[$name]);
1465 $values[$index] = '';
1468 elseif ('date' == substr($name, -4)) {
1469 $values[$index] = CRM_Utils_Date
::customFormat(CRM_Utils_Date
::processDate($params[$name]),
1470 $config->dateformatFull
);
1472 elseif ('country' == substr($name, 0, 7)) {
1473 if ($params[$name]) {
1474 $values[$index] = CRM_Core_PseudoConstant
::country($params[$name]);
1477 $values[$index] = '';
1480 elseif ('county' == substr($name, 0, 6)) {
1481 if ($params[$name]) {
1482 $values[$index] = CRM_Core_PseudoConstant
::county($params[$name]);
1485 $values[$index] = '';
1488 elseif (in_array(substr($name, 0, -3), array('gender', 'prefix', 'suffix', 'communication_style'))) {
1489 $values[$index] = CRM_Core_PseudoConstant
::getLabel('CRM_Contact_DAO_Contact', $name, $params[$name]);
1491 elseif (in_array($name, array(
1492 'addressee', 'email_greeting', 'postal_greeting'))) {
1493 $filterCondition = array('greeting_type' => $name);
1494 $greeting = CRM_Core_PseudoConstant
::greeting($filterCondition);
1495 $values[$index] = $greeting[$params[$name]];
1497 elseif ($name === 'preferred_communication_method') {
1498 $communicationFields = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'preferred_communication_method');
1500 $pref = $params[$name];
1501 if (is_array($pref)) {
1502 foreach ($pref as $k => $v) {
1504 $compref[] = $communicationFields[$k];
1508 $values[$index] = implode(',', $compref);
1510 elseif ($name == 'contact_sub_type') {
1511 $values[$index] = implode(', ', $params[$name]);
1513 elseif ($name == 'group') {
1514 $groups = CRM_Contact_BAO_GroupContact
::getGroupList();
1516 foreach ($params[$name] as $gId => $dontCare) {
1518 $title[] = $groups[$gId];
1521 $values[$index] = implode(', ', $title);
1523 elseif ($name == 'tag') {
1524 $entityTags = $params[$name];
1525 $allTags = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
1527 if (is_array($entityTags)) {
1528 foreach ($entityTags as $tagId => $dontCare) {
1529 $title[] = $allTags[$tagId];
1532 $values[$index] = implode(', ', $title);
1534 elseif ('participant_role_id' == $name OR
1535 'participant_role' == $name
1537 $roles = CRM_Event_PseudoConstant
::participantRole();
1538 $values[$index] = $roles[$params[$name]];
1540 elseif ('participant_status_id' == $name OR
1541 'participant_status' == $name
1543 $status = CRM_Event_PseudoConstant
::participantStatus();
1544 $values[$index] = $status[$params[$name]];
1546 elseif (substr($name, -11) == 'campaign_id') {
1547 $campaigns = CRM_Campaign_BAO_Campaign
::getCampaigns($params[$name]);
1548 $values[$index] = CRM_Utils_Array
::value($params[$name], $campaigns);
1550 elseif (strpos($name, '-') !== FALSE) {
1551 list($fieldName, $id) = CRM_Utils_System
::explode('-', $name, 2);
1552 $detailName = str_replace(' ', '_', $name);
1553 if (in_array($fieldName, array(
1554 'state_province', 'country', 'county'))) {
1555 $values[$index] = $params[$detailName];
1556 $idx = $detailName . '_id';
1557 $values[$index] = $params[$idx];
1559 elseif ($fieldName == 'im') {
1560 $providerName = NULL;
1561 if ($providerId = $detailName . '-provider_id') {
1562 $providerName = CRM_Utils_Array
::value($params[$providerId], $imProviders);
1564 if ($providerName) {
1565 $values[$index] = $params[$detailName] . " (" . $providerName . ")";
1568 $values[$index] = $params[$detailName];
1571 elseif ($fieldName == 'phone') {
1572 $phoneExtField = str_replace('phone', 'phone_ext', $detailName);
1573 if (isset($params[$phoneExtField])) {
1574 $values[$index] = $params[$detailName] . " (" . $params[$phoneExtField] . ")";
1577 $values[$index] = $params[$detailName];
1581 $values[$index] = $params[$detailName];
1585 if (substr($name, 0, 7) === 'do_not_' or substr($name, 0, 3) === 'is_') {
1586 if ($params[$name]) {
1587 $values[$index] = '[ x ]';
1591 if ($cfID = CRM_Core_BAO_CustomField
::getKeyID($name)) {
1593 SELECT html_type, data_type
1594 FROM civicrm_custom_field
1597 $dao = CRM_Core_DAO
::executeQuery($query);
1599 $htmlType = $dao->html_type
;
1601 if ($htmlType == 'File') {
1602 $values[$index] = $params[$index];
1605 if ($dao->data_type
== 'Int' ||
1606 $dao->data_type
== 'Boolean'
1608 $v = $params[$name];
1609 if (!CRM_Utils_System
::isNull($v)) {
1610 $customVal = (int)$v;
1613 elseif ($dao->data_type
== 'Float') {
1614 $customVal = (float )($params[$name]);
1616 elseif ($dao->data_type
== 'Date') {
1617 //@todo note the currently we are using default date time formatting. Since you can select/set
1618 // different date and time format specific to custom field we should consider fixing this
1619 // sometime in the future
1620 $customVal = $displayValue = CRM_Utils_Date
::customFormat(
1621 CRM_Utils_Date
::processDate($params[$name]), $config->dateformatFull
);
1623 if (!empty($params[$name . '_time'])) {
1624 $customVal = $displayValue = CRM_Utils_Date
::customFormat(
1625 CRM_Utils_Date
::processDate($params[$name], $params[$name . '_time']),
1626 $config->dateformatDatetime
);
1631 $customVal = $params[$name];
1633 //take the custom field options
1634 $returnProperties = array($name => 1);
1635 $query = new CRM_Contact_BAO_Query($params, $returnProperties, $fields);
1636 $options = &$query->_options
;
1638 $displayValue = CRM_Core_BAO_CustomField
::getDisplayValue($customVal, $cfID, $options);
1640 //Hack since we dont have function to check empty.
1641 //FIXME in 2.3 using crmIsEmptyArray()
1642 $customValue = TRUE;
1643 if (is_array($customVal) && is_array($displayValue)) {
1644 $customValue = array_diff($customVal, $displayValue);
1646 //use difference of arrays
1647 if (empty($customValue) ||
!$customValue) {
1648 $values[$index] = '';
1651 $values[$index] = $displayValue;
1655 elseif ($name == 'home_URL' &&
1656 !empty($params[$name])
1658 $url = CRM_Utils_System
::fixURL($params[$name]);
1659 $values[$index] = "<a href=\"$url\">{$params[$name]}</a>";
1661 elseif (in_array($name, array(
1662 'birth_date', 'deceased_date', 'participant_register_date'))) {
1663 $values[$index] = CRM_Utils_Date
::customFormat(CRM_Utils_Date
::format($params[$name]));
1666 $values[$index] = $params[$name];
1670 $profileFields[$name] = $field;
1676 * Function to build the array for Additional participant's information array of priamry and additional Ids
1678 * @param int $participantId id of Primary participant
1679 * @param array $values key/value event info
1680 * @param int $contactId contact id of Primary participant
1681 * @param boolean $isTest whether test or live transaction
1682 * @param boolean $isIdsArray to return an array of Ids
1684 * @param bool $skipCancel
1686 * @return array $customProfile array of Additional participant's info OR array of Ids.
1689 static function buildCustomProfile($participantId,
1693 $isIdsArray = FALSE,
1697 $customProfile = $additionalIDs = array();
1698 if (!$participantId) {
1699 CRM_Core_Error
::fatal(ts('Cannot find participant ID'));
1702 //set Ids of Primary Participant also.
1703 if ($isIdsArray && $contactId) {
1704 $additionalIDs[$participantId] = $contactId;
1707 //hack to skip cancelled participants, CRM-4320
1708 $where = "participant.registered_by_id={$participantId}";
1710 $cancelStatusId = 0;
1711 $negativeStatuses = CRM_Event_PseudoConstant
::participantStatus(NULL, "class = 'Negative'");
1712 $cancelStatusId = array_search('Cancelled', $negativeStatuses);
1713 $where .= " AND participant.status_id != {$cancelStatusId}";
1716 SELECT participant.id, participant.contact_id
1717 FROM civicrm_participant participant
1720 $dao = CRM_Core_DAO
::executeQuery($query);
1721 while ($dao->fetch()) {
1722 $additionalIDs[$dao->id
] = $dao->contact_id
;
1725 //return if only array is required.
1726 if ($isIdsArray && $contactId) {
1727 return $additionalIDs;
1730 $preProfileID = CRM_Utils_Array
::value('additional_custom_pre_id', $values);
1731 $postProfileID = CRM_Utils_Array
::value('additional_custom_post_id', $values);
1732 //else build array of Additional participant's information.
1733 if (count($additionalIDs)) {
1734 if ($preProfileID ||
$postProfileID) {
1735 $template = CRM_Core_Smarty
::singleton();
1737 $isCustomProfile = TRUE;
1739 $title = $groupTitles = array();
1740 foreach ($additionalIDs as $pId => $cId) {
1741 //get the params submitted by participant.
1742 $participantParams = CRM_Utils_Array
::value($pId, $values['params'], array());
1744 list($profilePre, $groupTitles) = self
::buildCustomDisplay($preProfileID,
1745 'additionalCustomPre',
1755 $profile = $profilePre;
1756 // $customProfile[$i] = array_merge( $groupTitles, $customProfile[$i] );
1758 $title = $groupTitles;
1762 list($profilePost, $groupTitles) = self
::buildCustomDisplay($postProfileID,
1763 'additionalCustomPost',
1773 if (isset($profilePre)) {
1774 $profile = array_merge($profilePre, $profilePost);
1776 $title = array_merge($title, $groupTitles);
1780 $profile = $profilePost;
1782 $title = $groupTitles;
1786 $profiles[] = $profile;
1789 $customProfile['title'] = $title;
1790 $customProfile['profile'] = $profiles;
1794 return $customProfile;
1797 /* Function to retrieve all events those having location block set.
1799 * @return array $events array of all events.
1804 static function getLocationEvents() {
1808 SELECT CONCAT_WS(' :: ' , ca.name, ca.street_address, ca.city, sp.name) title, ce.loc_block_id
1809 FROM civicrm_event ce
1810 INNER JOIN civicrm_loc_block lb ON ce.loc_block_id = lb.id
1811 INNER JOIN civicrm_address ca ON lb.address_id = ca.id
1812 LEFT JOIN civicrm_state_province sp ON ca.state_province_id = sp.id
1813 ORDER BY sp.name, ca.city, ca.street_address ASC
1816 $dao = CRM_Core_DAO
::executeQuery($query);
1817 while ($dao->fetch()) {
1818 $events[$dao->loc_block_id
] = $dao->title
;
1825 * @param $locBlockId
1827 * @return int|null|string
1829 static function countEventsUsingLocBlockId($locBlockId) {
1834 $locBlockId = CRM_Utils_Type
::escape($locBlockId, 'Integer');
1837 SELECT count(*) FROM civicrm_event ce
1838 WHERE ce.loc_block_id = $locBlockId";
1840 return CRM_Core_DAO
::singleValueQuery($query);
1844 * Check if event registration is valid according to permissions AND Dates
1846 * @param array $values
1847 * @param integer $eventID
1850 static function validRegistrationRequest($values, $eventID) {
1851 // check that the user has permission to register for this event
1852 $hasPermission = CRM_Core_Permission
::event(CRM_Core_Permission
::EDIT
,
1853 $eventID, 'register for events'
1856 return $hasPermission && self
::validRegistrationDate($values);
1864 static function validRegistrationDate(&$values) {
1865 // make sure that we are between registration start date and registration end date
1866 $startDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_start_date', $values));
1867 $endDate = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('registration_end_date', $values));
1868 $eventEnd = CRM_Utils_Date
::unixTime(CRM_Utils_Array
::value('end_date', $values));
1871 if ($startDate && $startDate >= $now) {
1874 if ($endDate && $endDate < $now) {
1877 if ($eventEnd && $eventEnd < $now) {
1884 /* Function to Show - Hide the Registration Link.
1886 * @param array $values key/value event info
1887 * @return boolean true if allow registration otherwise false
1895 static function showHideRegistrationLink($values) {
1897 $session = CRM_Core_Session
::singleton();
1898 $contactID = $session->get('userID');
1899 $alreadyRegistered = FALSE;
1902 $params = array('contact_id' => $contactID);
1904 if ($eventId = CRM_Utils_Array
::value('id', $values['event'])) {
1905 $params['event_id'] = $eventId;
1907 if ($roleId = CRM_Utils_Array
::value('default_role_id', $values['event'])) {
1908 $params['role_id'] = $roleId;
1910 $alreadyRegistered = self
::checkRegistration($params);
1913 if (!empty($values['event']['allow_same_participant_emails']) ||
1921 /* Function to check if given contact is already registered.
1923 * @param array $params key/value participant info
1924 * @return boolean $alreadyRegistered true/false
1932 static function checkRegistration($params) {
1933 $alreadyRegistered = FALSE;
1934 if (empty($params['contact_id'])) {
1935 return $alreadyRegistered;
1938 $statusTypes = CRM_Event_PseudoConstant
::participantStatus(NULL, 'is_counted = 1');
1940 $participant = new CRM_Event_DAO_Participant();
1941 $participant->copyValues($params);
1943 $participant->is_test
= CRM_Utils_Array
::value('is_test', $params, 0);
1944 $participant->selectAdd();
1945 $participant->selectAdd('status_id');
1946 if ($participant->find(TRUE) && array_key_exists($participant->status_id
, $statusTypes)) {
1947 $alreadyRegistered = TRUE;
1950 return $alreadyRegistered;
1954 * make sure that the user has permission to access this event
1956 * @param null $eventId
1959 * @internal param int $id the id of the event
1960 * @internal param int $name the name or title of the event
1962 * @return string the permission that the user has (or null)
1966 static function checkPermission($eventId = NULL, $type = CRM_Core_Permission
::VIEW
) {
1967 static $permissions = NULL;
1969 if (empty($permissions)) {
1970 $allEvents = CRM_Event_PseudoConstant
::event(NULL, TRUE);
1971 $createdEvents = array();
1973 $session = CRM_Core_Session
::singleton();
1974 if ($userID = $session->get('userID')) {
1975 $createdEvents = array_keys(CRM_Event_PseudoConstant
::event(NULL, TRUE, "created_id={$userID}"));
1978 // Note: for a multisite setup, a user with edit all events, can edit all events
1979 // including those from other sites
1980 if (CRM_Core_Permission
::check('edit all events')) {
1981 $permissions[CRM_Core_Permission
::EDIT
] = array_keys($allEvents);
1984 $permissions[CRM_Core_Permission
::EDIT
] = &CRM_ACL_API
::group(CRM_Core_Permission
::EDIT
, NULL, 'civicrm_event', $allEvents, $createdEvents);
1987 if (CRM_Core_Permission
::check('edit all events')) {
1988 $permissions[CRM_Core_Permission
::VIEW
] = array_keys($allEvents);
1991 if (CRM_Core_Permission
::check('access CiviEvent') &&
1992 CRM_Core_Permission
::check('view event participants')
1994 // use case: allow "view all events" but NOT "edit all events"
1995 // so for a normal site allow users with these two permissions to view all events AND
1996 // at the same time also allow any hook to override if needed.
1997 $createdEvents = array_keys($allEvents);
1999 $permissions[CRM_Core_Permission
::VIEW
] = &CRM_ACL_API
::group(CRM_Core_Permission
::VIEW
, NULL, 'civicrm_event', $allEvents, $createdEvents);
2002 $permissions[CRM_Core_Permission
::DELETE
] = array();
2003 if (CRM_Core_Permission
::check('delete in CiviEvent')) {
2004 // Note: we want to restrict the scope of delete permission to
2005 // events that are editable/viewable (usecase multisite).
2006 // We can remove array_intersect once we have ACL support for delete functionality.
2007 $permissions[CRM_Core_Permission
::DELETE
] = array_intersect($permissions[CRM_Core_Permission
::EDIT
],
2008 $permissions[CRM_Core_Permission
::VIEW
]
2014 return in_array($eventId, $permissions[$type]) ?
TRUE : FALSE;
2017 return $permissions;
2021 * Build From Email as the combination of all the email ids of the logged in user,
2022 * the domain email id and the email id configured for the event
2024 * @param int $eventId the id of the event
2026 * @return array an array of email ids
2030 static function getFromEmailIds($eventId = NULL) {
2031 $fromEmailValues['from_email_id'] = CRM_Core_BAO_Email
::getFromEmail();
2034 // add the email id configured for the event
2035 $params = array('id' => $eventId);
2036 $returnProperties = array('confirm_from_name', 'confirm_from_email', 'cc_confirm', 'bcc_confirm');
2037 $eventEmail = array();
2039 CRM_Core_DAO
::commonRetrieve('CRM_Event_DAO_Event', $params, $eventEmail, $returnProperties);
2040 if (!empty($eventEmail['confirm_from_name']) && !empty($eventEmail['confirm_from_email'])) {
2041 $eventEmailId = "{$eventEmail['confirm_from_name']} <{$eventEmail['confirm_from_email']}>";
2043 $fromEmailValues['from_email_id'][$eventEmailId] = htmlspecialchars($eventEmailId);
2044 $fromEmailId = array('cc' => CRM_Utils_Array
::value('cc_confirm', $eventEmail),
2045 'bcc' => CRM_Utils_Array
::value('bcc_confirm', $eventEmail),
2047 $fromEmailValues = array_merge($fromEmailValues, $fromEmailId);
2051 return $fromEmailValues;
2055 * Function to calculate event total seats occupied.
2057 * @param int $eventId event id.
2058 * @param sting $extraWhereClause extra filter on participants.
2060 * @return int event total seats w/ given criteria.
2064 static function eventTotalSeats($eventId, $extraWhereClause = NULL) {
2065 if (empty($eventId)) {
2069 $extraWhereClause = trim($extraWhereClause);
2070 if (!empty($extraWhereClause)) {
2071 $extraWhereClause = " AND ( {$extraWhereClause} )";
2074 //event seats calculation :
2075 //1. consider event seat as a single when participant does not have line item.
2076 //2. consider event seat as a single when participant has line items but does not
2077 // have count for corresponding price field value ( ie price field value does not carry any seat )
2078 //3. consider event seat as a sum of all seats from line items in case price field value carries count.
2081 SELECT IF ( SUM( value.count*lineItem.qty ),
2082 SUM( value.count*lineItem.qty ) +
2083 COUNT( DISTINCT participant.id ) -
2084 COUNT( DISTINCT IF ( value.count, participant.id, NULL ) ),
2085 COUNT( DISTINCT participant.id ) )
2086 FROM civicrm_participant participant
2087 INNER JOIN civicrm_contact contact ON ( contact.id = participant.contact_id AND contact.is_deleted = 0 )
2088 INNER JOIN civicrm_event event ON ( event.id = participant.event_id )
2089 LEFT JOIN civicrm_line_item lineItem ON ( lineItem.entity_id = participant.id
2090 AND lineItem.entity_table = 'civicrm_participant' )
2091 LEFT JOIN civicrm_price_field_value value ON ( value.id = lineItem.price_field_value_id AND value.count )
2092 WHERE ( participant.event_id = %1 )
2093 AND participant.is_test = 0
2095 GROUP BY participant.event_id";
2097 return (int)CRM_Core_DAO
::singleValueQuery($query, array(1 => array($eventId, 'Positive')));
2101 * Retrieve event template default values to be set
2102 * as default values for current new event.
2104 * @params int $templateId event template id.
2106 * @return $defaults an array of custom data defaults.
2109 * @param $templateId
2113 static function getTemplateDefaultValues($templateId) {
2114 $defaults = array();
2119 $templateParams = array('id' => $templateId);
2120 CRM_Event_BAO_Event
::retrieve($templateParams, $defaults);
2121 $fieldsToExclude = array(
2124 'default_discount_fee_id',
2130 $defaults = array_diff_key($defaults, array_flip($fieldsToExclude));
2139 static function get_sub_events($event_id) {
2140 $params = array('parent_event_id' => $event_id);
2141 $defaults = array();
2142 return CRM_Event_BAO_Event
::retrieve($params, $defaults);
2146 * Update the Campaign Id of all the participants of the given event
2148 * @params int $eventID event id.
2149 * @params int $eventCampaignID campaign id of that event
2154 * @param $eventCampaignID
2156 static function updateParticipantCampaignID($eventID, $eventCampaignID) {
2158 $params[1] = array($eventID, 'Integer');
2160 if(empty($eventCampaignID)) {
2161 $query = "UPDATE civicrm_participant SET campaign_id = NULL WHERE event_id = %1";
2164 $query = "UPDATE civicrm_participant SET campaign_id = %2 WHERE event_id = %1";
2165 $params[2] = array($eventCampaignID, 'Integer');
2167 CRM_Core_DAO
::executeQuery($query, $params);
2171 * Get options for a given field.
2172 * @see CRM_Core_DAO::buildOptions
2174 * @param String $fieldName
2175 * @param String $context: @see CRM_Core_DAO::buildOptionsContext
2176 * @param Array $props: whatever is known about this dao object
2178 * @return array|bool
2180 public static function buildOptions($fieldName, $context = NULL, $props = array()) {
2182 // Special logic for fields whose options depend on context or properties
2183 switch ($fieldName) {
2184 case 'financial_type_id':
2185 // Fixme - this is going to ignore context, better to get conditions, add params, and call PseudoConstant::get
2186 return CRM_Financial_BAO_FinancialType
::getIncomeFinancialType();
2189 return CRM_Core_PseudoConstant
::get(__CLASS__
, $fieldName, $params, $context);