/includes/class-gfp-stripe-list-table.php

  1. <?php 
  2. /** @package GFP_Stripe_List_Table 
  3. * @copyright 2014 gravity+ 
  4. * @license GPL-2.0+ 
  5. * @since 1.8.2 
  6. */ 
  7.  
  8. /** 
  9. * Class GFP_Stripe_List_Table 
  10. * 
  11. * @since 1.8.2 
  12. */ 
  13. class GFP_Stripe_List_Table extends WP_List_Table { 
  14.  
  15. private $_form_id; 
  16.  
  17. function __construct ( $form_id ) { 
  18.  
  19. $this->_form_id = $form_id; 
  20.  
  21. $this->_column_headers = array( 
  22. array( 
  23. 'cb' => '',  
  24. 'name' => __( 'Rule Name', 'gravity-forms-stripe' ),  
  25. 'type' => __( 'Transaction Type', 'gravity-forms-stripe' ) 
  26. ),  
  27. array(),  
  28. array() 
  29. ); 
  30.  
  31. parent::__construct(); 
  32.  
  33. public function get_columns() { 
  34.  
  35. return $this->_column_headers[0]; 
  36.  
  37. function prepare_items () { 
  38.  
  39. $feeds = GFP_Stripe_Data::get_feed_by_form( $this->_form_id ); 
  40. $this->items = $feeds; 
  41.  
  42. function display () { 
  43. $singular = $this->_args['singular']; 
  44. ?> 
  45.  
  46. <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>" cellspacing="0"> 
  47. <thead> 
  48. <tr> 
  49. <?php $this->print_column_headers(); ?> 
  50. </tr> 
  51. </thead> 
  52.  
  53. <tfoot> 
  54. <tr> 
  55. <?php $this->print_column_headers( false ); ?> 
  56. </tr> 
  57. </tfoot> 
  58.  
  59. <tbody id="the-list"<?php if ( $singular ) { 
  60. echo " class='list:$singular'"; 
  61. } ?>> 
  62.  
  63. <?php $this->display_rows_or_placeholder(); ?> 
  64.  
  65. </tbody> 
  66. </table> 
  67.  
  68. <?php 
  69.  
  70. function single_row ( $item ) { 
  71. static $row_class = ''; 
  72. $row_class = ( $row_class == '' ? ' class="alternate"' : '' ); 
  73.  
  74. echo '<tr id="stripe-' . $item['id'] . '" ' . $row_class . '>'; 
  75. echo $this->single_row_columns( $item ); 
  76. echo '</tr>'; 
  77.  
  78. function column_default ( $item, $column ) { 
  79. echo rgar( $item, $column ); 
  80.  
  81. function column_cb ( $item ) { 
  82. $is_active = isset( $item['is_active'] ) ? $item['is_active'] : true; 
  83. ?> 
  84. <img src="<?php echo GFCommon::get_base_url() ?>/images/active<?php echo intval( $is_active ) ?>.png" 
  85. style="cursor: pointer;" 
  86. alt="<?php echo $is_active ? __( 'Active', 'gravity-forms-stripe' ) : __( 'Inactive', 'gravity-forms-stripe' ); ?>" 
  87. title="<?php echo $is_active ? __( 'Active', 'gravity-forms-stripe' ) : __( 'Inactive', 'gravity-forms-stripe' ); ?>" 
  88. onclick="ToggleStripeFeedActive( this, '<?php echo $item['id'] ?>', '<?php echo $item['form_id'] ?>' ); "/> 
  89. <?php 
  90.  
  91. function column_name ( $item ) { 
  92. $edit_url = add_query_arg( array( 'sid' => $item['id'] ) ); 
  93. $actions = apply_filters( 'gfp_stripe_feed_actions', array( 
  94. 'edit' => '<a title="' . __( 'Edit this item', 'gravity-forms-stripe' ) . '" href="' . $edit_url . '">' . __( 'Edit', 'gravity-forms-stripe' ) . '</a>',  
  95. 'delete' => '<a title="' . __( 'Delete this item', 'gravity-forms-stripe' ) . '" class="submitdelete" onclick="javascript: if(confirm(\'' . __( "WARNING: You are about to delete this Stripe rule.", "gfp-stripe" ) . __( "\'Cancel\' to stop, \'OK\' to delete.", "gfp-stripe" ) . '\')) { DeleteStripeFeed(\'' . $item["id"] . '\'); }" style="cursor:pointer;">' . __( 'Delete', 'gravity-forms-stripe' ) . '</a>' 
  96. ) ); 
  97. ?> 
  98.  
  99. <strong><?php echo rgars( $item, 'meta/rule_name' ); ?></strong> 
  100. <div class="row-actions"> 
  101.  
  102. <?php 
  103. if ( is_array( $actions ) && ! empty( $actions ) ) { 
  104. $action_keys = array_keys( $actions ); 
  105. $last_key = array_pop( $action_keys ); 
  106. foreach ( $actions as $key => $html ) { 
  107. $divider = $key == $last_key ? '' : " | "; 
  108. ?> 
  109. <span class="<?php echo $key; ?>"> 
  110. <?php echo $html . $divider; ?> 
  111. </span> 
  112. <?php 
  113. ?> 
  114.  
  115. </div> 
  116.  
  117. <?php 
  118.  
  119. function column_type ( $item ) { 
  120. if ( has_action( 'gfp_stripe_list_feeds_product_type' ) ) { 
  121. do_action( 'gfp_stripe_list_feeds_product_type', $item ); 
  122. else { 
  123. switch ( $item['meta']['type'] ) { 
  124. case 'product' : 
  125. _e( 'One-Time Payment', 'gravity-forms-stripe' ); 
  126. break; 
  127.  
  128. function no_items () { 
  129. $add_new_url = add_query_arg( array( 'sid' => 0 ) ); 
  130. printf( __( "You currently don't have any Stripe Rules, let's go %screate one%s", 'gravity-forms-stripe' ), "<a href='{$add_new_url}'>", "</a>" ); 
.