0

I'm using Drupal 7 with views 3.

I am listing the student fees in a view and one of the field in view results is pid (payment id) which has some numeric value or NULL value. The NULL value means the payment is unpaid. I have used a custom field handler to show in view result as paid and unpaid for pid = some value as Paid and pid = Null value as Unpaid.

I want a filter on this field also which will have a drop down of two options as paid and unpaid. Which views filter I should use and how can I rename the drop down options?

hook_views_data()

// Status of payment paid or unpaid if pid is null in joined result set : unpaid
    $data['fee_schedule_payments']['payment_status'] = array(
        'real field' => 'pid',
        'title' => t('Fee schedule payment status'), 
        'label' => t('Status'),
        'help' => t('Fee schedule payment status'), 
        'field' => array(
      'handler' => 'fee_management_handler_field_payment_status', 
      'click sortable' => TRUE, // This is use by the table display plugin.
    ), 
    'filter' => array(
      'handler' => 'views_handler_filter_WHICH_ONE_I_SHOULD_USE',
    ),
    ); 




class fee_management_handler_field_payment_status extends views_handler_field {
    function construct() {
    parent::construct();
    $this->additional_fields['pid'] = 'pid';
  }
  function render($values) {
    $pid = $this->get_value($values, 'pid');
    if (!empty($pid)) {
            return 'Paid';
        }
        return 'Unpaid';    
  }
};

Thanks in advance for your help.

1 Answer 1

0

I have implemented this custom filter. All Thanks and credit goes to Amar :). I am just sharing the code.

// Status of payment paid or unpaid if pid is null in joined result set : unpaid
    $data['fee_schedule_payments']['payment_status'] = array(
        'real field' => 'pid',
        'title' => t('Fee schedule payment status'), 
        'label' => t('Status'),
        'help' => t('Fee schedule payment status'), 
        'field' => array(
      'handler' => 'fee_management_handler_field_payment_status', 
      'click sortable' => TRUE, // This is use by the table display plugin.
    ), 
    'filter' => array(
      'handler' => 'fee_management_handler_filter_payment_status',
      'numeric' => TRUE,
    ),
    ); 

Handler

class fee_management_handler_filter_payment_status extends views_handler_filter_many_to_one {
  function get_value_options() {
    $this->value_options = array('1' => 'Paid', '0' => 'Unpaid');
  }

    function query() {
    // as per your database st
        ;


  }


}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.