Skip to content

Commit

Permalink
2.3.7 - Number of Days
Browse files Browse the repository at this point in the history
Calculate and display the number of days between a selected range
  • Loading branch information
PromInc committed Jan 11, 2016
1 parent e9dcc95 commit 9fcb4fb
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 17 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.3.7 - 2016-01-11
### Added
- Display date range on report and datepicker for number of days selected

## 2.3.6 - 2016-01-08
### Bug Fix
- The preset date range pickers were adding a day and the report wasn't displaying the accurate date range
Expand Down
16 changes: 16 additions & 0 deletions organic-search-analytics/inc/code/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ public function getDateRangeArray( $strDateFrom, $strDateTo ) {
}


/**
* Calculate the number of days between two dates
*
* @param $start String Start date
* @param $end String End Date
* @param $include_end_day Bool Whether or not to include the end date in calculation
* Default: true
*
* @returns Int Number of days between the two dates
*/
public function getNumDays( $start, $end, $include_end_day = true) {
$num_days = floor( ( strtotime( $end ) - strtotime( $start ) ) / ( 60*60*24 ) );
if( $include_end_day ) { $num_days = $num_days + 1; }
return $num_days;
}

/**
* Get the current date/time
*
Expand Down
2 changes: 1 addition & 1 deletion organic-search-analytics/inc/code/dataCapture.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DataCapture

const GOOGLE_SEARCH_ANALYTICS_MAX_DATE_OFFSET = 4;
const GOOGLE_SEARCH_ANALYTICS_MAX_DAYS = 90;

public $core;
public $mysql;

Expand Down
9 changes: 8 additions & 1 deletion organic-search-analytics/inc/code/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
class Reports
{

public $core;

function __construct() {
$this->core = new Core(); //Load core
}

/**
* Import array of Bing Search Keywords to database
*
Expand Down Expand Up @@ -254,7 +260,8 @@ public function getReportQueryAndHeading( $reportParams ) {
if( isset( $reportParams['date_start'] ) && $reportParams['date_start'] > 0 && $reportParams['date_type'] == 'hard_set' ) {
if( isset( $reportParams['date_end'] ) && $reportParams['date_end'] > 0 ) {
$return['whereClauseItemsTable'][] = "date >= '" . $reportParams['date_start'] . "' AND date <= '" . $reportParams['date_end'] . "'";
$return['pageHeadingItems'][] = "Dates: " . $reportParams['date_start'] . " to " . $reportParams['date_end'];
$num_days = $this->core->getNumDays( $reportParams['date_start'], $reportParams['date_end'] );
$return['pageHeadingItems'][] = "Dates: " . $reportParams['date_start'] . " to " . $reportParams['date_end'] . " (" . $num_days . " day" . ( $num_days > 1 ? "s" : "" ) . ")";
} else {
$return['whereClauseItemsTable'][] = "date = '" . $reportParams['date_start'] . "'";
$return['pageHeadingItems'][] = "Date: " . $reportParams['date_start'];
Expand Down
28 changes: 14 additions & 14 deletions organic-search-analytics/inc/html/reportSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@
<?php $tooltip = "Select to set a date range" ?>
<span>
<input type="radio" name="date_type" id="date_type_hard_set" value="hard_set"<?php echo ( isset( $reportParams['date_type'] ) && $reportParams['date_type'] == 'hard_set' ? $checkedTrue : $checkedFalse ) ?>>
<label for="date_type_hard_set" tooltip="<?php echo $tooltip ?>">Specific Dates</label>
<?php
$date_range_display = "";
if( isset( $reportParams['date_type'] ) && $reportParams['date_type'] == 'hard_set' ) {
$num_days = $core->getNumDays( $reportParams['date_start'], $reportParams['date_end'] );
$date_range_display = " (" . $num_days . " day" . ( $num_days > 1 ? "s" : "" ) . ")";
}
?>
<label for="date_type_hard_set" tooltip="<?php echo $tooltip ?>">Specific Dates<span id="date_range_count"><?php echo $date_range_display ?></span></label>
</span>
</div>

Expand Down Expand Up @@ -124,7 +131,10 @@
defaultDate: "<?php echo $datePicker_start ?>",
dateFormat: "yy-mm-dd",
minDate: "<?php echo $row["min"] ?>",
maxDate: "<?php echo $row["max"] ?>"
maxDate: "<?php echo $row["max"] ?>",
onSelect: function( selectedDate ) {
updateDateRange();
}
});
/* Date Picker - End */
$( "#date_end_inline" ).datepicker({
Expand All @@ -138,20 +148,10 @@
minDate: "<?php echo $row["min"] ?>",
maxDate: "<?php echo $row["max"] ?>",
onSelect: function( selectedDate ) {
updateStartDate( selectedDate );
updateStartDate( '#date_start_inline', selectedDate );
updateDateRange();
}
});
/* Date Picker - Prevent start date from being later than end date */
function updateStartDate( endDate ) {
$( "#date_start_inline" ).datepicker( "option", "maxDate", endDate );
}

/* Tooltips */
$( "label" ).tooltip({
items: "label[tooltip]",
content: function() { return $( this ).attr('tooltip'); },
tooltipClass: "tooltips"
});
});
</script>
<div class="clear"></div>
Expand Down
47 changes: 47 additions & 0 deletions organic-search-analytics/js/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jQuery("#report-custom input:radio[name=groupBy]").change(function(e){
jQuery("#report-custom input:radio[name=date_type]").change(function(e){
if( e.target.id == "date_type_hard_set" ) {
jQuery( "#paramGroup_dateStart, #paramGroup_dateEnd" ).show();
updateDateRange();
} else {
jQuery( "#paramGroup_dateStart, #paramGroup_dateEnd" ).hide();
}
Expand All @@ -92,4 +93,50 @@ jQuery(".expandable").each(function(){
jQuery( '#' + element.id + ' h2' ).click(function() {
jQuery( '#' + element.id + ' .expandingBox').toggle();
});
});


/**
* Date Picker
*
* Prevent start date from being later than end date
*
* Directly modifies the jQuery UI element
*
* @param element String Element to modify
* @param endDate Date Last date avaialble for selection
*/
/* Date Picker - Prevent start date from being later than end date */
function updateStartDate( element, endDate ) {
$( element ).datepicker( "option", "maxDate", endDate );
}


/**
* Date Picker
*
* Update display for number of days in the date range
*/
/* Date Picker - Count number of days */
function updateDateRange() {
var date_start = $( "#date_start_inline" ).datepicker( "getDate" );
var date_end = $( "#date_end_inline" ).datepicker( "getDate" );
var date_range = Math.round( Math.abs( ( date_start.getTime() - date_end.getTime() ) / ( 24*60*60*1000 ) ) ) + 1;
var date_range_display = " (" + date_range + " day" + ( date_range > 1 ? "s" : "" ) + ")";
$("#date_range_count").empty().text( date_range_display );
}


/**
* Tooltips
*
* jQuery UI tool tips
*
* Add a tooltip to any <label> element with an attribute setting of "tooltip"
*/
/* Date Picker - Count number of days */
$( "label" ).tooltip({
items: "label[tooltip]",
content: function() { return $( this ).attr('tooltip'); },
tooltipClass: "tooltips"
});
2 changes: 1 addition & 1 deletion organic-search-analytics/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.6
2.3.7

0 comments on commit 9fcb4fb

Please sign in to comment.