<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
class CRM_Event_BAO_Participant extends CRM_Event_DAO_Participant {
/**
- * static field for all the participant information that we can potentially import
+ * Static field for all the participant information that we can potentially import
*
* @var array
* @static
static $_importableFields = NULL;
/**
- * static field for all the participant information that we can potentially export
+ * Static field for all the participant information that we can potentially export
*
* @var array
* @static
static $_exportableFields = NULL;
/**
- * static array for valid status transitions rules
+ * Static array for valid status transitions rules
*
* @var array
* @static
);
/**
- *
*/
- function __construct() {
+ public function __construct() {
parent::__construct();
}
/**
- * takes an associative array and creates a participant object
+ * Takes an associative array and creates a participant object
*
* the function extract all the params it needs to initialize the create a
* participant object. the params array could contain additional unused name/value
* pairs
*
- * @param array $params (reference ) an assoc array of name/value pairs
- *
- * @internal param array $ids the array that holds all the db ids
+ * @param array $params
+ * (reference ) an assoc array of name/value pairs.
*
- * @return object CRM_Event_BAO_Participant object
- * @access public
+ * @return CRM_Event_BAO_Participant object
* @static
*/
- static function &add(&$params) {
+ public static function &add(&$params) {
if (!empty($params['id'])) {
CRM_Utils_Hook::pre('edit', 'Participant', $params['id'], $params);
* Given the list of params in the params array, fetch the object
* and store the values in the values array
*
- * @param array $params input parameters to find object
- * @param array $values output values of the object
+ * @param array $params
+ * Input parameters to find object.
+ * @param array $values
+ * Output values of the object.
*
* @param $ids
*
* @return CRM_Event_BAO_Participant|null the found object or null
- * @access public
* @static
*/
- static function getValues(&$params, &$values, &$ids) {
+ public static function getValues(&$params, &$values, &$ids) {
if (empty($params)) {
return NULL;
}
}
/**
- * takes an associative array and creates a participant object
+ * Takes an associative array and creates a participant object
*
- * @param array $params (reference ) an assoc array of name/value pairs
+ * @param array $params
+ * (reference ) an assoc array of name/value pairs.
*
- * @internal param array $ids the array that holds all the db ids
- *
- * @return object CRM_Event_BAO_Participant object
- * @access public
+ * @return CRM_Event_BAO_Participant object
* @static
*/
- static function create(&$params) {
+ public static function create(&$params) {
$transaction = new CRM_Core_Transaction();
$status = NULL;
$noteValue = NULL;
$hasNoteField = FALSE;
foreach (array(
- 'note', 'participant_note') as $noteFld) {
+ 'note',
+ 'participant_note',
+ ) as $noteFld) {
if (array_key_exists($noteFld, $params)) {
$noteValue = $params[$noteFld];
$hasNoteField = TRUE;
* Check whether the event is full for participation and return as
* per requirements.
*
- * @param int $eventId event id.
- * @param boolean $returnEmptySeats are we require number if empty seats.
- * @param boolean $includeWaitingList consider waiting list in event full
+ * @param int $eventId
+ * Event id.
+ * @param bool $returnEmptySeats
+ * Are we require number if empty seats.
+ * @param bool $includeWaitingList
+ * Consider waiting list in event full.
* calculation or not. (it is for cron job purpose)
*
* @param bool $returnWaitingCount
* @param bool $considerTestParticipant
*
- * @return bool|int|null|string 1. false => If event having some empty spaces.@static
- * @access public
+ * @return bool|int|null|string
+ * 1. false => If event having some empty spaces.
+ * @static
*/
static function eventFull(
$eventId,
// It might be case there are some empty spaces and still event
// is full, as waitlist might represent group require spaces > empty.
- $participantRoles = CRM_Event_PseudoConstant::participantRole(NULL, 'filter = 1');
- $countedStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
- $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
+ $participantRoles = CRM_Event_PseudoConstant::participantRole(NULL, 'filter = 1');
+ $countedStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1');
+ $waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
$onWaitlistStatusId = array_search('On waitlist', $waitingStatuses);
//when we do require only waiting count don't consider counted.
if ($includeWaitingList && $onWaitlistStatusId) {
//build the where clause.
- $whereClause = ' WHERE ' . implode(' AND ', $where);
- $whereClause .= " AND participant.status_id = $onWaitlistStatusId ";
+ $whereClause = ' WHERE ' . implode(' AND ', $where);
+ $whereClause .= " AND participant.status_id = $onWaitlistStatusId ";
$eventSeatsWhere = implode(' AND ', $where) . " AND ( participant.status_id = $onWaitlistStatusId )";
$query = "
INNER JOIN civicrm_event event ON ( event.id = participant.event_id )
{$whereClause}";
- $eventFullText = ts('This event is full!!!');
+ $eventFullText = ts('This event is full.');
$participants = CRM_Core_DAO::executeQuery($query, $eventParams);
while ($participants->fetch()) {
//oops here event is full and we don't want waiting count.
}
//consider only counted participants.
- $where[] = ' participant.status_id IN ( ' . implode(', ', array_keys($countedStatuses)) . ' ) ';
- $whereClause = ' WHERE ' . implode(' AND ', $where);
+ $where[] = ' participant.status_id IN ( ' . implode(', ', array_keys($countedStatuses)) . ' ) ';
+ $whereClause = ' WHERE ' . implode(' AND ', $where);
$eventSeatsWhere = implode(' AND ', $where);
$query = "
{$whereClause}";
$eventMaxSeats = NULL;
- $eventFullText = ts('This event is full !!!');
- $participants = CRM_Core_DAO::executeQuery($query, $eventParams);
+ $eventFullText = ts('This event is full.');
+ $participants = CRM_Core_DAO::executeQuery($query, $eventParams);
while ($participants->fetch()) {
if ($participants->event_full_text) {
$eventFullText = $participants->event_full_text;
* Return the array of all price set field options,
* with total participant count that field going to carry.
*
- * @param int $eventId event id.
+ * @param int $eventId
+ * Event id.
* @param array $skipParticipantIds
+ * An array of participant ids those we should skip.
* @param bool $considerCounted
* @param bool $considerWaiting
* @param bool $considerTestParticipants
*
- * @internal param array $skipParticipants an array of participant ids those we should skip.
- * @internal param int $isTest would you like to consider test participants.
- *
- * @return array $optionsCount an array of each option id and total count
+ * @return array
+ * an array of each option id and total count
* @static
- * @access public
*/
static function priceSetOptionsCount(
$eventId,
* Get the empty spaces for event those we can allocate
* to pending participant to become confirm.
*
- * @param int $eventId event id.
+ * @param int $eventId
+ * Event id.
*
- * @return int $spaces Number of Empty Seats/null.
+ * @return int
+ * $spaces Number of Empty Seats/null.
* @static
- * @access public
*/
- static function pendingToConfirmSpaces($eventId) {
+ public static function pendingToConfirmSpaces($eventId) {
$emptySeats = 0;
if (!$eventId) {
return $emptySeats;
}
/**
- * combine all the importable fields from the lower levels object
+ * Combine all the importable fields from the lower levels object
*
* @param string $contactType
* @param bool $status
* @param bool $onlyParticipant
*
- * @return array array of importable Fields
- * @access public
+ * @return array
+ * array of importable Fields
* @static
*/
- static function &importableFields($contactType = 'Individual', $status = TRUE, $onlyParticipant = FALSE) {
+ public static function &importableFields($contactType = 'Individual', $status = TRUE, $onlyParticipant = FALSE) {
if (!self::$_importableFields) {
if (!$onlyParticipant) {
if (!$status) {
'title' => ts('Participant Note'),
'name' => 'participant_note',
'headerPattern' => '/(participant.)?note$/i',
- ));
+ ),
+ );
// Split status and status id into 2 fields
// Fixme: it would be better to leave as 1 field and intelligently handle both during import
'title' => ts('Participant Status'),
'name' => 'participant_status',
'data_type' => CRM_Utils_Type::T_STRING,
- ));
+ ),
+ );
$tmpFields['participant_status_id']['title'] = ts('Participant Status Id');
// Split role and role id into 2 fields
'title' => ts('Participant Role'),
'name' => 'participant_role',
'data_type' => CRM_Utils_Type::T_STRING,
- ));
+ ),
+ );
$tmpFields['participant_role_id']['title'] = ts('Participant Role Id');
$eventType = array(
'title' => ts('Event Type'),
'name' => 'event_type',
'data_type' => CRM_Utils_Type::T_STRING,
- ));
+ ),
+ );
$tmpContactField = $contactFields = array();
- $contactFields = array( );
+ $contactFields = array();
if (!$onlyParticipant) {
$contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
// Using new Dedupe rule.
$ruleParams = array(
'contact_type' => $contactType,
- 'used' => 'Unsupervised',
+ 'used' => 'Unsupervised',
);
$fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
}
/**
- * combine all the exportable fields from the lower levels object
+ * Combine all the exportable fields from the lower levels object
*
- * @return array array of exportable Fields
- * @access public
+ * @return array
+ * array of exportable Fields
* @static
*/
- static function &exportableFields() {
+ public static function &exportableFields() {
if (!self::$_exportableFields) {
if (!self::$_exportableFields) {
self::$_exportableFields = array();
$participantFields = CRM_Event_DAO_Participant::export();
$noteField = array(
- 'participant_note' => array('title' => 'Participant Note',
+ 'participant_note' => array(
+ 'title' => 'Participant Note',
'name' => 'participant_note',
- ));
+ ),
+ );
$participantStatus = array(
- 'participant_status' => array('title' => 'Participant Status',
+ 'participant_status' => array(
+ 'title' => 'Participant Status',
'name' => 'participant_status',
- ));
+ ),
+ );
$participantRole = array(
- 'participant_role' => array('title' => 'Participant Role',
+ 'participant_role' => array(
+ 'title' => 'Participant Role',
'name' => 'participant_role',
- ));
+ ),
+ );
//CRM-13595 add event id to participant export
$eventid = array(
- 'event_id' => array('title' => 'Event ID',
+ 'event_id' => array(
+ 'title' => 'Event ID',
'name' => 'event_id',
- ));
+ ),
+ );
$eventtitle = array(
- 'event_title' => array('title' => 'Event Title',
+ 'event_title' => array(
+ 'title' => 'Event Title',
'name' => 'event_title',
- ));
+ ),
+ );
- $discountFields = CRM_Core_DAO_Discount::export();
+ $discountFields = CRM_Core_DAO_Discount::export();
$fields = array_merge($participantFields, $participantStatus, $participantRole, $eventid, $eventtitle, $noteField, $discountFields);
}
/**
- * function to get the event name/sort name for a particular participation / participant
+ * Get the event name/sort name for a particular participation / participant
*
- * @param int $participantId id of the participant
-
+ * @param int $participantId
+ * Id of the participant.
*
- * @return array $name associated array with sort_name and event title
+ * @return array
+ * associated array with sort_name and event title
* @static
- * @access public
*/
- static function participantDetails($participantId) {
+ public static function participantDetails($participantId) {
$query = "
SELECT civicrm_contact.sort_name as name, civicrm_event.title as title, civicrm_contact.id as cid
FROM civicrm_participant
$details = array();
while ($dao->fetch()) {
- $details['name'] = $dao->name;
+ $details['name'] = $dao->name;
$details['title'] = $dao->title;
- $details['cid'] = $dao->cid;
+ $details['cid'] = $dao->cid;
}
return $details;
/**
* Get the values for pseudoconstants for name->value and reverse.
*
- * @param array $defaults (reference) the default values, some of which need to be resolved.
- * @param boolean $reverse true if we want to resolve the values in the reverse direction (value -> name)
+ * @param array $defaults
+ * (reference) the default values, some of which need to be resolved.
+ * @param bool $reverse
+ * True if we want to resolve the values in the reverse direction (value -> name).
*
* @return void
- * @access public
* @static
*/
- static function resolveDefaults(&$defaults, $reverse = FALSE) {
+ public static function resolveDefaults(&$defaults, $reverse = FALSE) {
self::lookupValue($defaults, 'event', CRM_Event_PseudoConstant::event(), $reverse);
self::lookupValue($defaults, 'status', CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'), $reverse);
self::lookupValue($defaults, 'role', CRM_Event_PseudoConstant::participantRole(), $reverse);
}
/**
- * This function is used to convert associative array names to values
+ * convert associative array names to values
* and vice-versa.
*
* This function is used by both the web form layer and the api. Note that
* the api needs the name => value conversion, also the view layer typically
* requires value => name conversion
*/
- static function lookupValue(&$defaults, $property, $lookup, $reverse) {
+ public static function lookupValue(&$defaults, $property, $lookup, $reverse) {
$id = $property . '_id';
$src = $reverse ? $property : $id;
/**
* Delete the record that are associated with this participation
*
- * @param int $id id of the participation to delete
+ * @param int $id
+ * Id of the participation to delete.
*
* @return void
- * @access public
* @static
*/
- static function deleteParticipant($id) {
+ public static function deleteParticipant($id) {
CRM_Utils_Hook::pre('delete', 'Participant', $id, CRM_Core_DAO::$_nullArray);
$transaction = new CRM_Core_Transaction();
CRM_Event_BAO_ParticipantPayment::deleteParticipantPayment($p);
// cleanup line items.
- $participantsId = array();
- $participantsId = self::getAdditionalParticipantIds($id);
+ $participantsId = array();
+ $participantsId = self::getAdditionalParticipantIds($id);
$participantsId[] = $id;
CRM_Price_BAO_LineItem::deleteLineItems($participantsId, 'civicrm_participant');
/**
* Checks duplicate participants
*
- * @param array $duplicates (reference ) an assoc array of name/value pairs
- * @param array $input an assosiative array of name /value pairs
+ * @param array $duplicates
+ * (reference ) an assoc array of name/value pairs.
+ * @param array $input
+ * An assosiative array of name /value pairs.
* from other function
*
- * @return object CRM_Contribute_BAO_Contribution object
- * @access public
+ * @return CRM_Contribute_BAO_Contribution object
* @static
*/
- static function checkDuplicate($input, &$duplicates) {
+ public static function checkDuplicate($input, &$duplicates) {
$eventId = CRM_Utils_Array::value('event_id', $input);
$contactId = CRM_Utils_Array::value('contact_id', $input);
$clause = implode(' AND ', $clause);
- $query = "SELECT id FROM civicrm_participant WHERE $clause";
- $dao = CRM_Core_DAO::executeQuery($query, $input);
+ $query = "SELECT id FROM civicrm_participant WHERE $clause";
+ $dao = CRM_Core_DAO::executeQuery($query, $input);
$result = FALSE;
while ($dao->fetch()) {
$duplicates[] = $dao->id;
}
/**
- * fix the event level
+ * Fix the event level
*
* When price sets are used as event fee, fee_level is set as ^A
* separated string. We need to change that string to comma
* separated string before using fee_level in view mode.
*
- * @param string $eventLevel event_leval string from db
+ * @param string $eventLevel
+ * Event_leval string from db.
*
* @static
*
* @return void
*/
- static function fixEventLevel(&$eventLevel) {
+ public static function fixEventLevel(&$eventLevel) {
if ((substr($eventLevel, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR) &&
(substr($eventLevel, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR)
) {
}
elseif ((substr($eventLevel, 0, 1) == CRM_Core_DAO::VALUE_SEPARATOR)) {
$eventLevel = implode(', ', explode(CRM_Core_DAO::VALUE_SEPARATOR,
- substr($eventLevel, 0, 1)
- ));
+ substr($eventLevel, 0, 1)
+ ));
}
elseif ((substr($eventLevel, -1, 1) == CRM_Core_DAO::VALUE_SEPARATOR)) {
$eventLevel = implode(', ', explode(CRM_Core_DAO::VALUE_SEPARATOR,
- substr($eventLevel, 0, -1)
- ));
+ substr($eventLevel, 0, -1)
+ ));
}
}
/**
- * get the additional participant ids.
+ * Get the additional participant ids.
*
- * @param int $primaryParticipantId primary partycipant Id
- * @param boolean $excludeCancel do not include participant those are cancelled.
+ * @param int $primaryParticipantId
+ * Primary partycipant Id.
+ * @param bool $excludeCancel
+ * Do not include participant those are cancelled.
*
- * @param null $oldStatusId
+ * @param int $oldStatusId
*
- * @return array $additionalParticipantIds
+ * @return array
* @static
*/
- static function getAdditionalParticipantIds($primaryParticipantId, $excludeCancel = TRUE, $oldStatusId = NULL) {
+ public static function getAdditionalParticipantIds($primaryParticipantId, $excludeCancel = TRUE, $oldStatusId = NULL) {
$additionalParticipantIds = array();
if (!$primaryParticipantId) {
return $additionalParticipantIds;
$where = "participant.registered_by_id={$primaryParticipantId}";
if ($excludeCancel) {
- $cancelStatusId = 0;
+ $cancelStatusId = 0;
$negativeStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'");
- $cancelStatusId = array_search('Cancelled', $negativeStatuses);
+ $cancelStatusId = array_search('Cancelled', $negativeStatuses);
$where .= " AND participant.status_id != {$cancelStatusId}";
}
* Get the event fee info for given participant ids
* either from line item table / participant table.
*
- * @param array $participantIds participant ids.
- * @param boolean $hasLineItems do fetch from line items.
+ * @param array $participantIds
+ * Participant ids.
+ * @param bool $hasLineItems
+ * Do fetch from line items.
*
- * @return array $feeDetails
+ * @return array
* @static
*/
- function getFeeDetails($participantIds, $hasLineItems = FALSE) {
+ public function getFeeDetails($participantIds, $hasLineItems = FALSE) {
$feeDetails = array();
if (!is_array($participantIds) || empty($participantIds)) {
return $feeDetails;
$where = 'WHERE participant.id IN ( ' . implode(', ', $participantIds) . ' )';
$query = "$select $from $where";
- $feeInfo = CRM_Core_DAO::executeQuery($query);
- $feeProperties = array('fee_level', 'fee_amount');
+ $feeInfo = CRM_Core_DAO::executeQuery($query);
+ $feeProperties = array('fee_level', 'fee_amount');
$lineProperties = array(
- 'lineId', 'label', 'qty', 'unit_price',
- 'line_total', 'field_title', 'html_type',
- 'price_field_id', 'participant_count', 'price_field_value_id', 'description',
+ 'lineId',
+ 'label',
+ 'qty',
+ 'unit_price',
+ 'line_total',
+ 'field_title',
+ 'html_type',
+ 'price_field_id',
+ 'participant_count',
+ 'price_field_value_id',
+ 'description',
);
while ($feeInfo->fetch()) {
if ($hasLineItems) {
}
}
else {
- foreach ($feeProperties as $property) $feeDetails[$feeInfo->id][$property] = $feeInfo->$property;
+ foreach ($feeProperties as $property) {
+ $feeDetails[$feeInfo->id][$property] = $feeInfo->$property;
+ }
}
}
* Retrieve additional participants display-names and URL to view their participant records.
* (excludes cancelled participants automatically)
*
- * @param int $primaryParticipantID id of primary participant record
+ * @param int $primaryParticipantID
+ * Id of primary participant record.
*
- * @return array $additionalParticipants $displayName => $viewUrl
+ * @return array
+ * $displayName => $viewUrl
* @static
*/
- static function getAdditionalParticipants($primaryParticipantID) {
+ public static function getAdditionalParticipants($primaryParticipantID) {
$additionalParticipantIDs = array();
$additionalParticipantIDs = self::getAdditionalParticipantIds($primaryParticipantID);
if (!empty($additionalParticipantIDs)) {
/**
* Function for update primary and additional participant status
*
- * @param int $participantID primary participant's id
- * @param $oldStatusID
- * @param null $newStatusID
+ * @param int $participantID
+ * Primary participant's id.
+ * @param int $oldStatusID
+ * @param int $newStatusID
* @param bool $updatePrimaryStatus
*
- * @internal param int $statusId status id for participant
- * return void
- *
- * @return bool
- * @access public
+ * @return bool|void
* @static
*/
- static function updateParticipantStatus($participantID, $oldStatusID, $newStatusID = NULL, $updatePrimaryStatus = FALSE) {
+ public static function updateParticipantStatus($participantID, $oldStatusID, $newStatusID = NULL, $updatePrimaryStatus = FALSE) {
if (!$participantID || !$oldStatusID) {
return;
}
/**
* Function for update status for given participant ids
*
- * @param int $participantIds array of participant ids
- * @param int $statusId status id for participant
+ * @param int $participantIds
+ * Array of participant ids.
+ * @param int $statusId
+ * Status id for participant.
* @param bool $updateRegisterDate
- * @params boolean $updateRegisterDate way to track when status changed.
*
- * return void
+ * @return void
*
- * @access public
* @static
*/
- static function updateStatus($participantIds, $statusId, $updateRegisterDate = FALSE) {
+ public static function updateStatus($participantIds, $statusId, $updateRegisterDate = FALSE) {
if (!is_array($participantIds) || empty($participantIds) || !$statusId) {
return;
}
* update status from $fromStatusId to $toStatusId
* and send mail + create activities.
*
- * @param array $participantIds participant ids.
- * @param int $toStatusId update status id.
- * @param int $fromStatusId from status id
+ * @param array $participantIds
+ * Participant ids.
+ * @param int $toStatusId
+ * Update status id.
+ * @param int $fromStatusId
+ * From status id.
*
* return void
* @param bool $returnResult
* @param bool $skipCascadeRule
*
* @return array
- * @access public
* @static
*/
- static function transitionParticipants($participantIds, $toStatusId,
+ static function transitionParticipants(
+ $participantIds, $toStatusId,
$fromStatusId = NULL, $returnResult = FALSE, $skipCascadeRule = FALSE
) {
if (!is_array($participantIds) || empty($participantIds) || !$toStatusId) {
$contactIds = $eventIds = $participantDetails = array();
- $statusTypes = CRM_Event_PseudoConstant::participantStatus();
+ $statusTypes = CRM_Event_PseudoConstant::participantStatus();
$participantRoles = CRM_Event_PseudoConstant::participantRole();
- $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL,
+ $pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL,
"class = 'Pending'"
);
if (empty($domainValues)) {
// making all tokens available to templates.
$domain = CRM_Core_BAO_Domain::getDomain();
- $tokens = array('domain' => array('name', 'phone', 'address', 'email'),
+ $tokens = array(
+ 'domain' => array('name', 'phone', 'address', 'email'),
'contact' => CRM_Core_SelectValues::contactTokens(),
);
//now we are ready w/ all required data.
//take a decision as per statuses.
- $emailType = NULL;
- $toStatus = $statusTypes[$toStatusId];
+ $emailType = NULL;
+ $toStatus = $statusTypes[$toStatusId];
$fromStatus = CRM_Utils_Array::value($fromStatusId, $statusTypes);
switch ($toStatus) {
}
/**
- * Function to send mail and create activity
+ * Send mail and create activity
* when participant status changed.
*
- * @param int $participantId participant id.
- * @param array $participantValues participant detail values. status id for participants
- * @param array $eventDetails required event details
- * @param array $contactDetails required contact details
- * @param array $domainValues required domain values.
- * @param string $mailType (eg 'approval', 'confirm', 'expired' )
+ * @param int $participantId
+ * Participant id.
+ * @param array $participantValues
+ * Participant detail values. status id for participants.
+ * @param array $eventDetails
+ * Required event details.
+ * @param array $contactDetails
+ * Required contact details.
+ * @param array $domainValues
+ * Required domain values.
+ * @param string $mailType
+ * (eg 'approval', 'confirm', 'expired' ).
*
* return void
*
* @return bool
- * @access public
* @static
*/
static function sendTransitionParticipantMail(
// 3. create activity record.
if ($mailSent) {
- $now = date('YmdHis');
- $activityType = 'Event Registration';
+ $now = date('YmdHis');
+ $activityType = 'Event Registration';
$activityParams = array(
'subject' => $subject,
'source_contact_id' => $contactId,
}
/**
- * get participant status change message.
+ * Get participant status change message.
*
- * @param $participantId
+ * @param int $participantId
* @param $statusChangeTo
- * @param $fromStatusId
+ * @param int $fromStatusId
*
* @return string
- * @access public
*/
- function updateStatusMessage($participantId, $statusChangeTo, $fromStatusId) {
+ public function updateStatusMessage($participantId, $statusChangeTo, $fromStatusId) {
$statusMsg = NULL;
$results = self::transitionParticipants(array($participantId),
$statusChangeTo, $fromStatusId, TRUE
array_key_exists($processedId, $results['mailedParticipants'])
) {
$statusMsg .= '<br /> ' . ts("Participant status has been updated to '%1'. An email has been sent to %2.",
- array(
- 1 => $allStatuses[$statusChangeTo],
- 2 => $results['mailedParticipants'][$processedId],
- )
- );
+ array(
+ 1 => $allStatuses[$statusChangeTo],
+ 2 => $results['mailedParticipants'][$processedId],
+ )
+ );
}
}
}
}
/**
- * get event full and waiting list message.
+ * Get event full and waiting list message.
*
- * @param $eventId
- * @param null $participantId
+ * @param int $eventId
+ * @param int $participantId
*
* @return string
- * @access public
*/
- static function eventFullMessage($eventId, $participantId = NULL) {
+ public static function eventFullMessage($eventId, $participantId = NULL) {
$eventfullMsg = $dbStatusId = NULL;
$checkEventFull = TRUE;
if ($participantId) {
if (is_string($emptySeats) && $emptySeats !== NULL) {
$maxParticipants = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'max_participants');
$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(
- 1 => $maxParticipants)) . '<br />';
+ 1 => $maxParticipants,
+ )) . '<br />';
}
$hasWaiting = FALSE;
}
/**
- * check for whether participant is primary or not
+ * Check for whether participant is primary or not
*
- * @param $participantId
+ * @param int $participantId
*
- * @return true if participant is primary
- * @access public
+ * @return bool
+ * true if participant is primary
*/
- static function isPrimaryParticipant($participantId) {
+ public static function isPrimaryParticipant($participantId) {
$participant = new CRM_Event_DAO_Participant();
$participant->registered_by_id = $participantId;
}
/**
- * get additional participant Ids for cascading with primary participant status
+ * Get additional participant Ids for cascading with primary participant status
*
- * @param int $participantId participant id.
- * @param int $oldStatusId previous status
- * @param int $newStatusId new status
+ * @param int $participantId
+ * Participant id.
+ * @param int $oldStatusId
+ * Previous status.
+ * @param int $newStatusId
+ * New status.
*
- * @return true if allowed
- * @access public
+ * @return bool
+ * true if allowed
*/
- static function getValidAdditionalIds($participantId, $oldStatusId, $newStatusId) {
+ public static function getValidAdditionalIds($participantId, $oldStatusId, $newStatusId) {
$additionalParticipantIds = array();
}
/**
- * Function to get participant record count for a Contact
+ * Get participant record count for a Contact
*
- * @param $contactID
+ * @param int $contactID
*
- * @internal param int $contactId Contact ID
- *
- * @return int count of participant records
- * @access public
+ * @return int
+ * count of participant records
* @static
*/
- static function getContactParticipantCount($contactID) {
+ public static function getContactParticipantCount($contactID) {
$query = "SELECT count(*)
FROM civicrm_participant
WHERE civicrm_participant.contact_id = {$contactID} AND
}
/**
- * Function to get participant ids by contribution id
+ * Get participant ids by contribution id
*
- * @param int $contributionId Contribution Id
- * @param bool $excludeCancelled Exclude cancelled additional participant
+ * @param int $contributionId
+ * Contribution Id.
+ * @param bool $excludeCancelled
+ * Exclude cancelled additional participant.
*
- * @return array $participantsId
- * @access public
+ * @return array
* @static
*/
- static function getParticipantIds($contributionId, $excludeCancelled = FALSE) {
+ public static function getParticipantIds($contributionId, $excludeCancelled = FALSE) {
$ids = array();
if (!$contributionId) {
// get additional participant ids (including cancelled)
if ($participantId) {
$ids = array_merge(array(
- $participantId), self::getAdditionalParticipantIds($participantId,
- $excludeCancelled
- ));
+ $participantId,
+ ), self::getAdditionalParticipantIds($participantId,
+ $excludeCancelled
+ ));
}
return $ids;
}
/**
- * Function to get additional Participant edit & view url .
+ * Get additional Participant edit & view url .
*
- * @param $participantIds
+ * @param array $participantIds
+ * An array of additional participant ids.
*
- * @internal param array $paticipantIds an array of additional participant ids.
- *
- * @return array of Urls.
- * @access public
+ * @return array
+ * of Urls.
* @static
*/
- static function getAdditionalParticipantUrl($participantIds) {
+ public static function getAdditionalParticipantUrl($participantIds) {
foreach ($participantIds as $value) {
- $links = array();
+ $links = array();
$details = self::participantDetails($value);
$viewUrl = CRM_Utils_System::url('civicrm/contact/view/participant',
"action=view&reset=1&id={$value}&cid={$details['cid']}"
}
/**
- * to create trxn entry if an event has discount.
+ * create trxn entry if an event has discount.
*
- * @param int $eventID event id
- * @param array $contributionParams contribution params.
+ * @param int $eventID
+ * Event id.
+ * @param array $contributionParams
+ * Contribution params.
*
* @param $feeLevel
*
* @static
*/
- static function createDiscountTrxn($eventID, $contributionParams, $feeLevel) {
+ public static function createDiscountTrxn($eventID, $contributionParams, $feeLevel) {
// CRM-11124
- $checkDiscount = CRM_Core_BAO_Discount::findSet($eventID,'civicrm_event');
+ $checkDiscount = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
if (!empty($checkDiscount)) {
$feeLevel = current($feeLevel);
$priceSetId = CRM_Price_BAO_PriceSet::getFor('civicrm_event', $eventID, NULL);
$query = "SELECT cpfv.amount FROM `civicrm_price_field_value` cpfv
LEFT JOIN civicrm_price_field cpf ON cpfv.price_field_id = cpf.id
WHERE cpf.price_set_id = %1 AND cpfv.label LIKE %2";
- $params = array(1 => array($priceSetId, 'Integer'),
- 2 => array($feeLevel, 'String'));
+ $params = array(
+ 1 => array($priceSetId, 'Integer'),
+ 2 => array($feeLevel, 'String'),
+ );
$mainAmount = CRM_Core_DAO::singleValueQuery($query, $params);
$relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Discounts Account is' "));
$contributionParams['trxnParams']['from_financial_account_id'] = CRM_Contribute_PseudoConstant::financialAccountType(
if (!empty($contributionParams['trxnParams']['from_financial_account_id'])) {
$contributionParams['trxnParams']['total_amount'] = $mainAmount - $contributionParams['total_amount'];
$contributionParams['trxnParams']['payment_processor_id'] = $contributionParams['trxnParams']['payment_instrument_id'] =
- $contributionParams['trxnParams']['check_number'] = $contributionParams['trxnParams']['trxn_id'] =
- $contributionParams['trxnParams']['net_amount'] = $contributionParams['trxnParams']['fee_amount'] = NULL;
+ $contributionParams['trxnParams']['check_number'] = $contributionParams['trxnParams']['trxn_id'] =
+ $contributionParams['trxnParams']['net_amount'] = $contributionParams['trxnParams']['fee_amount'] = NULL;
CRM_Core_BAO_FinancialTrxn::create($contributionParams['trxnParams']);
}
}
/**
- * Function to delete participants of contact
+ * Delete participants of contact
*
* CRM-12155
*
- * @param integer $contactId contact id
+ * @param int $contactId
+ * Contact id.
*
- * @access public
* @static
*/
- static function deleteContactParticipant($contactId) {
+ public static function deleteContactParticipant($contactId) {
$participant = new CRM_Event_DAO_Participant();
$participant->contact_id = $contactId;
$participant->find();
}
/**
- * @param $params
- * @param $participantId
- * @param $contributionId
+ * @param array $params
+ * @param int $participantId
+ * @param int $contributionId
* @param $feeBlock
- * @param $lineItems
+ * @param array $lineItems
* @param $paidAmount
- * @param $priceSetId
+ * @param int $priceSetId
*/
- static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId) {
+ public static function changeFeeSelections($params, $participantId, $contributionId, $feeBlock, $lineItems, $paidAmount, $priceSetId) {
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
$pendingRefundStatusId = array_search('Pending refund', $contributionStatuses);
CRM_Price_BAO_LineItem::format($id, $params, $values, $submittedLineItems);
$submittedFieldId[] = CRM_Utils_Array::retrieveValueRecursive($submittedLineItems, 'price_field_id');
}
- $insertLines = $submittedLineItems;
-
- $submittedFieldValueIds = array_keys($submittedLineItems);
- $updateLines = array();
- foreach ($previousLineItems as $id => $previousLineItem) {
- // check through the submitted items if the previousItem exists,
- // if found in submitted items, do not use it for new item creations
- if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
- // if submitted line items are existing don't fire INSERT query
- unset($insertLines[$previousLineItem['price_field_value_id']]);
- // for updating the line items i.e. use-case - once deselect-option selecting again
- if ($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) {
- $updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
- $updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
+ if (!empty($submittedLineItems)) {
+ $insertLines = $submittedLineItems;
+
+ $submittedFieldValueIds = array_keys($submittedLineItems);
+ $updateLines = array();
+ foreach ($previousLineItems as $id => $previousLineItem) {
+ // check through the submitted items if the previousItem exists,
+ // if found in submitted items, do not use it for new item creations
+ if (in_array($previousLineItem['price_field_value_id'], $submittedFieldValueIds)) {
+ // if submitted line items are existing don't fire INSERT query
+ unset($insertLines[$previousLineItem['price_field_value_id']]);
+ // for updating the line items i.e. use-case - once deselect-option selecting again
+ if (($previousLineItem['line_total'] != $submittedLineItems[$previousLineItem['price_field_value_id']]['line_total']) ||
+ ($submittedLineItems[$previousLineItem['price_field_value_id']]['line_total'] == 0 && $submittedLineItems[$previousLineItem['price_field_value_id']]['qty'] == 1)
+ ) {
+ $updateLines[$previousLineItem['price_field_value_id']] = $submittedLineItems[$previousLineItem['price_field_value_id']];
+ $updateLines[$previousLineItem['price_field_value_id']]['id'] = $id;
+ }
}
}
- }
-
- $submittedFields = implode(', ', $submittedFieldId);
- $submittedFieldValues = implode(', ', $submittedFieldValueIds);
+ $submittedFields = implode(', ', $submittedFieldId);
+ $submittedFieldValues = implode(', ', $submittedFieldValueIds);
+ }
if (!empty($submittedFields) && !empty($submittedFieldValues)) {
$updateLineItem = "UPDATE civicrm_line_item li
INNER JOIN civicrm_financial_item fi
// if not submitted and difference is not 0 make it negative
if (!in_array($updateFinancialItemInfoValues['price_field_value_id'], $submittedFieldValueIds) && $updateFinancialItemInfoValues['differenceAmt'] != 0) {
// INSERT negative financial_items
- $updateFinancialItemInfoValues['amount'] = - $updateFinancialItemInfoValues['amount'];
+ $updateFinancialItemInfoValues['amount'] = -$updateFinancialItemInfoValues['amount'];
CRM_Financial_BAO_FinancialItem::create($updateFinancialItemInfoValues, NULL, $trxnId);
// INSERT negative financial_items for tax amount
if ($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']) {
- $updateFinancialItemInfoValues['amount'] = - ($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']);
+ $updateFinancialItemInfoValues['amount'] = -($previousLineItems[$updateFinancialItemInfoValues['entity_id']]['tax_amount']);
$updateFinancialItemInfoValues['description'] = $taxTerm;
if ($updateFinancialItemInfoValues['financial_type_id']) {
$updateFinancialItemInfoValues['financial_account_id'] = CRM_Contribute_BAO_Contribution::getFinancialAccountId($updateFinancialItemInfoValues['financial_type_id']);
}
}
}
-
+ elseif (empty($submittedFields) && empty($submittedFieldValues)) {
+ $updateLineItem = "UPDATE civicrm_line_item li
+ INNER JOIN civicrm_financial_item fi
+ ON (li.id = fi.entity_id AND fi.entity_table = 'civicrm_line_item')
+ SET li.qty = 0,
+ li.line_total = 0.00,
+ li.tax_amount = NULL
+ WHERE (li.entity_table = 'civicrm_participant' AND li.entity_id = {$participantId})";
+ CRM_Core_DAO::executeQuery($updateLineItem);
+ }
if (!empty($updateLines)) {
foreach ($updateLines as $valueId => $vals) {
if (isset($vals['tax_amount'])) {
// insert new 'adjusted amount' transaction entry and update contribution entry.
// ensure entity_financial_trxn table has a linking of it.
// insert new line items
- foreach ($insertLines as $valueId => $lineParams) {
- $lineParams['entity_table'] = 'civicrm_participant';
- $lineParams['entity_id'] = $participantId;
- $lineParams['contribution_id'] = $contributionId;
- $lineObj = CRM_Price_BAO_LineItem::create($lineParams);
+ if (!empty($insertLines)) {
+ foreach ($insertLines as $valueId => $lineParams) {
+ $lineParams['entity_table'] = 'civicrm_participant';
+ $lineParams['entity_id'] = $participantId;
+ $lineParams['contribution_id'] = $contributionId;
+ $lineObj = CRM_Price_BAO_LineItem::create($lineParams);
+ }
}
// the recordAdjustedAmt code would execute over here
$fetchCon = array('id' => $contributionId);
$updatedContribution = CRM_Contribute_BAO_Contribution::retrieve($fetchCon, CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
// insert financial items
- foreach ($insertLines as $valueId => $lineParams) {
- $lineParams['entity_table'] = 'civicrm_participant';
- $lineParams['entity_id'] = $participantId;
- $lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
- // insert financial items
- // ensure entity_financial_trxn table has a linking of it.
- $prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution);
- if (isset($lineObj->tax_amount)) {
- CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution, TRUE);
+ if (!empty($insertLines)) {
+ foreach ($insertLines as $valueId => $lineParams) {
+ $lineParams['entity_table'] = 'civicrm_participant';
+ $lineParams['entity_id'] = $participantId;
+ $lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams, CRM_Core_DAO::$_nullArray);
+ // insert financial items
+ // ensure entity_financial_trxn table has a linking of it.
+ $prevItem = CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution);
+ if (isset($lineObj->tax_amount)) {
+ CRM_Financial_BAO_FinancialItem::add($lineObj, $updatedContribution, TRUE);
+ }
}
}
// update participant fee_amount column
$partUpdateFeeAmt['id'] = $participantId;
+ foreach ($lineItems as $lineValue) {
+ if ($lineValue['price_field_value_id']) {
+ $line[$lineValue['price_field_value_id']] = $lineValue['label'] . ' - ' . $lineValue['qty'];
+ }
+ }
+
+ $partUpdateFeeAmt['fee_level'] = implode(', ', $line);
$partUpdateFeeAmt['fee_amount'] = $params['amount'];
self::add($partUpdateFeeAmt);
/**
* @param $updatedAmount
* @param $paidAmount
- * @param $contributionId
+ * @param int $contributionId
*/
- static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL) {
+ public static function recordAdjustedAmt($updatedAmount, $paidAmount, $contributionId, $taxAmount = NULL) {
$balanceAmt = $updatedAmount - $paidAmount;
$contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
$partiallyPaidStatusId = array_search('Partially paid', $contributionStatuses);
'payment_instrument_id' => $updatedContribution->payment_instrument_id,
'contribution_id' => $updatedContribution->id,
'trxn_date' => date('YmdHis'),
- 'currency' => $updatedContribution->currency
+ 'currency' => $updatedContribution->currency,
);
$adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
}
}
/**
- * @param $participantId
+ * @param int $participantId
* @param $activityType
*
* @throws CRM_Core_Exception
*/
- static function addActivityForSelection($participantId, $activityType) {
+ public static function addActivityForSelection($participantId, $activityType) {
$eventId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantId, 'event_id');
$contactId = CRM_Core_DAO::getFieldValue('CRM_Event_BAO_Participant', $participantId, 'contact_id');
}
CRM_Activity_BAO_Activity::create($activityParams);
}
+
+ /**
+ * Get options for a given field.
+ * @see CRM_Core_DAO::buildOptions
+ *
+ * @param string $fieldName
+ * @param string $context
+ * : @see CRM_Core_DAO::buildOptionsContext.
+ * @param array $props
+ * : whatever is known about this dao object.
+ *
+ * @return Array|bool
+ */
+ public static function buildOptions($fieldName, $context = NULL, $props = array()) {
+ $params = array('condition' => array());
+
+ if ($fieldName == 'status_id' && $context != 'validate') {
+ // Get rid of cart-related option if disabled
+ // FIXME: Why does this option even exist if cart is disabled?
+ if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart')) {
+ $params['condition'][] = "name <> 'Pending in cart'";
+ }
+ }
+
+ return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
+ }
}