You are here

function _simpleads_statuses in SimpleAds 7

Helper function. Display Ad statuses.

1 call to _simpleads_statuses()
simpleads_simpleads_stats_info in ./simpleads.module
Implements hook_simpleads_stats_info().

File

./simpleads.stat.inc, line 225
SimpleAds Statistics.

Code

function _simpleads_statuses($node) {
  $status = "";
  $start_time = "";
  $end_time = "";
  if (isset($node->field_ad_start_date[$node->language]) && !empty($node->field_ad_start_date[$node->language][0]['value'])) {
    $start_time = $node->field_ad_start_date[$node->language][0]['value'];
  }
  if (isset($node->field_ad_end_date[$node->language]) && !empty($node->field_ad_end_date[$node->language][0]['value'])) {
    $end_time = $node->field_ad_end_date[$node->language][0]['value'];
  }
  $ustart_time = strtotime(check_plain($start_time));
  $uend_time = strtotime(check_plain($end_time));
  $now = time();
  if ($node->status == 1) {
    $status .= t("Published");
    if ($start_time != '' && $end_time != '') {
      $status .= ", " . t("Active during (@startdate - @enddate)", array(
        '@startdate' => $start_time,
        '@enddate' => $end_time,
      ));
    }
    elseif ($start_time == '' && $end_time != '') {
      $status .= ", " . t("Expires on @datetime", array(
        '@datetime' => $end_time,
      ));
    }
  }
  else {
    $status .= t("Not Published");
    if ($start_time != '' && $end_time != '') {
      if ($uend_time <= $now) {
        $status = t("Expired on @datetime", array(
          '@datetime' => $end_time,
        ));
      }
      else {
        $status .= ", " . t("Start from (@startdate - @enddate)", array(
          '@startdate' => $start_time,
          '@enddate' => $end_time,
        ));
      }
    }
    elseif ($start_time == '' && $end_time != '') {
      if ($uend_time <= $now) {
        $status = t("Expired on @datetime", array(
          '@datetime' => $end_time,
        ));
      }
      else {
        $status .= ", " . t("Expires on @datetime", array(
          '@datetime' => $end_time,
        ));
      }
    }
  }
  return $status;
}