You are here

protected function StatsPro::get_week_from_reference in Statistics Pro 6.2

Same name and namespace in other branches
  1. 6 statspro.inc \statspro::get_week_from_reference()

Returns a SQL WHERE for the selected week.

Weeks starts at mondays and ends at sundays.

For date('w') we get 0 (for Sunday) through 6 (for Saturday).

Parameters

<int> $reference Defines the selected week.:

Return value

<string> SQL min and max WHERE for week.

1 call to StatsPro::get_week_from_reference()
StatsPro::get_period in ./statspro.inc
Generate SQL fragment for period query.

File

./statspro.inc, line 254
statspro class for Statistics Pro module.

Class

StatsPro
Manages the data saving and retrieval according to the user defined parameters.

Code

protected function get_week_from_reference($reference, $field, $use_timestamp) {
  $min = $this
    ->get_first_day_of_week_from_reference($reference, $use_timestamp);
  $day_of_week = date('w', $reference);
  $max = $day_of_week == 0 ? 'today' : 'next sunday';
  $max = strtotime($max, $reference);
  if (!$use_timestamp) {
    $max = date('Y-m-d', $max);
    return sprintf('(%s >= \'%s\' AND %1$s <= \'%s\')', $field, $min, $max);
  }
  return $this
    ->get_min_max_period($field, $min, $max);
}