[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

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

   1  <?php
   2  // $Id: project.views.inc,v 1.5 2009/02/16 22:43:15 dww Exp $
   3  
   4  
   5  /**
   6   * @file
   7   * Provide views data and handlers for project.module.
   8   */
   9  
  10  /**
  11   * Implementation of hook_views_data().
  12   *
  13   * Exposes all fields to the views system.
  14   */
  15  function project_views_data() {
  16    $data = array();
  17    // ----------------------------------------------------------------
  18    // project_projects table
  19  
  20    // Define the base group of this table. Fields that don't
  21    // have a group defined will go into this field by default.
  22    $data['project_projects']['table']['group']  = t('Project');
  23  
  24    $data['project_projects']['table']['join'] = array(
  25      'node' => array(
  26        'type' => 'INNER',
  27        'left_field' => 'nid',
  28        'field' => 'nid',
  29      ),
  30    );
  31  
  32    // uri
  33    $data['project_projects']['uri'] = array(
  34      'title' => t('Short name'),
  35      'help' => t('The short name (uri) of a project.'),
  36      'field' => array(
  37        'group' => t('Project'),
  38        'handler' => 'views_handler_field_node',
  39        'click sortable' => TRUE,
  40       ),
  41      'sort' => array(
  42        'handler' => 'views_handler_sort',
  43      ),
  44      'filter' => array(
  45        'handler' => 'views_handler_filter_string',
  46      ),
  47      'argument' => array(
  48        'handler' => 'views_handler_argument_string',
  49      ),
  50    );
  51  
  52    // homepage
  53    $data['project_projects']['homepage'] = array(
  54      'title' => t('Homepage'),
  55      'help' => t("The project's homepage."),
  56      'field' => array(
  57        'group' => t('Project'),
  58        'handler' => 'views_handler_field_url',
  59        'click sortable' => TRUE,
  60       ),
  61      'sort' => array(
  62        'handler' => 'views_handler_sort',
  63      ),
  64      'filter' => array(
  65        'handler' => 'views_handler_filter_string',
  66      ),
  67      'argument' => array(
  68        'handler' => 'views_handler_argument_string',
  69      ),
  70    );
  71  
  72    // changelog
  73    $data['project_projects']['changelog'] = array(
  74      'title' => t('Changelog'),
  75      'help' => t("The project's changelog."),
  76      'field' => array(
  77        'group' => t('Project'),
  78        'handler' => 'views_handler_field_url',
  79        'click sortable' => TRUE,
  80       ),
  81      'sort' => array(
  82        'handler' => 'views_handler_sort',
  83      ),
  84      'filter' => array(
  85        'handler' => 'views_handler_filter_string',
  86      ),
  87      'argument' => array(
  88        'handler' => 'views_handler_argument_string',
  89      ),
  90    );
  91  
  92    // cvs
  93    $data['project_projects']['cvs'] = array(
  94      'title' => t('CVS directory'),
  95      'help' => t("The project's cvs directory."),
  96      'field' => array(
  97        'group' => t('Project'),
  98        //'handler' => 'views_handler_field_node',
  99        'click sortable' => TRUE,
 100       ),
 101      'sort' => array(
 102        'handler' => 'views_handler_sort',
 103      ),
 104      'filter' => array(
 105        'handler' => 'views_handler_filter_string',
 106      ),
 107      'argument' => array(
 108        'handler' => 'views_handler_argument_string',
 109      ),
 110    );
 111  
 112    // demo
 113    $data['project_projects']['demo'] = array(
 114      'title' => t('Demonstration'),
 115      'help' => t('Link to a demonstration of the project.'),
 116      'field' => array(
 117        'group' => t('Project'),
 118        'handler' => 'views_handler_field_url',
 119        'click sortable' => TRUE,
 120       ),
 121      'sort' => array(
 122        'handler' => 'views_handler_sort',
 123      ),
 124      'filter' => array(
 125        'handler' => 'views_handler_filter_string',
 126      ),
 127      'argument' => array(
 128        'handler' => 'views_handler_argument_string',
 129      ),
 130    );
 131  
 132    // documentation
 133    $data['project_projects']['documentation'] = array(
 134      'title' => t('Documentation'),
 135      'help' => t("The project's documentation."),
 136      'field' => array(
 137        'group' => t('Project'),
 138        'handler' => 'views_handler_field_url',
 139        'click sortable' => TRUE,
 140       ),
 141      'sort' => array(
 142        'handler' => 'views_handler_sort',
 143      ),
 144      'filter' => array(
 145        'handler' => 'views_handler_filter_string',
 146      ),
 147      'argument' => array(
 148        'handler' => 'views_handler_argument_string',
 149      ),
 150    );
 151  
 152    // screenshots
 153    $data['project_projects']['screenshots'] = array(
 154      'title' => t('Screenshots'),
 155      'help' => t("The project's screenshots."),
 156      'field' => array(
 157        'group' => t('Project'),
 158        'handler' => 'views_handler_field_url',
 159        'click sortable' => TRUE,
 160       ),
 161      'sort' => array(
 162        'handler' => 'views_handler_sort',
 163      ),
 164      'filter' => array(
 165        'handler' => 'views_handler_filter_string',
 166      ),
 167      'argument' => array(
 168        'handler' => 'views_handler_argument_string',
 169      ),
 170    );
 171  
 172    // license
 173    $data['project_projects']['license'] = array(
 174      'title' => t('License'),
 175      'help' => t('The license used for the project.'),
 176      'field' => array(
 177        'group' => t('Project'),
 178        'handler' => 'views_handler_field_url',
 179        'click sortable' => TRUE,
 180       ),
 181      'sort' => array(
 182        'handler' => 'views_handler_sort',
 183      ),
 184      'filter' => array(
 185        'handler' => 'views_handler_filter_string',
 186      ),
 187      'argument' => array(
 188        'handler' => 'views_handler_argument_string',
 189      ),
 190    );
 191  
 192    return $data;
 193  }
 194  
 195  /**
 196   * Implementation of hook_views_data_alter().
 197   */
 198  function project_views_data_alter(&$data) {
 199    // @TODO:  Rewrite the help and title to be more descriptive?
 200    $data['term_node']['term_node_tid_depth_project'] = array(
 201      'group' => t('Taxonomy'),
 202      'title' => t('Term ID (summary)'),
 203      'help' => t('This argument produces a summary with the option to exclude top level terms.'),
 204      'real field' => 'tid',
 205      'argument' => array(
 206        'handler' => 'project_handler_argument_term_node_tid_depth_project',
 207        'name table' => 'term_data',
 208        'name field' => 'name',
 209        'empty name field' => t('Uncategorized'),
 210        'numeric' => TRUE,
 211      ),
 212    );
 213  
 214    // Add a Project type vocabulary filter that makes it possible to include
 215    // only the top level terms or child terms in the project types vocabulary.
 216    $data['term_data']['project_type'] = array(
 217      'title' => t('Project type depth'),
 218      'help' => t('Limit the results to project type terms that are either parents or children, or both.'),
 219      'filter' => array(
 220        'field' => 'vid',
 221        'handler' => 'project_handler_filter_project_type_vid',
 222      ),
 223    );
 224  
 225    // tid field (based on {term_node}.tid field in taxonomy.views.inc).
 226    $data['term_node']['project_type_tid'] = array(
 227      'group' => t('Project'),
 228      'title' => t('Project type term'),
 229      'real field' => 'tid',
 230      'field' => array(
 231        'title' => t('Project type terms'),
 232        'help' => t('The project type terms associated with a node.'),
 233        'handler' => 'project_handler_field_term_node_project_type_tid',
 234      ),
 235      'filter' => array(
 236        'help' => t('Filter by the project type term.'),
 237        'handler' => 'project_handler_filter_term_node_project_type_tid',
 238        'hierarchy table' => 'term_hierarchy',
 239        'numeric' => TRUE,
 240      ),
 241    );
 242  
 243    // Project sorting method filter.  This is a bit of a hack until Views
 244    // supports exposed sorting.
 245    $data['views']['project_sort_method'] = array(
 246      'group' => t('Project'),
 247      'title' => t('Sort method'),
 248      'help' => t('This is a filter that provides a sort method select box that can be exposed to the user.'),
 249      'filter' => array(
 250        'handler' => 'project_handler_filter_project_sort_method',
 251      ),
 252    );
 253  }
 254  
 255  /**
 256   * Implementation of hook_views_handlers().
 257   */
 258  function project_views_handlers() {
 259    return array(
 260      'info' => array(
 261        'path' => drupal_get_path('module', 'project') .'/views/handlers',
 262      ),
 263      'handlers' => array(
 264        'project_handler_argument_term_node_tid_depth_project' => array(
 265          'parent' => 'views_handler_argument_term_node_tid',
 266        ),
 267        'project_handler_field_term_node_project_type_tid' => array(
 268          'parent' => 'views_handler_field_term_node_tid',
 269        ),
 270        'project_handler_filter_project_sort_method' => array(
 271          'parent' => 'views_handler_filter',
 272        ),
 273        'project_handler_filter_project_type_vid' => array(
 274          'parent' => 'views_handler_filter_in_operator',
 275        ),
 276        'project_handler_filter_project_type_vid' => array(
 277          'parent' => 'views_handler_filter_in_operator',
 278        ),
 279        'project_handler_filter_term_node_project_type_tid' => array(
 280          'parent' => 'views_handler_filter_term_node_tid',
 281        ),
 282      ),
 283    );
 284  }
 285  
 286  /**
 287   * Implementation of hook_views_plugins().
 288   */
 289  function project_views_plugins() {
 290    $project_path = drupal_get_path('module', 'project');
 291    return array(
 292      'module' => 'project',
 293      'style' => array(
 294        'project_list' => array(
 295          'title' => t('Project list'),
 296          'help' => t('Displays a list of project rows with additional project related information.'),
 297          'handler' => 'project_plugin_style_project_list',
 298          'path' => "$project_path/views/plugins",
 299          'theme' => 'project_views_view_project_list',
 300          'theme file' => 'theme.inc',
 301          'theme path' => "$project_path/views/theme",
 302          'uses row plugin' => TRUE,
 303          'uses options' => TRUE,
 304          'uses fields' => TRUE,
 305          'uses grouping' => TRUE,
 306          'type' => 'normal',
 307        ),
 308        'collapsible_summary' => array(
 309          'title' => t('Collapsible'),
 310          'help' => t('Displays the summary in a collapsible fieldset.'),
 311          'handler' => 'views_plugin_style_summary',
 312          'path' => drupal_get_path('module', 'project') .'/views/plugins',
 313          'theme' => 'project_views_view_collapsible_summary',
 314          'theme file' => 'theme.inc',
 315          'theme path' => "$project_path/views/theme",
 316          'type' => 'summary', // only shows up as a summary style
 317          'uses options' => TRUE,
 318        ),
 319      ),
 320      'row' => array(
 321        'project_node' => array(
 322          'title' => t('Project node'),
 323          'help' => t('Display the project node with download table.'),
 324          'handler' => 'project_plugin_row_project_node_view',
 325          'path' => drupal_get_path('module', 'project') .'/views/plugins',
 326          'theme' => 'project_views_view_row_project_node',
 327          'theme file' => 'theme.inc',
 328          'theme path' => "$project_path/views/theme",
 329          'base' => array('node'), // only works with 'node' as base.
 330          'uses options' => TRUE,
 331          'type' => 'normal',
 332        ),
 333        'project_fields' => array(   // Project row style for fields.
 334          'title' => t('Project fields'),
 335          'help' => t('Displays project fields.'),
 336          'handler' => 'project_plugin_row_project_fields_view',
 337          'path' => drupal_get_path('module', 'project') .'/views/plugins',
 338          'theme' => 'project_views_view_row_project_fields',
 339          'theme file' => 'theme.inc',
 340          'theme path' => "$project_path/views/theme",
 341          'uses fields' => TRUE,
 342          'uses options' => TRUE,
 343          'type' => 'normal',
 344        ),
 345      ),
 346      'argument validator' => array(
 347        'project_term_top_level' => array(
 348          'title' => t('Project type: Top level term'),
 349          'handler' => 'project_plugin_argument_validate_project_term_top_level',
 350          'path' => drupal_get_path('module', 'project') .'/views/plugins',
 351        ),
 352        'project_type_term' => array(
 353          'title' => t('Project type term'),
 354          'handler' => 'project_plugin_argument_validate_project_type_term',
 355          'path' => drupal_get_path('module', 'project') .'/views/plugins',
 356        ),
 357        'project_nid' => array(
 358          'title' => t('Project node'),
 359          'handler' => 'project_plugin_argument_validate_project_nid',
 360          'path' => drupal_get_path('module', 'project') .'/views/plugins',
 361        ),
 362      ),
 363    );
 364  }
 365  
 366  /**
 367   * Provides the term object for the project type used
 368   * as an argument.
 369   *
 370   * @param $argument
 371   *   This should be the value of the argument used to indicate
 372   *   what project type is being browsed.  This will usually be
 373   *   the first argument.  The value can be either the tid or the
 374   *   name of the term.
 375   *
 376   * @return
 377   *   The term object or NULL if none could be found.
 378   */
 379  function _project_views_get_project_type($argument = NULL) {
 380    if (module_exists('taxonomy')) {
 381      if (is_numeric($argument)) {
 382        $term = taxonomy_get_term($argument);
 383      }
 384      else {
 385        $project_vid = _project_get_vid();
 386        $term = db_fetch_object(db_query(db_rewrite_sql("SELECT t.tid, t.* FROM {term_data} t INNER JOIN {term_hierarchy} th ON t.tid = th.tid WHERE t.vid = %d AND th.parent = %d AND t.name = '%s'", 't', 'tid'), $project_vid, 0, $argument));
 387      }
 388      return $term;
 389    }
 390  }
 391  


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