From c2be40dc40e5be4e8f8d4455afcf3db2fc6fed2c Mon Sep 17 00:00:00 2001 From: Andrew Hunt Date: Wed, 7 Aug 2013 19:54:40 -0400 Subject: [PATCH] 3 months of events & don't check payment for past events --- CRM/Activity/BAO/Activity.php | 2 +- .../Form/Search/Custom/EventAggregate.php | 2 +- CRM/Event/BAO/Event.php | 14 ++++++++++--- CRM/Event/Form/EventFees.php | 5 +++-- CRM/Event/Form/Participant.php | 9 +++++---- CRM/Event/Page/AJAX.php | 3 ++- templates/CRM/Event/Form/Participant.tpl | 20 ++++++++++++------- 7 files changed, 36 insertions(+), 19 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 09af16d78b..e9e5e5ad9f 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -1788,7 +1788,7 @@ SELECT display_name $component = 'Membership'; } elseif ($activity->__table == 'civicrm_participant') { - $event = CRM_Event_BAO_Event::getEvents(TRUE, $activity->event_id, TRUE, FALSE); + $event = CRM_Event_BAO_Event::getEvents(1, $activity->event_id, TRUE, FALSE); $roles = CRM_Event_PseudoConstant::participantRole(); $status = CRM_Event_PseudoConstant::participantStatus(); diff --git a/CRM/Contact/Form/Search/Custom/EventAggregate.php b/CRM/Contact/Form/Search/Custom/EventAggregate.php index b7b86ca725..f6e1230e61 100644 --- a/CRM/Contact/Form/Search/Custom/EventAggregate.php +++ b/CRM/Contact/Form/Search/Custom/EventAggregate.php @@ -74,7 +74,7 @@ class CRM_Contact_Form_Search_Custom_EventAggregate extends CRM_Contact_Form_Sea foreach ($event_type as $eventId => $eventName) { $form->addElement('checkbox', "event_type_id[$eventId]", 'Event Type', $eventName); } - $events = CRM_Event_BAO_Event::getEvents(TRUE); + $events = CRM_Event_BAO_Event::getEvents(1); $form->add('select', 'event_id', ts('Event Name'), array('' => ts('- select -')) + $events); $form->addDate('start_date', ts('Payments Date From'), FALSE, array('formatType' => 'custom')); diff --git a/CRM/Event/BAO/Event.php b/CRM/Event/BAO/Event.php index 97d35cbdc4..f399d2dcea 100644 --- a/CRM/Event/BAO/Event.php +++ b/CRM/Event/BAO/Event.php @@ -254,14 +254,16 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event { /** * Function to get current/future Events * - * @param $all boolean true if events all are required else returns current and future events + * @param $all int 0 returns current and future events + * 1 if events all are required + * 2 returns events since 3 months ago * @param $id int id of a specific event to return * @param $isActive boolean true if you need only active events * @param $checkPermission boolean true if you need to check permission else false * * @static */ - static function getEvents($all = FALSE, + static function getEvents($all = 0, $id = FALSE, $isActive = TRUE, $checkPermission = TRUE @@ -274,10 +276,16 @@ WHERE ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )"; if ($id) { $query .= " AND `id` = {$id}"; } - elseif (!$all) { + elseif ($all == 0) { + // find only events ending in the future $endDate = date('YmdHis'); $query .= " AND ( `end_date` >= {$endDate} OR end_date IS NULL )"; } + elseif ($all == 2) { + // find only events starting in the last 3 months + $startDate = date('YmdHis', strtotime('3 months ago')); + $query .= " AND ( `start_date` >= {$startDate} OR start_date IS NULL )"; + } if ($isActive) { $query .= " AND civicrm_event.is_active = 1"; } diff --git a/CRM/Event/Form/EventFees.php b/CRM/Event/Form/EventFees.php index 303933f8b8..f0890fc5be 100644 --- a/CRM/Event/Form/EventFees.php +++ b/CRM/Event/Form/EventFees.php @@ -78,7 +78,7 @@ class CRM_Event_Form_EventFees { if ($form->_eventId) { //get receipt text and financial type - $returnProperities = array( 'confirm_email_text', 'financial_type_id', 'campaign_id' ); + $returnProperities = array( 'confirm_email_text', 'financial_type_id', 'campaign_id', 'start_date' ); $details = array(); CRM_Core_DAO::commonRetrieveAll('CRM_Event_DAO_Event', 'id', $form->_eventId, $details, $returnProperities); if ( CRM_Utils_Array::value( 'financial_type_id', $details[$form->_eventId] ) ) { @@ -121,7 +121,8 @@ class CRM_Event_Form_EventFees { //CRM-11601 we should keep the record contribution //true by default while adding participant - if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent) { + if ($form->_action == CRM_Core_Action::ADD && !$form->_mode && $form->_isPaidEvent + && strtotime(CRM_Utils_Array::value('start_date', $details[$form->_eventId])) >= time()) { $defaults[$form->_pId]['record_contribution'] = 1; } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index bf4823d384..3f9a0d6d9c 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -751,13 +751,14 @@ SELECT civicrm_custom_group.name as name, if ( $this->_eID ) { $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID,'end_date'); } - $this->assign('past', FALSE); + $this->assign('past', 0); if ($this->_action & CRM_Core_Action::UPDATE) { - $events = CRM_Event_BAO_Event::getEvents(TRUE, FALSE, FALSE); + $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE); } elseif ($this->getElementValue('past_event') || (isset($eventEndDate) && (CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)))) { - $events = CRM_Event_BAO_Event::getEvents(TRUE); - $this->assign('past', TRUE); + $pastval = $this->getElementValue('past_event'); + $events = CRM_Event_BAO_Event::getEvents($pastval); + $this->assign('past', $pastval); } else { $events = CRM_Event_BAO_Event::getEvents(); diff --git a/CRM/Event/Page/AJAX.php b/CRM/Event/Page/AJAX.php index bbc4bf6e8d..77672acc09 100644 --- a/CRM/Event/Page/AJAX.php +++ b/CRM/Event/Page/AJAX.php @@ -119,7 +119,8 @@ GROUP BY cv.label"; } function eventList() { - $events = CRM_Event_BAO_Event::getEvents(TRUE); + $listparams = CRM_Utils_Array::value('listall', $_REQUEST, 1); + $events = CRM_Event_BAO_Event::getEvents($listparams); $elements = array(array('name' => ts('- select -'), 'value' => '', diff --git a/templates/CRM/Event/Form/Participant.tpl b/templates/CRM/Event/Form/Participant.tpl index 2e1d685999..34135b1b67 100644 --- a/templates/CRM/Event/Form/Participant.tpl +++ b/templates/CRM/Event/Form/Participant.tpl @@ -216,9 +216,10 @@ {/if} {$form.event_id.label}{$form.event_id.html}  - {if $action eq 1 && !$past } -
» {ts}Include past event(s) in this select list.{/ts} + {if $action eq 1 && $past neq 1 } +
» {ts}Include past event(s) in this select list:{/ts} + {if !$past}{ts}past three months{/ts} |{/if} + {ts}all{/ts}
{/if} {if $is_test} {ts}(test){/ts} @@ -285,17 +286,22 @@ {literal}