MS_Helper_ListTable_RuleMatching

Membership Matching-List Table.

Defined (1)

The class is defined in the following location(s).

/app/helper/listtable/class-ms-helper-listtable-rulematching.php  
  1. class MS_Helper_ListTable_RuleMatching extends MS_Helper_ListTable_Rule { 
  2.  
  3. /** 
  4. * List of matching options that are available for each list item. 
  5. * @var array 
  6. */ 
  7. protected $matching_options = array(); 
  8.  
  9. /** 
  10. * True means that the matching can be changed. 
  11. * False will display the matching details in read-only mode 
  12. * @var bool 
  13. */ 
  14. protected $editable = true; 
  15.  
  16. /** 
  17. * Constructor. 
  18. * @since 1.0.0 
  19. * @param MS_Model $model Model for the list data. 
  20. * @param MS_Model_Membership $membership The associated membership. 
  21. */ 
  22. public function __construct( $model ) { 
  23. parent::__construct( $model ); 
  24.  
  25. /** 
  26. * Defines available columns. 
  27. * Generally this list will not change... 
  28. * @since 1.0.0 
  29. * @return array 
  30. */ 
  31. public function get_columns() { 
  32. $columns = array( 
  33. 'item' => $this->get_column_label( 'item' ),  
  34. 'match' => $this->get_column_label( 'match' ),  
  35. ); 
  36.  
  37. return apply_filters( 
  38. 'ms_helper_listtable_' . $this->id . '_columns',  
  39. $columns 
  40. ); 
  41.  
  42. /** 
  43. * Allows child classes to easily override the column captions. 
  44. * @since 1.0.0 
  45. * @param string $col 
  46. * @return string 
  47. */ 
  48. protected function get_column_label( $col ) { 
  49. $label = ''; 
  50.  
  51. switch ( $col ) { 
  52. case 'item': $label = __( 'Item', 'membership2' ); break; 
  53. case 'match': $label = __( 'Matching', 'membership2' ); break; 
  54.  
  55. return $label; 
  56.  
  57. /** 
  58. * Define which columns are included in the list that are not displayed. 
  59. * Usually this is an empty array. 
  60. * @since 1.0.0 
  61. * @return array 
  62. */ 
  63. public function get_hidden_columns() { 
  64. return apply_filters( 
  65. 'ms_helper_listtable_' . $this->id . '_hidden_columns',  
  66. array() 
  67. ); 
  68.  
  69. /** 
  70. * Define which columns can be sorted. 
  71. * @since 1.0.0 
  72. * @return array 
  73. */ 
  74. public function get_sortable_columns() { 
  75. return apply_filters( 
  76. 'ms_helper_listtable_' . $this->id . '_sortable_columns',  
  77. array() 
  78. ); 
  79.  
  80. /** 
  81. * Prepare the table contents so they can be displayed later. 
  82. * @since 1.0.0 
  83. */ 
  84. public function prepare_items() { 
  85. parent::prepare_items(); 
  86.  
  87. // Load the matching-list that is displayed for each item. 
  88. $this->matching_options = apply_filters( 
  89. 'ms_helper_listtable_matching_' . $this->id . ' _matching',  
  90. $this->model->get_matching_options() 
  91. ); 
  92.  
  93. /** 
  94. * Renders the contents of the ITEM colum. 
  95. * @since 1.0.0 
  96. * @param mixed $item 
  97. * @param string $column_name 
  98. * @return string HTML code 
  99. */ 
  100. public function column_item( $item ) { 
  101. $html = $item->title; 
  102. return $html; 
  103.  
  104. /** 
  105. * Renders the contents of the MATCH/REPLACE column. 
  106. * @since 1.0.0 
  107. * @param mixed $item 
  108. * @param string $column_name 
  109. * @return string HTML code 
  110. */ 
  111. public function column_match( $item ) { 
  112. if ( $this->editable ) { 
  113. $list = array( 
  114. 'id' => 'ms-list-' . $item->id,  
  115. 'type' => MS_Helper_Html::INPUT_TYPE_SELECT,  
  116. 'value' => $item->value,  
  117. 'field_options' => $this->matching_options,  
  118. 'ajax_data' => array( 
  119. 'action' => MS_Controller_Rule::AJAX_ACTION_UPDATE_MATCHING,  
  120. 'rule_type' => $item->type,  
  121. 'item' => $item->id,  
  122. ),  
  123. ); 
  124. $html = MS_Helper_Html::html_element( $list, true ); 
  125. } else { 
  126. if ( isset( $this->matching_options[$item->value] ) ) { 
  127. $html = esc_html( $this->matching_options[$item->value] ); 
  128. } else { 
  129. $html = '-'; 
  130.  
  131. return $html; 
  132.