本文整理汇总了PHP中CRM_Event_BAO_Event::eventTotalSeats方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Event_BAO_Event::eventTotalSeats方法的具体用法?PHP CRM_Event_BAO_Event::eventTotalSeats怎么用?PHP CRM_Event_BAO_Event::eventTotalSeats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Event_BAO_Event
的用法示例。
在下文中一共展示了CRM_Event_BAO_Event::eventTotalSeats方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: eventFull
/**
* Check whether the event is full for participation and return as.
* per requirements.
*
* @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.
*/
public static function eventFull($eventId, $returnEmptySeats = FALSE, $includeWaitingList = TRUE, $returnWaitingCount = FALSE, $considerTestParticipant = FALSE)
{
$result = NULL;
if (!$eventId) {
return $result;
}
// consider event is full when.
// 1. (count(is_counted) >= event_size) or
// 2. (count(participants-with-status-on-waitlist) > 0)
// 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'");
$onWaitlistStatusId = array_search('On waitlist', $waitingStatuses);
//when we do require only waiting count don't consider counted.
if (!$returnWaitingCount && !empty($countedStatuses)) {
$allStatusIds = array_keys($countedStatuses);
}
$where = array(' event.id = %1 ');
if (!$considerTestParticipant) {
$where[] = ' ( participant.is_test = 0 OR participant.is_test IS NULL ) ';
}
if (!empty($participantRoles)) {
$escapedRoles = array();
foreach (array_keys($participantRoles) as $participantRole) {
$escapedRoles[] = CRM_Utils_Type::escape($participantRole, 'String');
}
$where[] = " participant.role_id IN ( '" . implode("', '", $escapedRoles) . "' ) ";
}
$eventParams = array(1 => array($eventId, 'Positive'));
//in case any waiting, straight forward event is full.
if ($includeWaitingList && $onWaitlistStatusId) {
//build the where clause.
$whereClause = ' WHERE ' . implode(' AND ', $where);
$whereClause .= " AND participant.status_id = {$onWaitlistStatusId} ";
$eventSeatsWhere = implode(' AND ', $where) . " AND ( participant.status_id = {$onWaitlistStatusId} )";
$query = "\n SELECT participant.id id,\n event.event_full_text as event_full_text\n FROM civicrm_participant participant\nINNER JOIN civicrm_event event ON ( event.id = participant.event_id )\n {$whereClause}";
$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.
if ($returnWaitingCount) {
return CRM_Event_BAO_Event::eventTotalSeats($eventId, $eventSeatsWhere);
} else {
return $participants->event_full_text ? $participants->event_full_text : $eventFullText;
}
}
}
//consider only counted participants.
$where[] = ' participant.status_id IN ( ' . implode(', ', array_keys($countedStatuses)) . ' ) ';
$whereClause = ' WHERE ' . implode(' AND ', $where);
$eventSeatsWhere = implode(' AND ', $where);
$query = "\n SELECT participant.id id,\n event.event_full_text as event_full_text,\n event.max_participants as max_participants\n FROM civicrm_participant participant\nINNER JOIN civicrm_event event ON ( event.id = participant.event_id )\n {$whereClause}";
$eventMaxSeats = NULL;
$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;
}
$eventMaxSeats = $participants->max_participants;
//don't have limit for event seats.
if ($participants->max_participants == NULL) {
return $result;
}
}
//get the total event seats occupied by these participants.
$eventRegisteredSeats = CRM_Event_BAO_Event::eventTotalSeats($eventId, $eventSeatsWhere);
if ($eventRegisteredSeats) {
if ($eventRegisteredSeats >= $eventMaxSeats) {
$result = $eventFullText;
} elseif ($returnEmptySeats) {
$result = $eventMaxSeats - $eventRegisteredSeats;
}
return $result;
} else {
$query = '
SELECT event.event_full_text,
event.max_participants
FROM civicrm_event event
WHERE event.id = %1';
//.........这里部分代码省略.........
示例2: updateParticipantStatus
public function updateParticipantStatus()
{
require_once 'CRM/Event/PseudoConstant.php';
$participantRole = CRM_Event_PseudoConstant::participantRole();
$pendingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Pending'");
$expiredStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Negative'");
$waitingStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, "class = 'Waiting'");
//build the required status ids.
$statusIds = '(' . implode(',', array_merge(array_keys($pendingStatuses), array_keys($waitingStatuses))) . ')';
$participantDetails = $fullEvents = array();
$expiredParticipantCount = $waitingConfirmCount = $waitingApprovalCount = 0;
//get all participant who's status in class pending and waiting
$query = "SELECT * FROM civicrm_participant WHERE status_id IN {$statusIds} ORDER BY register_date";
$query = "\n SELECT participant.id,\n participant.contact_id,\n participant.status_id,\n participant.register_date,\n participant.registered_by_id,\n participant.event_id,\n event.title as eventTitle,\n event.registration_start_date,\n event.registration_end_date,\n event.end_date,\n event.expiration_time,\n event.requires_approval\n FROM civicrm_participant participant\nLEFT JOIN civicrm_event event ON ( event.id = participant.event_id )\n WHERE participant.status_id IN {$statusIds}\n AND (event.end_date > now() OR event.end_date IS NULL)\n AND event.is_active = 1 \n ORDER BY participant.register_date, participant.id \n";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$participantDetails[$dao->id] = array('id' => $dao->id, 'event_id' => $dao->event_id, 'status_id' => $dao->status_id, 'contact_id' => $dao->contact_id, 'register_date' => $dao->register_date, 'registered_by_id' => $dao->registered_by_id, 'eventTitle' => $dao->eventTitle, 'registration_start_date' => $dao->registration_start_date, 'registration_end_date' => $dao->registration_end_date, 'end_date' => $dao->end_date, 'expiration_time' => $dao->expiration_time, 'requires_approval' => $dao->requires_approval);
}
if (!empty($participantDetails)) {
//cron 1. move participant from pending to expire if needed
foreach ($participantDetails as $participantId => $values) {
//process the additional participant at the time of
//primary participant, don't process separately.
if (CRM_Utils_Array::value('registered_by_id', $values)) {
continue;
}
$expirationTime = CRM_Utils_Array::value('expiration_time', $values);
if ($expirationTime && array_key_exists($values['status_id'], $pendingStatuses)) {
//get the expiration and registration pending time.
$expirationSeconds = $expirationTime * 3600;
$registrationPendingSeconds = CRM_Utils_Date::unixTime($values['register_date']);
// expired registration since registration cross allow confirmation time.
if ($expirationSeconds + $registrationPendingSeconds < time()) {
//lets get the transaction mechanism.
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
require_once 'CRM/Event/BAO/Participant.php';
$ids = array($participantId);
$expiredId = array_search('Expired', $expiredStatuses);
$results = CRM_Event_BAO_Participant::transitionParticipants($ids, $expiredId, $values['status_id'], TRUE, TRUE);
$transaction->commit();
if (!empty($results)) {
//diaplay updated participants
if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
foreach ($results['updatedParticipantIds'] as $processedId) {
$expiredParticipantCount += 1;
echo "<br /><br />- status updated to: Expired";
//mailed participants.
if (is_array($results['mailedParticipants']) && array_key_exists($processedId, $results['mailedParticipants'])) {
echo "<br />Expiration Mail sent to: {$results['mailedParticipants'][$processedId]}";
}
}
}
}
}
}
}
//cron 1 end.
//cron 2. lets move participants from waiting list to pending status
foreach ($participantDetails as $participantId => $values) {
//process the additional participant at the time of
//primary participant, don't process separately.
if (CRM_Utils_Array::value('registered_by_id', $values)) {
continue;
}
if (array_key_exists($values['status_id'], $waitingStatuses) && !array_key_exists($values['event_id'], $fullEvents)) {
if ($waitingStatuses[$values['status_id']] == 'On waitlist' && CRM_Event_BAO_Event::validRegistrationDate($values)) {
//check the target event having space.
require_once 'CRM/Event/BAO/Participant.php';
$eventOpenSpaces = CRM_Event_BAO_Participant::eventFull($values['event_id'], TRUE, FALSE);
if ($eventOpenSpaces && is_numeric($eventOpenSpaces) || $eventOpenSpaces === NULL) {
//get the additional participant if any.
$additionalIds = CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId);
$allIds = array($participantId);
if (!empty($additionalIds)) {
$allIds = array_merge($allIds, $additionalIds);
}
$pClause = ' participant.id IN ( ' . implode(' , ', $allIds) . ' )';
$requiredSpaces = CRM_Event_BAO_Event::eventTotalSeats($values['event_id'], $pClause);
//need to check as to see if event has enough speces
if ($requiredSpaces <= $eventOpenSpaces || $eventOpenSpaces === NULL) {
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
require_once 'CRM/Event/BAO/Participant.php';
$ids = array($participantId);
$updateStatusId = array_search('Pending from waitlist', $pendingStatuses);
//lets take a call to make pending or need approval
if ($values['requires_approval']) {
$updateStatusId = array_search('Awaiting approval', $waitingStatuses);
}
$results = CRM_Event_BAO_Participant::transitionParticipants($ids, $updateStatusId, $values['status_id'], TRUE, TRUE);
//commit the transaction.
$transaction->commit();
if (!empty($results)) {
//diaplay updated participants
if (is_array($results['updatedParticipantIds']) && !empty($results['updatedParticipantIds'])) {
foreach ($results['updatedParticipantIds'] as $processedId) {
if ($values['requires_approval']) {
$waitingApprovalCount += 1;
echo "<br /><br />- status updated to: Awaiting approval";
//.........这里部分代码省略.........
示例3: buildQuickForm
/**
* Build the form object.
*
*
* @return void
*/
public function buildQuickForm()
{
parent::buildQuickForm();
$this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
CRM_Event_BAO_Query::buildSearchForm($this);
$rows = $this->get('rows');
if (is_array($rows)) {
$lineItems = $eventIds = array();
if (!$this->_single) {
$this->addRowSelectors($rows);
}
foreach ($rows as $row) {
$eventIds[$row['event_id']] = $row['event_id'];
if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
// add line item details if applicable
$lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
}
}
//get actual count only when we are dealing w/ single event.
$participantCount = 0;
if (count($eventIds) == 1) {
//convert form values to clause.
$seatClause = array();
if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') {
$seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
}
if (!empty($this->_formValues['participant_status_id'])) {
$seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int');
if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) {
$this->_formValues['participant_status_id'] = $status;
}
}
if (!empty($this->_formValues['participant_role_id'])) {
$seatClause[] = '( participant.role_id IN ( ' . implode(' , ', (array) $this->_formValues['participant_role_id']) . ' ) )';
}
// CRM-15379
if (!empty($this->_formValues['participant_fee_id'])) {
$participant_fee_id = $this->_formValues['participant_fee_id'];
$feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label');
$feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel));
$seatClause[] = "( participant.fee_level LIKE '%{$feeLabel}%' )";
}
$seatClause = implode(' AND ', $seatClause);
$participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause);
}
$this->assign('participantCount', $participantCount);
$this->assign('lineItems', $lineItems);
$permission = CRM_Core_Permission::getPermission();
$tasks = CRM_Event_Task::permissionedTaskTitles($permission);
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
}
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'));
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
$this->addTaskMenu($tasks);
}
}
示例4: buildQuickForm
/**
* Build the form object.
*
*
* @return void
*/
public function buildQuickForm()
{
parent::buildQuickForm();
$this->addSortNameField();
if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) {
$this->addElement('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
}
CRM_Event_BAO_Query::buildSearchForm($this);
$rows = $this->get('rows');
if (is_array($rows)) {
$lineItems = $eventIds = array();
if (!$this->_single) {
$this->addRowSelectors($rows);
}
foreach ($rows as $row) {
$eventIds[$row['event_id']] = $row['event_id'];
if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
// add line item details if applicable
$lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
}
}
//get actual count only when we are dealing w/ single event.
$participantCount = 0;
if (count($eventIds) == 1) {
//convert form values to clause.
$seatClause = array();
if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') {
$seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
}
if (!empty($this->_formValues['participant_status_id'])) {
$seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int');
if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) {
$this->_formValues['participant_status_id'] = $status;
}
}
if (!empty($this->_formValues['participant_role_id'])) {
$escapedRoles = array();
foreach ((array) $this->_formValues['participant_role_id'] as $participantRole) {
$escapedRoles[] = CRM_Utils_Type::escape($participantRole, 'String');
}
$seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )";
}
// CRM-15379
if (!empty($this->_formValues['participant_fee_id'])) {
$participant_fee_id = $this->_formValues['participant_fee_id'];
foreach ($participant_fee_id as $k => &$val) {
$val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
$val = CRM_Core_DAO::escapeString(trim($val));
}
$feeLabel = implode('|', $participant_fee_id);
$seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )";
}
$seatClause = implode(' AND ', $seatClause);
$participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause);
}
$this->assign('participantCount', $participantCount);
$this->assign('lineItems', $lineItems);
$permission = CRM_Core_Permission::getPermission();
$tasks = CRM_Event_Task::permissionedTaskTitles($permission);
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
}
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'));
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
$this->addTaskMenu($tasks);
}
}
示例5: buildQuickForm
/**
* Build the form
*
* @access public
*
* @return void
*/
function buildQuickForm()
{
$this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
CRM_Event_BAO_Query::buildSearchForm($this);
/*
* add form checkboxes for each row. This is needed out here to conform to QF protocol
* of all elements being declared in builQuickForm
*/
$rows = $this->get('rows');
if (is_array($rows)) {
$lineItems = $eventIds = array();
if (!$this->_single) {
$this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);"));
}
foreach ($rows as $row) {
$eventIds[$row['event_id']] = $row['event_id'];
if (!$this->_single) {
$this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');"));
}
if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
// add line item details if applicable
$lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']);
}
}
//get actual count only when we are dealing w/ single event.
$participantCount = 0;
if (count($eventIds) == 1) {
//convert form values to clause.
$seatClause = array();
// Filter on is_test if specified in search form
if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') {
$seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
}
if (CRM_Utils_Array::value('participant_status_id', $this->_formValues)) {
$statuses = array_keys($this->_formValues['participant_status_id']);
$seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )';
}
if (CRM_Utils_Array::value('participant_role_id', $this->_formValues)) {
$roles = array_keys($this->_formValues['participant_role_id']);
$seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )';
}
$clause = NULL;
if (!empty($seatClause)) {
$clause = implode(' AND ', $seatClause);
}
$participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $clause);
}
$this->assign('participantCount', $participantCount);
$this->assign('lineItems', $lineItems);
$total = $cancel = 0;
$permission = CRM_Core_Permission::getPermission();
$tasks = array('' => ts('- actions -')) + CRM_Event_Task::permissionedTaskTitles($permission);
if (isset($this->_ssID)) {
if ($permission == CRM_Core_Permission::EDIT) {
$tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
}
$savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'));
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
$this->add('select', 'task', ts('Actions:') . ' ', $tasks);
$this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);"));
$this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);"));
// need to perform tasks on all or selected items ? using radio_ts(task selection) for it
$this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
$this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );"));
}
// add buttons
$this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE)));
}