NGG_Gallery_List_Table

Class NGG_List_Table.

Defined (1)

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

/admin/manage/class-ngg-gallery-list-table.php  
  1. class NGG_Gallery_List_Table extends WP_List_Table { 
  2.  
  3. private $base; 
  4.  
  5. public function __construct( $base, $screen = null ) { 
  6.  
  7. parent::__construct( array( 'screen' => $screen, 'plural' => 'ngg-manager' ) ); 
  8.  
  9. $this->base = $base; 
  10.  
  11. /** 
  12. * Prepare the items for the table to process 
  13. * @return Void 
  14. */ 
  15. public function prepare_items() { 
  16.  
  17. /** 
  18. * @global $nggdb nggdb 
  19. */ 
  20. global $nggdb; 
  21.  
  22. $columns = $this->get_columns(); 
  23. $hidden = $this->get_hidden_columns(); 
  24. $sortable = $this->get_sortable_columns(); 
  25.  
  26. $this->_column_headers = array( $columns, $hidden, $sortable ); 
  27.  
  28. /** 
  29. * Do the pagination. 
  30. */ 
  31. $currentPage = $this->get_pagenum(); 
  32. $perPage = $this->get_items_per_page('ngg_galleries_per_page', 25); 
  33.  
  34. /** 
  35. * Sorting 
  36. */ 
  37. if ( ( isset ( $_GET['order'] ) && $_GET['order'] == 'desc' ) ) { 
  38. $order = 'DESC'; 
  39. } else { 
  40. $order = 'ASC'; 
  41.  
  42. if ( ( isset ( $_GET['orderby'] ) && ( in_array( $_GET['orderby'], array( 'gid', 'title', 'author' ) ) ) ) ) { 
  43. $order_by = $_GET['orderby']; 
  44. } else { 
  45. $order_by = 'gid'; 
  46.  
  47. $start = ( $currentPage - 1 ) * $perPage; 
  48. $this->items = $nggdb->find_all_galleries( $order_by, $order, true, $perPage, $start, true ); 
  49.  
  50. $totalItems = (int) $nggdb->count_galleries(); 
  51.  
  52. $this->set_pagination_args( array( 
  53. 'total_items' => $totalItems,  
  54. 'per_page' => $perPage 
  55. ) ); 
  56.  
  57. /** 
  58. * Sort the items/ 
  59. */ 
  60. usort( $this->items, array( $this, 'sort' ) ); 
  61.  
  62. /** 
  63. * Get the hidden columns from the screen options. 
  64. */ 
  65. private function get_hidden_columns() { 
  66. return (array) get_user_option( 'manage' . $this->screen->id . 'columnshidden' ); 
  67.  
  68. /** 
  69. * The checkbox column. 
  70. * @param object $item 
  71. * @return string 
  72. */ 
  73. protected function column_cb( $item ) { 
  74. if ( nggAdmin::can_manage_this_gallery( $item->author ) ) { 
  75. return '<input name="doaction[]" type="checkbox" value="' . $item->gid . '" />'; 
  76. } else { 
  77. return ""; 
  78.  
  79. protected function column_title( $item ) { 
  80. if ( nggAdmin::can_manage_this_gallery( $item->author ) ) { 
  81. $out = '<a href="' . wp_nonce_url( $this->base . '&mode=image&gid=' . $item->gid,  
  82. 'ngg_editgallery' ) . '" class="edit" title="' . __( 'Edit' ) . '">'; 
  83. $out .= esc_html( $item->title ); 
  84. $out .= "</a>"; 
  85. } else { 
  86. $out = esc_html( $item->title ); 
  87. $out .= '<div class="row-actions"></div>'; 
  88.  
  89. return $out; 
  90.  
  91. /** 
  92. * Define what data to show on each column of the table 
  93. * @param nggGallery $item Data 
  94. * @param String $column_name - Current column name 
  95. * @return Mixed 
  96. */ 
  97. protected function column_default( $item, $column_name ) { 
  98. switch ( $column_name ) { 
  99. case 'id': 
  100. return $item->gid; 
  101. case 'description': 
  102. return $item->galdesc; 
  103. case 'author': 
  104. return $item->author; 
  105. case 'page_id': 
  106. return $item->pageid; 
  107. case 'quantity': 
  108. return $item->counter; 
  109. default: 
  110. ob_start(); 
  111. do_action( 'ngg_manage_gallery_custom_column', $column_name, $item->gid ); 
  112.  
  113. return ob_get_clean(); 
  114.  
  115. /** 
  116. * With this we can register the columns in the screen options. 
  117. */ 
  118. public static function get_columns_static() { 
  119.  
  120. $columns = array( 
  121. 'cb' => '<input type="checkbox" />',  
  122. 'id' => __( 'ID', 'nggallery' ),  
  123. 'title' => __( 'Title', 'nggallery' ),  
  124. 'description' => __( 'Description', 'nggallery' ),  
  125. 'author' => __( 'Author', 'nggallery' ),  
  126. 'page_id' => __( 'Page ID', 'nggallery' ),  
  127. 'quantity' => __( 'Images', 'nggallery' ) 
  128. ); 
  129.  
  130. /** 
  131. * Apply a filter to the columns. 
  132. */ 
  133. $columns = apply_filters( 'ngg_manage_gallery_columns', $columns ); 
  134.  
  135. return $columns; 
  136.  
  137.  
  138. /** 
  139. * Get the columns. 
  140. */ 
  141. public function get_columns() { 
  142.  
  143. return self::get_columns_static(); 
  144.  
  145. /** 
  146. * Get the sortable columns. 
  147. */ 
  148. protected function get_sortable_columns() { 
  149. return array( 
  150. 'id' => array( 'gid', true ),  
  151. 'title' => array( 'title', false ),  
  152. 'author' => array( 'author', false ) 
  153. ); 
  154.  
  155. private function sort( $a, $b ) { 
  156.  
  157. if ( isset( $_GET['orderby'] ) && $_GET['orderby'] === 'title' ) { 
  158. $result = strnatcmp( $a->title, $b->title ); 
  159. } else { 
  160. if ( isset( $_GET['orderby'] ) ) { 
  161. $orderby = $_GET['orderby']; 
  162. } else { 
  163. $orderby = 'gid'; 
  164. $result = $a->{$orderby} - $b->{$orderby}; 
  165.  
  166. if ( ! isset( $_GET['order'] ) || $_GET['order'] === 'asc' ) { 
  167. return $result; 
  168. } else { 
  169. return - $result; 
  170.  
  171. protected function get_bulk_actions() { 
  172. return array( 
  173. 'delete_gallery' => __( 'Delete', 'nggallery' ),  
  174. 'set_watermark' => __( 'Set watermark', 'nggallery' ),  
  175. 'new_thumbnail' => __( 'Create new thumbnails', 'nggallery' ),  
  176. 'resize_images' => __( 'Resize images', 'nggallery' ),  
  177. 'import_meta' => __( 'Import metadata', 'nggallery' ),  
  178. 'recover_images' => __( 'Recover from backup', 'nggallery' ),  
  179. );