/app/helper/listtable/class-ms-helper-listtable-rulematching.php

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