PageRenderTime 108ms CodeModel.GetById 53ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/wp-lister-for-ebay/classes/table/ListingsTable.php

https://bitbucket.org/sanders_nick/my-maxi-skirt
PHP | 658 lines | 374 code | 110 blank | 174 comment | 72 complexity | 45d2b80014cb425ce8184f38668af1ba MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, AGPL-1.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. /*************************** LOAD THE BASE CLASS *******************************
  3. *******************************************************************************
  4. * The WP_List_Table class isn't automatically available to plugins, so we need
  5. * to check if it's available and load it if necessary.
  6. */
  7. if(!class_exists('WP_List_Table')){
  8. require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  9. }
  10. /************************** CREATE A PACKAGE CLASS *****************************
  11. *******************************************************************************
  12. * Create a new list table package that extends the core WP_List_Table class.
  13. * WP_List_Table contains most of the framework for generating the table, but we
  14. * need to define and override some methods so that our data can be displayed
  15. * exactly the way we need it to be.
  16. *
  17. * To display this example on a page, you will first need to instantiate the class,
  18. * then call $yourInstance->prepare_items() to handle any data manipulation, then
  19. * finally call $yourInstance->display() to render the table to the page.
  20. *
  21. * Our theme for this list table is going to be profiles.
  22. */
  23. class ListingsTable extends WP_List_Table {
  24. /** ************************************************************************
  25. * REQUIRED. Set up a constructor that references the parent constructor. We
  26. * use the parent reference to set some default configs.
  27. ***************************************************************************/
  28. function __construct(){
  29. global $status, $page;
  30. //Set parent defaults
  31. parent::__construct( array(
  32. 'singular' => 'auction', //singular name of the listed records
  33. 'plural' => 'auctions', //plural name of the listed records
  34. 'ajax' => false //does this table support ajax?
  35. ) );
  36. // get array of profile names
  37. $profilesModel = new ProfilesModel();
  38. $this->profiles = $profilesModel->getAllNames();
  39. }
  40. /** ************************************************************************
  41. * Recommended. This method is called when the parent class can't find a method
  42. * specifically build for a given column. Generally, it's recommended to include
  43. * one method for each column you want to render, keeping your package class
  44. * neat and organized. For example, if the class needs to process a column
  45. * named 'title', it would first see if a method named $this->column_title()
  46. * exists - if it does, that method will be used. If it doesn't, this one will
  47. * be used. Generally, you should try to use custom column methods as much as
  48. * possible.
  49. *
  50. * Since we have defined a column_title() method later on, this method doesn't
  51. * need to concern itself with any column with a name of 'title'. Instead, it
  52. * needs to handle everything else.
  53. *
  54. * For more detailed insight into how columns are handled, take a look at
  55. * WP_List_Table::single_row_columns()
  56. *
  57. * @param array $item A singular item (one full row's worth of data)
  58. * @param array $column_name The name/slug of the column to be processed
  59. * @return string Text or HTML to be placed inside the column <td>
  60. **************************************************************************/
  61. function column_default($item, $column_name){
  62. switch($column_name){
  63. case 'type':
  64. case 'quantity_sold':
  65. case 'ebay_id':
  66. case 'status':
  67. return $item[$column_name];
  68. case 'fees':
  69. case 'price':
  70. return $this->number_format( $item[$column_name], 2 );
  71. case 'end_date':
  72. case 'date_published':
  73. // use date format from wp
  74. return mysql2date( get_option('date_format'), $item[$column_name] );
  75. case 'template':
  76. return basename( $item['template'] );
  77. case 'profile':
  78. return isset($item['profile_id']) ? $this->profiles[ $item['profile_id'] ] : '';
  79. default:
  80. return print_r($item,true); //Show the whole array for troubleshooting purposes
  81. }
  82. }
  83. /** ************************************************************************
  84. * Recommended. This is a custom column method and is responsible for what
  85. * is rendered in any column with a name/slug of 'title'. Every time the class
  86. * needs to render a column, it first looks for a method named
  87. * column_{$column_title} - if it exists, that method is run. If it doesn't
  88. * exist, column_default() is called instead.
  89. *
  90. * This example also illustrates how to implement rollover actions. Actions
  91. * should be an associative array formatted as 'slug'=>'link html' - and you
  92. * will need to generate the URLs yourself. You could even ensure the links
  93. *
  94. *
  95. * @see WP_List_Table::::single_row_columns()
  96. * @param array $item A singular item (one full row's worth of data)
  97. * @return string Text to be placed inside the column <td> (profile title only)
  98. **************************************************************************/
  99. function column_auction_title($item){
  100. // get current page with paging as url param
  101. $page = $_REQUEST['page'];
  102. if ( isset( $_REQUEST['paged'] )) $page .= '&paged='.$_REQUEST['paged'];
  103. //Build row actions
  104. $actions = array(
  105. 'preview_auction' => sprintf('<a href="?page=%s&action=%s&auction=%s&width=820&height=550" class="thickbox">%s</a>',$page,'preview_auction',$item['id'],__('Preview','wplister')),
  106. 'edit' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'edit',$item['id'],__('Edit','wplister')),
  107. 'verify' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'verify',$item['id'],__('Verify','wplister')),
  108. 'publish2e' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'publish2e',$item['id'],__('Publish','wplister')),
  109. 'open' => sprintf('<a href="%s" target="_blank">%s</a>',$item['ViewItemURL'],__('View on eBay','wplister')),
  110. 'revise' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'revise',$item['id'],__('Revise','wplister')),
  111. 'end_item' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'end_item',$item['id'],__('End Listing','wplister')),
  112. #'update' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'update',$item['id'],__('Update','wplister')),
  113. #'open' => sprintf('<a href="%s" target="_blank">%s</a>',$item['ViewItemURL'],__('Open in new tab','wplister')),
  114. 'relist' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'relist',$item['id'],__('Relist','wplister')),
  115. 'delete' => sprintf('<a href="?page=%s&action=%s&auction=%s">%s</a>',$page,'delete',$item['id'],__('Delete','wplister')),
  116. );
  117. $profile_data = maybe_unserialize( $item['profile_data'] );
  118. $listing_title = $item['auction_title'];
  119. // make title link to products edit page
  120. if ( ProductWrapper::plugin == 'woo' ) {
  121. $listing_title = '<a class="product_title_link" href="post.php?post='.$item['post_id'].'&action=edit">'.$listing_title.'</a>';
  122. } elseif ( ProductWrapper::plugin == 'shopp' ) {
  123. $listing_title = '<a class="product_title_link" href="admin.php?page=shopp-products&id='.$item['post_id'].'">'.$listing_title.'</a>';
  124. }
  125. // show variations
  126. if ( ProductWrapper::hasVariations( $item['post_id'] ) ) {
  127. $listing_title .= ' (<a href="#" onClick="jQuery(\'#pvars_'.$item['id'].'\').toggle();return false;">&raquo;Variations</a>)<br>';
  128. // $listing_title .= '<pre>'.print_r( ProductWrapper::getVariations( $item['post_id'] ), 1 )."</pre>";
  129. $variations = ProductWrapper::getVariations( $item['post_id'] );
  130. $listingsModel = new ListingsModel();
  131. $variations_html = '<div id="pvars_'.$item['id'].'" class="variations_list" style="display:none;margin-bottom:10px;">';
  132. // show variation mode message
  133. if ( isset( $profile_data['details']['variations_mode'] ) && ( $profile_data['details']['variations_mode'] == 'flat' ) ) {
  134. $variations_html .= '<p><b>' . __('These variations will be listed as a single item.','wplister') . '</b></p>';
  135. }
  136. $variations_html .= '<table style="margin-bottom: 8px;">';
  137. // header
  138. $variations_html .= '<tr><th>';
  139. $variations_html .= '&nbsp;';
  140. $variations_html .= '</th><th>';
  141. foreach ($variations[0]['variation_attributes'] as $name => $value) {
  142. $variations_html .= $name;
  143. $variations_html .= '</th><th>';
  144. }
  145. $variations_html .= __('Price','wplister');
  146. $variations_html .= '</th></tr>';
  147. foreach ($variations as $var) {
  148. // first column: quantity
  149. $variations_html .= '<tr><td align="right">';
  150. $variations_html .= intval( $var['stock'] ) . '&nbsp;x';
  151. $variations_html .= '</td>';
  152. foreach ($var['variation_attributes'] as $name => $value) {
  153. // $variations_html .= $name.': '.$value ;
  154. $variations_html .= '<td>';
  155. $variations_html .= $value ;
  156. $variations_html .= '</td>';
  157. }
  158. // $variations_html .= '('.$var['sku'].') ';
  159. // $variations_html .= '('.$var['image'].') ';
  160. // last column: price
  161. $variations_html .= '<td align="right">';
  162. $price = $listingsModel->applyProfilePrice( $var['price'], $profile_data['details']['start_price'] );
  163. $variations_html .= $this->number_format( $price, 2 );
  164. $variations_html .= '</td></tr>';
  165. }
  166. $variations_html .= '</table>';
  167. // show variation mode message
  168. if ( isset( $profile_data['details']['variations_mode'] ) && ( $profile_data['details']['variations_mode'] == 'flat' ) ) {
  169. // $variations_html .= '<p><b>' . __('These variations will be listed as a single item.','wplister') . '</b></p>';
  170. } else {
  171. }
  172. // list shopp addons
  173. if ( ProductWrapper::plugin == 'shopp' ) {
  174. $addons = ProductWrapper::getAddons( $item['post_id'] );
  175. $variations_html .= '<table style="margin-bottom: 8px;">';
  176. foreach ($addons as $addonGroup) {
  177. // first column: quantity
  178. $variations_html .= '<tr><td colspan="2" align="left"><b>';
  179. $variations_html .= $addonGroup->name;
  180. $variations_html .= '</b></td></tr>';
  181. foreach ($addonGroup->options as $addon) {
  182. $variations_html .= '<tr><td align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  183. $variations_html .= $addon->name;
  184. $variations_html .= '</td><td align="right">';
  185. $variations_html .= $this->number_format( $addon->price, 2 );
  186. $variations_html .= '</td></tr>';
  187. }
  188. }
  189. $variations_html .= '</table>';
  190. }
  191. $variations_html .= '</div>';
  192. $listing_title .= $variations_html;
  193. }
  194. // disable some actions depending on status
  195. if ( $item['status'] != 'published' ) unset( $actions['end_item'] );
  196. if ( $item['status'] != 'prepared' ) unset( $actions['verify'] );
  197. if ( $item['status'] != 'changed' ) unset( $actions['revise'] );
  198. if (($item['status'] != 'prepared' ) &&
  199. ($item['status'] != 'verified')) unset( $actions['publish2e'] );
  200. if (($item['status'] != 'published' ) &&
  201. ($item['status'] != 'changed') &&
  202. ($item['status'] != 'ended')) unset( $actions['open'] );
  203. if ( $item['status'] == 'ended' ) unset( $actions['edit'] );
  204. if ( $item['status'] == 'ended' ) unset( $actions['preview_auction'] );
  205. if ( $item['status'] != 'ended' ) unset( $actions['delete'] );
  206. if ( $item['status'] != 'ended' ) unset( $actions['relist'] );
  207. //Return the title contents
  208. //return sprintf('%1$s <span style="color:silver">%2$s</span>%3$s',
  209. return sprintf('%1$s %2$s',
  210. /*$1%s*/ $listing_title,
  211. /*$2%s*/ //$item['profile_id'],
  212. /*$3%s*/ $this->row_actions($actions)
  213. );
  214. }
  215. function column_ebay_id_DISABLED($item){
  216. //Build row actions
  217. #if ( intval($item['ebay_id']) > 0)
  218. if ( trim($item['ViewItemURL']) != '')
  219. $actions = array(
  220. 'open' => sprintf('<a href="%s" target="_blank">%s</a>',$item['ViewItemURL'],__('View on eBay','wplister')),
  221. );
  222. //Return the title contents
  223. return sprintf('%1$s %2$s',
  224. /*$1%s*/ $item['ebay_id'],
  225. /*$2%s*/ $this->row_actions($actions)
  226. );
  227. }
  228. function column_quantity($item){
  229. // use profile quantity for flattened variations
  230. $profile_data = maybe_unserialize( $item['profile_data'] );
  231. if ( isset( $profile_data['details']['variations_mode'] ) && ( $profile_data['details']['variations_mode'] == 'flat' ) ) {
  232. if ( $item['quantity_sold'] > 0 ) {
  233. $qty_available = $item['quantity'] - $item['quantity_sold'];
  234. return $qty_available . ' / ' . $item['quantity'];
  235. }
  236. return $item['quantity'];
  237. }
  238. // if item has variations count them...
  239. if ( ProductWrapper::hasVariations( $item['post_id'] ) ) {
  240. $variations = ProductWrapper::getVariations( $item['post_id'] );
  241. $quantity = 0;
  242. foreach ($variations as $var) {
  243. $quantity += intval( $var['stock'] );
  244. }
  245. return $quantity;
  246. }
  247. if ( $item['quantity_sold'] > 0 ) {
  248. $qty_available = $item['quantity'] - $item['quantity_sold'];
  249. return $qty_available . ' / ' . $item['quantity'];
  250. }
  251. return $item['quantity'];
  252. }
  253. function column_price($item){
  254. // if item has variations check each price...
  255. if ( ProductWrapper::hasVariations( $item['post_id'] ) ) {
  256. $variations = ProductWrapper::getVariations( $item['post_id'] );
  257. $price_min = 1000000; // one million should be a high enough ceiling
  258. $price_max = 0;
  259. foreach ($variations as $var) {
  260. $price = $var['price'];
  261. if ( $price > $price_max ) $price_max = $price;
  262. if ( $price < $price_min ) $price_min = $price;
  263. }
  264. // apply price modifiers
  265. $listingsModel = new ListingsModel();
  266. $profile_data = maybe_unserialize( $item['profile_data'] );
  267. $price_min = $listingsModel->applyProfilePrice( $price_min, $profile_data['details']['start_price'] );
  268. $price_max = $listingsModel->applyProfilePrice( $price_max, $profile_data['details']['start_price'] );
  269. // use lowest price for flattened variations
  270. $profile_data = maybe_unserialize( $item['profile_data'] );
  271. if ( isset( $profile_data['details']['variations_mode'] ) && ( $profile_data['details']['variations_mode'] == 'flat' ) ) {
  272. return $this->number_format( $price_min, 2 );
  273. }
  274. if ( $price_min == $price_max ) {
  275. return $this->number_format( $price_min, 2 );
  276. } else {
  277. return $this->number_format( $price_min, 2 ) . ' - ' . $this->number_format( $price_max, 2 );
  278. }
  279. }
  280. return $this->number_format( $item['price'], 2 );
  281. }
  282. function column_end_date($item) {
  283. $profile_data = maybe_unserialize( $item['profile_data'] );
  284. if ( $item['date_finished'] ) {
  285. $date = $item['date_finished'];
  286. $value = mysql2date( get_option('date_format'), $date );
  287. return '<span style="color:darkgreen">'.$value.'</span>';
  288. } elseif ( ( is_array($profile_data['details']) ) && ( 'GTC' == $profile_data['details']['listing_duration'] ) ) {
  289. $value = 'GTC';
  290. return '<span style="color:silver">'.$value.'</span>';
  291. } else {
  292. $date = $item['end_date'];
  293. $value = mysql2date( get_option('date_format'), $date );
  294. return '<span>'.$value.'</span>';
  295. }
  296. }
  297. function column_status($item){
  298. switch( $item['status'] ){
  299. case 'prepared':
  300. $color = 'orange';
  301. $value = __('prepared','wplister');
  302. break;
  303. case 'verified':
  304. $color = '#21759B';
  305. $value = __('verified','wplister');
  306. break;
  307. case 'published':
  308. $color = 'darkgreen';
  309. $value = __('published','wplister');
  310. break;
  311. case 'sold':
  312. $color = 'black';
  313. $value = __('sold','wplister');
  314. break;
  315. case 'ended':
  316. $color = '#777';
  317. $value = __('ended','wplister');
  318. break;
  319. case 'imported':
  320. $color = 'orange';
  321. $value = __('imported','wplister');
  322. break;
  323. case 'selected':
  324. $color = 'orange';
  325. $value = __('selected','wplister');
  326. break;
  327. case 'changed':
  328. $color = 'purple';
  329. $value = __('changed','wplister');
  330. break;
  331. default:
  332. $color = 'black';
  333. $value = $item['status'];
  334. }
  335. //Return the title contents
  336. return sprintf('<mark style="background-color:%1$s">%2$s</mark>',
  337. /*$1%s*/ $color,
  338. /*$2%s*/ $value
  339. );
  340. }
  341. function column_profile($item){
  342. $profile_name = @$this->profiles[ $item['profile_id'] ];
  343. return sprintf(
  344. '<a href="admin.php?page=wplister-profiles&action=edit&profile=%1$s&return_to=listings" title="%2$s">%3$s</a>',
  345. /*$1%s*/ $item['profile_id'],
  346. /*$2%s*/ __('Edit','wplister'),
  347. /*$3%s*/ $profile_name
  348. );
  349. }
  350. function column_template($item){
  351. $template_id = basename( $item['template'] );
  352. $template_name = TemplatesModel::getNameFromCache( $template_id );
  353. return sprintf(
  354. '<a href="admin.php?page=wplister-templates&action=edit&template=%1$s&return_to=listings" title="%2$s">%3$s</a>',
  355. /*$1%s*/ $template_id,
  356. /*$2%s*/ __('Edit','wplister'),
  357. /*$3%s*/ $template_name
  358. );
  359. }
  360. /** ************************************************************************
  361. * REQUIRED if displaying checkboxes or using bulk actions! The 'cb' column
  362. * is given special treatment when columns are processed. It ALWAYS needs to
  363. * have it's own method.
  364. *
  365. * @see WP_List_Table::::single_row_columns()
  366. * @param array $item A singular item (one full row's worth of data)
  367. * @return string Text to be placed inside the column <td> (profile title only)
  368. **************************************************************************/
  369. function column_cb($item){
  370. return sprintf(
  371. '<input type="checkbox" name="%1$s[]" value="%2$s" />',
  372. /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("listing")
  373. /*$2%s*/ $item['id'] //The value of the checkbox should be the record's id
  374. );
  375. }
  376. /** ************************************************************************
  377. * REQUIRED! This method dictates the table's columns and titles. This should
  378. * return an array where the key is the column slug (and class) and the value
  379. * is the column's title text. If you need a checkbox for bulk actions, refer
  380. * to the $columns array below.
  381. *
  382. * The 'cb' column is treated differently than the rest. If including a checkbox
  383. * column in your table you must create a column_cb() method. If you don't need
  384. * bulk actions or checkboxes, simply leave the 'cb' entry out of your array.
  385. *
  386. * @see WP_List_Table::::single_row_columns()
  387. * @return array An associative array containing column information: 'slugs'=>'Visible Titles'
  388. **************************************************************************/
  389. function get_columns(){
  390. $columns = array(
  391. 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
  392. 'ebay_id' => __('eBay ID','wplister'),
  393. 'auction_title' => __('Title','wplister'),
  394. 'quantity' => __('Quantity','wplister'),
  395. 'quantity_sold' => __('Sold','wplister'),
  396. 'price' => __('Price','wplister'),
  397. 'fees' => __('Fees','wplister'),
  398. 'date_published' => __('Created at','wplister'),
  399. 'end_date' => __('Ends at','wplister'),
  400. 'profile' => __('Profile','wplister'),
  401. 'template' => __('Template','wplister'),
  402. 'status' => __('Status','wplister')
  403. );
  404. return $columns;
  405. }
  406. /** ************************************************************************
  407. * Optional. If you want one or more columns to be sortable (ASC/DESC toggle),
  408. * you will need to register it here. This should return an array where the
  409. * key is the column that needs to be sortable, and the value is db column to
  410. * sort by. Often, the key and value will be the same, but this is not always
  411. * the case (as the value is a column name from the database, not the list table).
  412. *
  413. * @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool)
  414. **************************************************************************/
  415. function get_sortable_columns() {
  416. $sortable_columns = array(
  417. 'date_published' => array('date_published',false), //true means its already sorted
  418. 'end_date' => array('end_date',false),
  419. 'auction_title' => array('auction_title',false),
  420. 'status' => array('status',false)
  421. );
  422. return $sortable_columns;
  423. }
  424. /** ************************************************************************
  425. * Optional. If you need to include bulk actions in your list table, this is
  426. * the place to define them. Bulk actions are an associative array in the format
  427. * 'slug'=>'Visible Title'
  428. *
  429. * Also note that list tables are not automatically wrapped in <form> elements,
  430. * so you will need to create those manually in order for bulk actions to function.
  431. *
  432. * @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles'
  433. **************************************************************************/
  434. function get_bulk_actions() {
  435. $actions = array(
  436. 'verify' => __('Verify with eBay','wplister'),
  437. 'publish2e' => __('Publish to eBay','wplister'),
  438. 'update' => __('Update details from eBay','wplister'),
  439. 'reselect' => __('Select another profile','wplister'),
  440. 'reapply' => __('Re-apply profile','wplister'),
  441. 'revise' => __('Revise items','wplister'),
  442. 'end_item' => __('End listings','wplister'),
  443. 'relist' => __('Re-list ended items','wplister'),
  444. 'delete' => __('Delete listings','wplister')
  445. );
  446. return $actions;
  447. }
  448. /** ************************************************************************
  449. * Optional. You can handle your bulk actions anywhere or anyhow you prefer.
  450. * For this example package, we will handle it in the class to keep things
  451. * clean and organized.
  452. *
  453. * @see $this->prepare_items()
  454. **************************************************************************/
  455. function process_bulk_action() {
  456. global $wbdb;
  457. //Detect when a bulk action is being triggered...
  458. if( 'delete'===$this->current_action() ) {
  459. #wp_die('Items deleted (or they would be if we had items to delete)!');
  460. #$wpdb->query("DELETE FROM {$wpdb->prefix}ebay_auctions WHERE id = ''",)
  461. }
  462. if( 'verify'===$this->current_action() ) {
  463. #echo "<br>verify handler<br>";
  464. }
  465. }
  466. // status filter links
  467. // http://wordpress.stackexchange.com/questions/56883/how-do-i-create-links-at-the-top-of-wp-list-table
  468. function get_views(){
  469. $views = array();
  470. $current = ( !empty($_REQUEST['listing_status']) ? $_REQUEST['listing_status'] : 'all');
  471. // get listing status summary
  472. $lm = new ListingsModel();
  473. $summary = $lm->getStatusSummary();
  474. // All link
  475. $class = ($current == 'all' ? ' class="current"' :'');
  476. $all_url = remove_query_arg('listing_status');
  477. $views['all'] = "<a href='{$all_url }' {$class} >".__('All','wplister')."</a>";
  478. $views['all'] .= '<span class="count">('.$this->total_items.')</span>';
  479. // prepared link
  480. $prepared_url = add_query_arg('listing_status','prepared');
  481. $class = ($current == 'prepared' ? ' class="current"' :'');
  482. $views['prepared'] = "<a href='{$prepared_url}' {$class} >".__('Prepared','wplister')."</a>";
  483. if ( isset($summary->prepared) ) $views['prepared'] .= '<span class="count">('.$summary->prepared.')</span>';
  484. // verified link
  485. $verified_url = add_query_arg('listing_status','verified');
  486. $class = ($current == 'verified' ? ' class="current"' :'');
  487. $views['verified'] = "<a href='{$verified_url}' {$class} >".__('Verified','wplister')."</a>";
  488. if ( isset($summary->verified) ) $views['verified'] .= '<span class="count">('.$summary->verified.')</span>';
  489. // published link
  490. $published_url = add_query_arg('listing_status','published');
  491. $class = ($current == 'published' ? ' class="current"' :'');
  492. $views['published'] = "<a href='{$published_url}' {$class} >".__('Published','wplister')."</a>";
  493. if ( isset($summary->published) ) $views['published'] .= '<span class="count">('.$summary->published.')</span>';
  494. // changed link
  495. $changed_url = add_query_arg('listing_status','changed');
  496. $class = ($current == 'changed' ? ' class="current"' :'');
  497. $views['changed'] = "<a href='{$changed_url}' {$class} >".__('Changed','wplister')."</a>";
  498. if ( isset($summary->changed) ) $views['changed'] .= '<span class="count">('.$summary->changed.')</span>';
  499. // ended link
  500. $ended_url = add_query_arg('listing_status','ended');
  501. $class = ($current == 'ended' ? ' class="current"' :'');
  502. $views['ended'] = "<a href='{$ended_url}' {$class} >".__('Ended','wplister')."</a>";
  503. if ( isset($summary->ended) ) $views['ended'] .= '<span class="count">('.$summary->ended.')</span>';
  504. return $views;
  505. }
  506. /** ************************************************************************
  507. * REQUIRED! This is where you prepare your data for display. This method will
  508. * usually be used to query the database, sort and filter the data, and generally
  509. * get it ready to be displayed. At a minimum, we should set $this->items and
  510. * $this->set_pagination_args(), although the following properties and methods
  511. * are frequently interacted with here...
  512. *
  513. * @uses $this->_column_headers
  514. * @uses $this->items
  515. * @uses $this->get_columns()
  516. * @uses $this->get_sortable_columns()
  517. * @uses $this->get_pagenum()
  518. * @uses $this->set_pagination_args()
  519. **************************************************************************/
  520. function prepare_items( $items = false ) {
  521. // process bulk actions
  522. $this->process_bulk_action();
  523. // get pagination state
  524. $current_page = $this->get_pagenum();
  525. $per_page = $this->get_items_per_page('listings_per_page', 20);
  526. // define columns
  527. $this->_column_headers = $this->get_column_info();
  528. // fetch listings from model - if no parameter passed
  529. if ( ! $items ) {
  530. $listingsModel = new ListingsModel();
  531. $this->items = $listingsModel->getPageItems( $current_page, $per_page );
  532. $this->total_items = $listingsModel->total_items;
  533. } else {
  534. $this->items = $items;
  535. $this->total_items = count($items);
  536. }
  537. // register our pagination options & calculations.
  538. $this->set_pagination_args( array(
  539. 'total_items' => $this->total_items,
  540. 'per_page' => $per_page,
  541. 'total_pages' => ceil($this->total_items/$per_page)
  542. ) );
  543. }
  544. // small helper to make sure $price is not a string
  545. function number_format( $price, $decimals = 2 ) {
  546. return number_format_i18n( floatval($price), $decimals );
  547. }
  548. }