Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#964 Add start date and end date values on page contribution widget ajax response #14262

Merged
merged 1 commit into from
May 19, 2019

Conversation

francescbassas
Copy link
Contributor

@francescbassas francescbassas commented May 16, 2019

Overview

Contribution page widgets calls civicrm/extern/widget.php to extract info of the campaign related to the widget. In some cases it maybe interesting to have the time to start or to finish the campaign to customize the widget with options such as "Starts in X days", "Ends in X days" or anything else.

in the line of https://issues.civicrm.org/jira/browse/CRM-21454

Before

After

Json response includes "start_date":YYYY-MM-DD hh:mm:ss,"time_to_end":YYYY-MM-DD hh:mm:ss if start date and end date are defined respectively.

Comments

An example of how to take advantage of these new fields:

var start_date = new Date(jsonvar.start_date.replace(/ /g,"T"));
var end_date = new Date(jsonvar.end_date.replace(/ /g,"T"));
var now = Date.now();

if ( start_date > now ) {
  var time_left = start_date - now;
  if ( time_left > 86400000 ) {
    document.getElementById('crm_cpid_'+cpid+'_status-item').innerHTML =
    "Starts in " + Math.ceil(time_left/86400000) + " days";
  }
  else {
    document.getElementById('crm_cpid_'+cpid+'_status-item').innerHTML =
    "Starts in " + Math.ceil(time_left3600000) + " hours";
  }
}
else if (end_date < now) {
  document.getElementById('crm_cpid_'+cpid+'_status-item').style.display = "none";
}
else {
  var time_left = end_date - now;
  if ( time_left > 86400000 ) {
    document.getElementById('crm_cpid_'+cpid+'_status-item').innerHTML =
    "Ends in " +Math.ceil(time_left/86400000) + " days";
  }
  else {
    document.getElementById('crm_cpid_'+cpid+'_status-item').innerHTML =
    "Ends in " +Math.ceil(time_left/3600000) + " hours";
  }
}

"start_date" and "end_date" values also allows customize predefined "campaign_start" messages ('Campaign starts on %1', 'Campaign ended on %1', etc.)

@civibot
Copy link

civibot bot commented May 16, 2019

(Standard links)

@civibot civibot bot added the master label May 16, 2019
@francescbassas francescbassas changed the title dev/core#964 Add time to start an time to end on page contribution widget ajax response dev/core#964 Add time start and end values on page contribution widget ajax response May 17, 2019
@@ -127,6 +127,8 @@ public static function getContributionPageData($contributionPageID, $widgetID, $
$now = time();
if ($dao->start_date) {
$startDate = CRM_Utils_Date::unixTime($dao->start_date);
$data['stard_date'] = $startDate;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo here in the word "stard"

@colemanw
Copy link
Member

I think it would be more consistent with everything else in civi if you return the ISO format for start_date & end_date instead of a timestamp.

Also I'm not wild about the "time to start" and "time to end" since that's generally something that should be calculated & updated in real-time by javascript. As soon as you fetch this data it will be outdated, moreso if any kind of caching is used.

@francescbassas francescbassas changed the title dev/core#964 Add time start and end values on page contribution widget ajax response dev/core#964 Add start date and end date values on page contribution widget ajax response May 19, 2019
@francescbassas
Copy link
Contributor Author

@colemanw, I agree with your comments, I have already applied the changes. If you do it for good, I will change the description of the PR according to the changes. Thanks!

@colemanw
Copy link
Member

Ok this looks useful and harmless as it's just adding a couple other bits of data to an ajax response.

@colemanw colemanw merged commit 0af0b7b into civicrm:master May 19, 2019
@francescbassas francescbassas deleted the patch-16 branch May 19, 2019 16:32
@francescbassas
Copy link
Contributor Author

Thanks @colemanw

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants