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

  1. <?php 
  2. /** 
  3. * Membership List Table 
  4. * 
  5. * @since 1.0.0 
  6. */ 
  7. class MS_Helper_ListTable_Event extends MS_Helper_ListTable { 
  8.  
  9. protected $id = 'event'; 
  10.  
  11. public function __construct() { 
  12. parent::__construct( 
  13. array( 
  14. 'singular' => 'event',  
  15. 'plural' => 'events',  
  16. 'ajax' => false,  
  17. ); 
  18.  
  19. public function get_columns() { 
  20. $columns = array( 
  21. 'post_modified' => __( 'Date', 'membership2' ),  
  22. 'user_id' => __( 'Member', 'membership2' ),  
  23. 'membership_id' => __( 'Membership', 'membership2' ),  
  24. 'description' => __( 'Event', 'membership2' ),  
  25. ); 
  26.  
  27. if ( isset( $_REQUEST['membership_id'] ) ) { 
  28. unset( $columns['membership_id'] ); 
  29.  
  30. return apply_filters( 
  31. 'membership_helper_listtable_event_columns',  
  32. $columns 
  33. ); 
  34.  
  35. public function get_sortable_columns() { 
  36. return apply_filters( 
  37. 'membership_helper_listtable_event_sortable_columns',  
  38. array( 
  39. 'post_modified' => array( 'post_modified', false ),  
  40. 'user_id' => array( 'user_id', false ),  
  41. 'membership_id' => array( 'membership_id', false ),  
  42. ); 
  43.  
  44. /** 
  45. * Prepare list items. 
  46. * 
  47. * @since 1.0.0 
  48. */ 
  49. public function prepare_items() { 
  50. $this->_column_headers = array( 
  51. $this->get_columns(),  
  52. array(),  
  53. $this->get_sortable_columns(),  
  54. ); 
  55.  
  56. $per_page = apply_filters( 
  57. 'ms_helper_listtable_member_items_per_page',  
  58. self::DEFAULT_PAGE_SIZE 
  59. ); 
  60. $current_page = $this->get_pagenum(); 
  61.  
  62. $args = array( 
  63. 'posts_per_page' => $per_page,  
  64. 'offset' => ( $current_page - 1 ) * $per_page,  
  65. ); 
  66.  
  67. if ( isset( $_REQUEST['membership_id'] ) ) { 
  68. $args['membership_id'] = $_REQUEST['membership_id']; 
  69.  
  70. if ( ! empty( $_REQUEST['s'] ) ) { 
  71. $args['s'] = $_REQUEST['s']; 
  72. $this->search_string = $args['s']; 
  73. $args['posts_per_page'] = -1; 
  74. $args['number'] = false; 
  75. $args['offset'] = 0; 
  76.  
  77. // Prepare order by statement. 
  78. if ( ! empty( $_REQUEST['orderby'] ) && ! empty( $_REQUEST['order'] ) ) { 
  79. $args['orderby'] = $_REQUEST['orderby']; 
  80. $args['order'] = $_REQUEST['order']; 
  81.  
  82. $total_items = MS_Model_Event::get_event_count( $args ); 
  83. $this->items = MS_Model_Event::get_events( $args ); 
  84.  
  85. $this->set_pagination_args( 
  86. array( 
  87. 'total_items' => $total_items,  
  88. 'per_page' => $per_page,  
  89. ); 
  90.  
  91. do_action( 
  92. 'ms_helper_listtable_event_prepare_items',  
  93. $args,  
  94. $this 
  95. ); 
  96.  
  97. public function column_user_id( $item, $column_name ) { 
  98. $member = MS_Factory::load( 
  99. 'MS_Model_Member',  
  100. $item->user_id 
  101. ); 
  102. $html = $member->username; 
  103.  
  104. return $html; 
  105.  
  106. public function column_membership_id( $item, $column_name ) { 
  107. $membership = MS_Factory::load( 
  108. 'MS_Model_Membership',  
  109. $item->membership_id 
  110. ); 
  111. $html = $membership->name; 
  112.  
  113. return $html; 
  114.  
  115. public function column_post_modified( $item, $column_name ) { 
  116. $html = MS_Helper_Period::format_date( $item->post_modified ); 
  117.  
  118. return $html; 
  119.  
  120. public function column_description( $item, $column_name ) { 
  121. $html = $item->description; 
  122.  
  123. return $html; 
  124.  
.