You are here

function _quiz_get_interval_timestamps in Quiz 7.4

Same name and namespace in other branches
  1. 8.4 quiz.admin.inc \_quiz_get_interval_timestamps()
  2. 6.4 quiz.admin.inc \_quiz_get_interval_timestamps()
  3. 7 quiz.admin.inc \_quiz_get_interval_timestamps()

Returns an array with sql where clauses correscponding to the options in the time filters.

Return value

$changed_timestamps array of timestamps and sql filters

See also

_quiz_questions_browser_form()

3 calls to _quiz_get_interval_timestamps()
_quiz_question_browser_form in ./quiz.admin.inc
Creates the browser part of the quiz_questions_form
_quiz_question_browser_prepare_filter_sql in ./quiz.admin.inc
Returns sql to be added in where clause in the browsers select statement
_quiz_results_mr_prepare_filter in ./quiz.admin.inc
Returns sql and parameters to be added in join, where and group clauses in the _quiz_results_mr_data_provider select statement

File

./quiz.admin.inc, line 2640
Administrator interface for Quiz module.

Code

function _quiz_get_interval_timestamps($fieldname) {

  // Create datastructure to help create where clause in the sql for the changed filter...
  $now = REQUEST_TIME;
  $one_day = 86400;
  $one_week = 604800;
  $timestamp_today = mktime(0, 0, 0, date('n'), date('j'), date('Y'));
  $weekday = date('N', $now);
  $timestamp_week = $timestamp_today - ((int) $weekday - 1) * $one_day;
  $timestamp_month = mktime(0, 0, 0, date('n'), 1, date('Y'));
  $timestamp_last_month = mktime(0, 0, 0, date('n', $timestamp_month - 1), 1, date('Y', $timestamp_month - 1));
  $timestamp_year = mktime(0, 0, 0, 1, 1, date('Y'));
  $timestamp_last_year = mktime(0, 0, 0, 1, 1, date('Y', $timestamp_year - 1));
  $changed_timestamps = array(
    NULL,
    array(
      $timestamp_today,
      $now,
    ),
    array(
      $timestamp_today - $one_day * 1,
      $timestamp_today,
    ),
    array(
      $timestamp_today - $one_day * 2,
      $timestamp_today - $one_day * 1,
    ),
    array(
      $timestamp_week,
      $now,
    ),
    array(
      $timestamp_week - $one_week,
      $timestamp_week,
    ),
    array(
      $timestamp_month,
      $now,
    ),
    array(
      $timestamp_last_month,
      $timestamp_month,
    ),
    array(
      $timestamp_year,
      $now,
    ),
    array(
      $timestamp_last_year,
      $timestamp_year,
    ),
    array(
      0,
      $timestamp_last_year,
    ),
  );
  foreach ($changed_timestamps as $key => &$val) {
    if ($val == NULL) {
      continue;
    }
    $val['sql'] = " AND {$fieldname} > " . $val[0] . " AND {$fieldname} < " . $val[1];
  }
  return $changed_timestamps;
}