HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: /var/www/html/shootinschool/wp-content/plugins/shootin-school-plugin/list_packages.php
<?php
if (!class_exists('WP_List_Table')) {
	require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
global $postNumber;
$postNumber = 1;

function render_siab_packages(){

   class Packages_List_Table extends WP_List_Table
	{
		/**
		 * Prepare the items for the table to process
		 *
		 * @return Void
		 */

		public function prepare_items()
		{
			$columns = $this->get_columns();
			$hidden = $this->get_hidden_columns();
			$sortable = $this->get_sortable_columns();

			$data = $this->table_data();
			usort($data, array(&$this, 'sort_data'));

			$perPage = 10;
			$currentPage = $this->get_pagenum();
			$totalItems = count($data);

			$this->set_pagination_args(array(
				'total_items' => $totalItems,
				'per_page'    => $perPage
			));

			$data = array_slice($data, (($currentPage - 1) * $perPage), $perPage);

			$this->_column_headers = array($columns, $hidden, $sortable);
			$this->items = $data;
		}

		/**
		 * Override the parent columns method. Defines the columns to use in your listing table
		 *
		 * @return Array
		 */
		public function get_columns()
		{
			$columns = array(
				'id' => 'Sl No',
				'session_name'	=> 'Session Name',
				'credit' => 'Credit',
				'price' => 'Price',

				'min_capacity' => 'Min Capacity',
				'max_capacity' => 'Max Capacity',
				'actions' => 'Actions',
			);

			return $columns;
		}

		/**
		 * Define which columns are hidden
		 *
		 * @return Array
		 */
		public function get_hidden_columns()
		{
			return array();
		}

		/**
		 * Define the sortable columns
		 *
		 * @return Array
		 */
		public function get_sortable_columns()
		{
			return array('session_name' => array('session_name', false));
		}

		/**
		 * Get the table data
		 *
		 * @return Array
		 */
		private function table_data()
		{
			global $wpdb;
			$data = $wpdb->get_results("SELECT * FROM " . DB_PACKAGE_SESSIONS, ARRAY_A);

			return $data;
		}

		/**
		 * Define what data to show on each column of the table
		 *
		 * @param  Array $item        Data
		 * @param  String $column_name - Current column name
		 *
		 * @return Mixed
		 */
		public function column_default($item, $column_name)
		{
			switch ($column_name) {
				case 'id':
				  echo $postNumber;
				case 'session_name':
				case 'credit':
				case 'price':
				case 'min_capacity':
				case 'max_capacity':
				  return $item[$column_name];




				default:
					return print_r($item, true);
			}
			$postNumber++;
		}

		function column_actions($item){

		    $actions = array(
		        'edit'      => sprintf('<a href="?page=add_session&action=edit&id='.$item['id'].'">Edit</a>', $_REQUEST['page'],'edit',$item['id']),
		        // 'delete'    => sprintf('<a href="?page=siab-locations&action=delete&id='.$item['id'].'">Delete</a>', $_REQUEST['page'],'delete',$item['id']),
		    );

		    // return sprintf('%1$s %2$s',
		    // 	urlencode(base64_encode($item['id'])),
		    // 	$this->row_actions($actions)
		    // );

		    return sprintf('%1$s <span style="color:silver">(id:%2$s)</span>%3$s',
		        /*$1%s*/ $item['title'],
		        /*$2%s*/ $item['id'],
		        /*$3%s*/ $this->row_actions($actions)
		    );
		}

		/**
		 * Allows you to sort the data by the variables set in the $_GET
		 *
		 * @return Mixed
		 */
		private function sort_data($a, $b)
		{
			// Set defaults
			$orderby = 'id';
			$order = 'asc';

			// If orderby is set, use this as the sort column
			if (!empty($_GET['orderby'])) {
				$orderby = $_GET['orderby'];
			}

			// If order is set use this as the order
			if (!empty($_GET['order'])) {
				$order = $_GET['order'];
			}

			$result = strcmp($a[$orderby], $b[$orderby]);

			if ($order === 'asc') {
				return $result;
			}

			return -$result;
		}

	}
	$importedListTable = new Packages_List_Table();
	$importedListTable->prepare_items();
	?>
	<div class="wrap">
		<div class="alert alert-info" role="alert" style="border: 1px solid green;border-radius: 5px;">
			<h3> Instructor Packages </h3>
			<a class="add-new-h2" href="admin.php?page=add_package_group">Add New Package Group</a>
			<a class="add-new-h2" href="admin.php?page=add_session">Add Session </a>
		</div>
		<?php $importedListTable->display(); ?>
	</div>
	<?php
}
 ?>