You are here

abstract class field_timer_jquery_countdown_js_base in Field Timer 7.2

Base class for jquery_countdown formatters.

Hierarchy

Expanded class hierarchy of field_timer_jquery_countdown_js_base

File

includes/field_timer_base.inc, line 145
Contains base help classes to perform field formatter related actions.

View source
abstract class field_timer_jquery_countdown_js_base extends field_timer_formatter_js_base {

  /**
   * @inheritdoc
   */
  public function enableFormatter() {
    $library = libraries_detect('jquery.countdown');
    return $library && !empty($library['installed']);
  }

  /**
   * @inheritdoc
   */
  protected function loadLibrary() {
    if (!$this->library_loaded) {
      $library = libraries_load('jquery.countdown');
      $this->library_loaded = $library && !empty($library['loaded']);
      $js_name = 'jquery.countdown.js';
      $js_name_min = 'jquery.countdown.min.js';
      $base_path = 'sites/all/libraries/jquery.countdown';
      if (!$this->library_loaded) {
        drupal_set_message(t("Can't load jQuery Countdown library. Please download !url plugin and extract it to @path, so @js and @js_min can be found at @full_path and @full_path_min.", array(
          '!url' => l(t('jQuery Countdown'), 'http://keith-wood.name/countdown.html', array(
            'absolute' => TRUE,
          )),
          '@path' => $base_path,
          '@js' => $js_name,
          '@js_min' => $js_name_min,
          '@full_path' => $base_path . '/' . $js_name,
          '@full_path_min' => $base_path . '/' . $js_name_min,
        )), 'error');
      }
    }
    return $this->library_loaded;
  }

  /**
   * @inheritdoc
   */
  protected function generateJSSettings($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    $info = entity_get_info($entity_type);
    $id_key = $info['entity keys']['id'];
    $js_settings = array();
    $settings = $display['settings'];
    foreach ($items as $delta => $item) {
      $key = $entity_type . '_' . $entity->{$id_key} . '_' . $field['field_name'] . '_' . $delta;
      $timestamp = $this
        ->getTimestamp($item, $field);
      $js_settings += $this
        ->generateJSSettingsArray($key, $timestamp, $settings['type'], $settings);
    }
    return $js_settings;
  }

  /**
   * @inheritdoc
   */
  protected function loadJSandCSS($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
    parent::loadJSandCSS($entity_type, $entity, $field, $instance, $langcode, $items, $display);
    drupal_add_css(drupal_get_path('module', 'field_timer') . '/css/field_timer.css', 'file');
  }
  protected function generateJSSettingsArray($key, $timestamp, $type, $settings) {
    $js_settings = array();
    $js_settings[$key]['timestamp'] = $timestamp;
    $js_settings[$key]['options'] = $settings;
    if ($type == 'timer' || $type == 'auto' && $timestamp <= REQUEST_TIME) {
      $js_settings[$key]['options']['until'] = FALSE;
      $js_settings[$key]['options']['since'] = TRUE;
    }
    elseif ($type == 'countdown' || $type == 'auto' && $timestamp > REQUEST_TIME) {
      $js_settings[$key]['options']['until'] = TRUE;
      $js_settings[$key]['options']['since'] = FALSE;
    }
    $js_settings[$key]['plugin'] = $this
      ->getPluginName();
    return $js_settings;
  }
  protected function formatterTypes() {
    return array(
      'auto' => t('Auto'),
      'timer' => t('Timer'),
      'countdown' => t('Countdown'),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
field_timer_formatter_base::getTimestamp abstract protected function Convert field item value to timestamp. 16
field_timer_formatter_interface::getDefaultSettings public function Get default formatter settings. All settings for each field type will be combined into one array. 4
field_timer_formatter_interface::getFieldType public function Get field type. 16
field_timer_formatter_interface::getFormatterDefinition public function Get formatter definition. 4
field_timer_formatter_interface::getFormatterName public function Get formatter name. 4
field_timer_formatter_interface::getSettingsForm public function Get formatter settings form. 4
field_timer_formatter_interface::getSettingsSummary public function Get formatter settings summary. 4
field_timer_formatter_interface::renderItems public function Render field items. 4
field_timer_formatter_js_base::$library_loaded protected property
field_timer_formatter_js_base::getPluginName abstract public function Get jQuery plugin name. 3
field_timer_jquery_countdown_js_base::enableFormatter public function @inheritdoc Overrides field_timer_formatter_interface::enableFormatter
field_timer_jquery_countdown_js_base::formatterTypes protected function
field_timer_jquery_countdown_js_base::generateJSSettings protected function @inheritdoc Overrides field_timer_formatter_js_base::generateJSSettings 2
field_timer_jquery_countdown_js_base::generateJSSettingsArray protected function
field_timer_jquery_countdown_js_base::loadJSandCSS protected function @inheritdoc Overrides field_timer_formatter_js_base::loadJSandCSS 3
field_timer_jquery_countdown_js_base::loadLibrary protected function @inheritdoc Overrides field_timer_formatter_js_base::loadLibrary