Skip to content

Commit

Permalink
Merge pull request #11881 from yashodha/CRM-21854
Browse files Browse the repository at this point in the history
CRM-21854 - Contribution start date and end dates are not respected
  • Loading branch information
eileenmcnaughton authored Jun 14, 2018
2 parents ffa950d + ffc1e56 commit 412f2d1
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 21 deletions.
25 changes: 25 additions & 0 deletions CRM/Contribute/Exception/FutureContributionPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class CRM_Contribute_Exception_FutureContributionPageException extends Exception {
private $id;

/**
* @param string $message
* @param int $id
*/
public function __construct($message, $id) {
parent::__construct(ts($message));
$this->id = $id;
CRM_Core_Error::debug_log_message('Access to contribution page with start date in future attempted - page number ' . $id);
}

/**
* Get Contribution page ID.
*
* @return int
*/
public function getID() {
return $this->id;
}

}
25 changes: 25 additions & 0 deletions CRM/Contribute/Exception/PastContributionPageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

class CRM_Contribute_Exception_PastContributionPageException extends Exception {
private $id;

/**
* @param string $message
* @param int $id
*/
public function __construct($message, $id) {
parent::__construct(ts($message));
$this->id = $id;
CRM_Core_Error::debug_log_message('Access to contribution page with past end date attempted - page number ' . $id);
}

/**
* Get Contribution page ID.
*
* @return int
*/
public function getID() {
return $this->id;
}

}
11 changes: 11 additions & 0 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ public function preProcess() {
throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id);
}

$endDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $this->_values));
$now = date('YmdHis');
if ($endDate && $endDate < $now) {
throw new CRM_Contribute_Exception_PastContributionPageException(ts('The page you requested has past its end date on ' . CRM_Utils_Date::customFormat($endDate)), $this->_id);
}

$startDate = CRM_Utils_Date::processDate(CRM_Utils_Array::value('start_date', $this->_values));
if ($startDate && $startDate > $now) {
throw new CRM_Contribute_Exception_FutureContributionPageException(ts('The page you requested will be active from ' . CRM_Utils_Date::customFormat($startDate)), $this->_id);
}

$this->assignBillingType();

// check for is_monetary status
Expand Down
10 changes: 1 addition & 9 deletions CRM/Contribute/Form/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,14 +332,6 @@ public function setDefaultValues() {
if ($this->_priceSetID) {
$defaults['price_set_id'] = $this->_priceSetID;
}

if (!empty($defaults['end_date'])) {
list($defaults['end_date'], $defaults['end_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['end_date']);
}

if (!empty($defaults['start_date'])) {
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($defaults['start_date']);
}
}
else {
$defaults['is_active'] = 1;
Expand All @@ -353,7 +345,7 @@ public function setDefaultValues() {
), '1');
}
else {
# CRM 10860
// CRM-10860
$defaults['recur_frequency_unit'] = array('month' => 1);
}

Expand Down
8 changes: 2 additions & 6 deletions CRM/Contribute/Form/ContributionPage/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ public function buildQuickForm() {
}

// add optional start and end dates
$this->addDateTime('start_date', ts('Start Date'));
$this->addDateTime('end_date', ts('End Date'));
$this->add('datepicker', 'start_date', ts('Start Date'));
$this->add('datepicker', 'end_date', ts('End Date'));

$this->addFormRule(array('CRM_Contribute_Form_ContributionPage_Settings', 'formRule'), $this);

Expand Down Expand Up @@ -334,10 +334,6 @@ public function postProcess() {
$params['is_credit_card_only'] = CRM_Utils_Array::value('is_credit_card_only', $params, FALSE);
$params['honor_block_is_active'] = CRM_Utils_Array::value('honor_block_is_active', $params, FALSE);
$params['is_for_organization'] = !empty($params['is_organization']) ? CRM_Utils_Array::value('is_for_organization', $params, FALSE) : 0;

$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time'], TRUE);
$params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], TRUE);

$params['goal_amount'] = CRM_Utils_Rule::cleanMoney($params['goal_amount']);

if (!$params['honor_block_is_active']) {
Expand Down
8 changes: 2 additions & 6 deletions templates/CRM/Contribute/Form/ContributionPage/Settings.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,11 @@
</tr>
<tr class="crm-contribution-contributionpage-settings-form-block-start_date">
<td class ="label">{$form.start_date.label} {help id="id-start_date"}</td>
<td>
{include file="CRM/common/jcalendar.tpl" elementName=start_date}
</td>
<td>{$form.start_date.html}</td>
</tr>
<tr class="crm-contribution-contributionpage-settings-form-block-end_date">
<td class ="label">{$form.end_date.label}</td>
<td>
{include file="CRM/common/jcalendar.tpl" elementName=end_date}
</td>
<td>{$form.end_date.html}</td>
</tr>
<tr class="crm-contribution-contributionpage-settings-form-block-honor_block_is_active">
<td>&nbsp;</td><td>{$form.honor_block_is_active.html}{$form.honor_block_is_active.label} {help id="id-honoree_section"}</td>
Expand Down

0 comments on commit 412f2d1

Please sign in to comment.