[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/project/release/views/handlers/ -> project_release_handler_field_download_table.inc (source)

   1  <?php
   2  // $Id: project_release_handler_field_download_table.inc,v 1.1 2009/01/13 17:47:09 dww Exp $
   3  
   4  
   5  /**
   6   * Views field handler for the table to download releases.
   7   */
   8  class project_release_handler_field_download_table extends views_handler_field {
   9    /**
  10     * Constructor; calls to base object constructor.
  11     */
  12    function construct() {
  13      parent::construct();
  14  
  15      $this->additional_fields = array();
  16      $this->additional_fields['nid'] = 'nid';
  17      $this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format');
  18      $this->additional_fields['uid'] = 'uid';
  19      $this->additional_fields['type'] = 'type';
  20    }
  21  
  22    function init(&$view, $options) {
  23      parent::init($view, $options);
  24  
  25      $this->options += array(
  26        'release_type' => $this->radios_get_default($this->get_type_options('release')),
  27        'table_type' => $this->radios_get_default($this->get_type_options('table')),
  28        'first_column_title' => '',
  29      );
  30    }
  31  
  32    /**
  33     * Helper function that returns an array of possible types.
  34     *
  35     * @param $type
  36     *   Indicates what type of options should be returned.  Possible
  37     *   values are 'release' to get release types or 'table' to get
  38     *   release table types.
  39     * @return
  40     *   An array of possible types.
  41     */
  42    function get_type_options($type){
  43      $types = array(
  44        'release' => array(
  45          'default' => 'official',
  46          'options' => array(
  47            'official' => array(
  48              'name' => t('Official'),
  49              'default_title' => t('Official releases'),
  50            ),
  51            'snapshot' => array(
  52              'name' => t('Snapshot'),
  53              'default_title' => t('Snapshot releases'),
  54            ),
  55            'all' => array(
  56              'name' => t('All'),
  57              'default_title' => t('Version'),
  58            ),
  59          ),
  60        ),
  61        'table' => array(
  62          'default' => 'supported',
  63          'options' => array(
  64            'recommended' => array(
  65              'name' => t('Recommended'),
  66            ),
  67            'supported' => array(
  68              'name' => t('Supported'),
  69            ),
  70            'all' => array(
  71              'name' => t('All'),
  72            ),
  73          ),
  74        ),
  75      );
  76      return (isset($types[$type])) ? $types[$type] : array();
  77    }
  78  
  79    /**
  80     * Get the default option.
  81     *
  82     * @param $types
  83     *   An array of types returned by $this::get_type_options().
  84     * @return
  85     *   A string indicating the key of $types that should be the default option.
  86     */
  87    function radios_get_default($types) {
  88      return isset($types['default']) ? $types['default'] : '';
  89    }
  90  
  91    /**
  92     * Get all possible options.
  93     *
  94     * @param $types
  95     *   An array of types returned by $this::get_type_options().
  96     * @return
  97     *   An array of possible options.
  98     */
  99    function radios_get_options($types) {
 100      $options = array();
 101      foreach ($types['options'] as $key => $info) {
 102        $options[$key] = $info['name'];
 103      }
 104      return $options;
 105    }
 106  
 107    /**
 108     * Default options form that provides the label widget that all fields
 109     * should have.
 110     */
 111    function options_form(&$form, &$form_state) {
 112      parent::options_form($form, $form_state);
 113  
 114      $form['table_type'] = array(
 115        '#type' => 'radios',
 116        '#prefix' => '<div class="clear-block">',
 117        '#suffix' => '</div>',
 118        '#title'=> t('Table type'),
 119        '#options' => $this->radios_get_options($this->get_type_options('table')),
 120        '#default_value'=> $this->options['table_type'],
 121      );
 122      $release_types = $this->get_type_options('release');
 123      $form['release_type'] = array(
 124        '#type' => 'radios',
 125        '#prefix' => '<div class="views-left-30">',
 126        '#suffix' => '</div>',
 127        '#title'=> t('Release type'),
 128        '#options' => $this->radios_get_options($release_types),
 129        '#default_value' => $this->options['release_type'],
 130      );
 131      $form['first_column_title']= array(
 132        '#type' => 'textfield',
 133        '#prefix' => '<div class="views-left-50">',
 134        '#suffix' => '</div>',
 135        '#title' => t('Title of first column of table'),
 136        '#max_length' => 20,
 137        '#default_value' => empty($this->options['first_column_title']) ? $release_types['options'][$this->options['release_type']]['default_title'] : $this->options['first_column_title'],
 138     );
 139    }
 140  
 141    /**
 142     * Provide extra data to the administration form.
 143     */
 144    function admin_summary() {
 145      $output = '';
 146      $release_types = $this->radios_get_options($this->get_type_options('release'));
 147      $table_types = $this->radios_get_options($this->get_type_options('table'));
 148      $output .= t('@release_type releases, Table type: @table_type', array('@release_type' => $release_types[$this->options['release_type']], '@table_type' => $table_types[$this->options['table_type']]));
 149      return $output;
 150    }
 151  
 152    function query() {
 153      $this->ensure_my_table();
 154      $this->add_additional_fields();
 155    }
 156  
 157    function render($values) {
 158      $node = new stdClass();
 159      $node->nid = $values->{$this->aliases['nid']};
 160      $node->uid = $values->{$this->aliases['uid']};
 161      $node->type = $values->{$this->aliases['type']};
 162      $node->format = $values->{$this->aliases['format']};
 163  
 164      // Load a few release related fields for the project itself.
 165      project_release_project_nodeapi_load($node);
 166      $node->status = 1; // unpublished nodes ignore access control
 167      if (empty($node->releases)) {
 168        return;
 169      }
 170      $output = '';
 171      $output .= project_release_table($node, $this->options['table_type'], $this->options['release_type'], $this->options['first_column_title']);
 172  
 173      return $output;
 174    }
 175  }
 176  


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7