欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Custom Filter Example for Views 2 in Drupal 6 可以不看

 Code
Custom Filter Example for Views 2 in Drupal 6
 <?php
  
 /**
 * This gist is a basic example of how to define a custom field for a view. This filter becomes available
 * to views in the views gui interface.
 */
  
 /**
 * Inform views
 */
 function mymodule_views_data() {
 $data = array();
 $data['mymodule']['table']['group'] = t('My Module Group Name');
 $data['mymodule']['custom_filter'] = array(
 'title' => t('Custom Filter'),
 'help' => t(''),
 'group' => t('My Module'),
 'filter' => array(
 'handler' => 'mymodule_handler_filter_signed_up',
 )
 );
 }
  
  
 /**
 * Inform views about our handlers
 */
 function mymodule_views_handlers() {
 return array(
 'info' => array(
 'path' => drupal_get_path('module', 'mymodule') . '/views',
 ),
 'handlers' => array(
 'mymodule_handler_filter_my_custom_filter' => array(
 'parent' => 'views_handler_filter',
 ),
 ),
 );
 }
  
 //Goes in mymodule_handler_filter_my_custom_filter.inc
 class mymodule_handler_filter_my_custom_filter extends views_handler_filter{
 function construct() {
 parent::construct();
 $this->additional_fields['created_timestamp'] = 'created_timestamp';
 $this->additional_fields['deleted_timestamp'] = 'deleted_timestamp';
 }
  
 function query() {
 $table = $this->ensure_my_table();
 $this->query->set_group_operator('AND');
  
 $this->query->add_where('my_custom_filter', "created_timestamp < deleted_timestamp OR deleted_timestamp = 0");
 $this->query->add_groupby('id');
 }
 }
来自  https://gist.github.com/prairiehippo/2371314
普通分类: