You are here

function rate_expiration_rate_widget in Rate 6.2

Implements hook_rate_widget().

File

expiration/rate_expiration.module, line 49

Code

function rate_expiration_rate_widget($op, &$widget, $values = NULL) {
  switch ($op) {
    case 'insert':
    case 'update':
      $widget->expiration = $values['expiration'];
      $widget->expiration_allow_override = !empty($values['expiration_allow_override']);
      break;
    case 'delete':
      $sql = 'DELETE FROM {rate_expiration} WHERE widget_name = \'%s\'';
      db_query($sql, $widget->name);
      break;
    case 'view':
      if ($values['content_type'] == 'node') {
        if ($node = node_load($values['content_id'])) {
          $configuration = _rate_expiration_get_node_values($node->nid);
          if (isset($configuration[$widget->name])) {
            $start = $configuration[$widget->name]['start'];
            $end = $configuration[$widget->name]['end'];
          }
          else {
            $start = 0;
            $end = 0;
          }
          if ($widget->expiration > 0) {
            !empty($end) or $end = $node->created + $widget->expiration;
          }
          if ($end > 0 && $end <= time() || $start > 0 && $start > time()) {
            $widget->mode = RATE_CLOSED;
          }
        }
      }
      break;
  }
}