You are here

function _advpoll_generate_blocks in Advanced Poll 6.2

1 call to _advpoll_generate_blocks()
advpoll_views_default_views in views/advpoll.views.inc

File

views/advpoll.views.inc, line 234
Views integration for Advanced Poll module.

Code

function _advpoll_generate_blocks($view) {

  // MW generates custom view blocks based on selection criteria
  $result = db_query('SELECT * FROM {node} n INNER JOIN {advpoll} p ON p.nid = n.nid WHERE n.status = 1
                        AND p.active = 1 AND p.create_view_block = 1 AND p.start_date < %d
                        AND p.end_date > %d', time(), time());

  // MW note that the id of a given block is unique since it's based on the displayed node's
  // nid.  This is done so that each time the view is refreshed, the blocks can be regenerated without
  // regard for order - this ensures that a specific block placed on a page will remain there even if
  // the view is rebuilt (as it is each time a poll is edited or created).
  while ($node = db_fetch_object($result)) {
    $handler = $view
      ->new_display('block', 'Poll Block - ' . $node->title, 'block_' . $node->nid);
    $handler
      ->override_option('filters', array(
      'status' => array(
        'operator' => '=',
        'value' => '1',
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'status',
        'table' => 'node',
        'field' => 'status',
        'relationship' => 'none',
      ),
      'type' => array(
        'operator' => 'in',
        'value' => array(
          'advpoll_binary' => 'advpoll_binary',
        ),
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'type',
        'table' => 'node',
        'field' => 'type',
        'relationship' => 'none',
      ),
      'active' => array(
        'operator' => '=',
        'value' => '1',
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'active',
        'table' => 'advpoll',
        'field' => 'active',
        'relationship' => 'none',
      ),
      'create_view_block' => array(
        'operator' => '=',
        'value' => '1',
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'create_view_block',
        'table' => 'advpoll',
        'field' => 'create_view_block',
        'relationship' => 'none',
      ),
      'end_date' => array(
        'operator' => '>',
        'value' => array(
          'type' => 'offset',
          'value' => 'now',
          'min' => '',
          'max' => '',
        ),
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'end_date',
        'table' => 'advpoll',
        'field' => 'end_date',
        'relationship' => 'none',
      ),
      'start_date' => array(
        'operator' => '<',
        'value' => array(
          'type' => 'offset',
          'value' => 'now',
          'min' => '',
          'max' => '',
        ),
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'start_date',
        'table' => 'advpoll',
        'field' => 'start_date',
        'relationship' => 'none',
      ),
      'nid' => array(
        'operator' => '=',
        'value' => array(
          'value' => $node->nid,
          'min' => '',
          'max' => '',
        ),
        'group' => '0',
        'exposed' => FALSE,
        'expose' => array(
          'operator' => FALSE,
          'label' => '',
        ),
        'id' => 'nid',
        'table' => 'node',
        'field' => 'nid',
        'override' => array(
          'button' => 'Use default',
        ),
        'relationship' => 'none',
      ),
    ));
    $handler
      ->override_option('block_description', '');
    $handler
      ->override_option('block_caching', -1);
  }
}