| <?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'); |
| } |
| } |