1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class WPSC_Table { |
4
|
|
|
public $columns = array(); |
5
|
|
|
public $items = array(); |
6
|
|
|
|
7
|
|
|
public function __construct() { |
8
|
|
|
} |
9
|
|
|
|
10
|
|
|
public function print_column_headers() { |
11
|
|
|
foreach ( $this->columns as $name => $title ) { |
12
|
|
|
$class = str_replace( '_', '-', $name ); |
13
|
|
|
echo "<div class='wpsc-cart-cell-header {$class}' data-title='" . esc_attr( $title ) . "'>" . esc_html( $title ) . "</div>"; |
14
|
|
|
} |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function display_rows() { |
18
|
|
|
|
19
|
|
|
foreach ( $this->items as $key => $item ) { |
20
|
|
|
$cart_class = isset( $item->product_id ) ? ' wpsc-cart-item-' . $item->product_id : ''; |
21
|
|
|
|
22
|
|
|
echo '<div class="wpsc-cart-item'. $cart_class .'">'; |
23
|
|
|
foreach ( $this->columns as $column => $title ) { |
24
|
|
|
$class = str_replace( '_', '-', $column ); |
25
|
|
|
echo '<div class="wpsc-cart-cell ' . $class . '" data-title="' . sprintf( _x( '%s: ', 'The cart column title', 'wp-e-commerce' ), $title ) . '">'; |
26
|
|
|
$callback = "column_{$column}"; |
27
|
|
|
|
28
|
|
|
if ( is_callable( array( $this, "column_{$column}") ) ) { |
29
|
|
|
$this->$callback( $item, $key ); |
30
|
|
|
} else { |
31
|
|
|
$this->column_default( $item, $key, $column ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
echo '</div>'; |
35
|
|
|
} |
36
|
|
|
echo '</div>'; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
protected function before_table() { |
41
|
|
|
// subclass should override this |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
protected function after_table() { |
45
|
|
|
// subclass should override this |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
protected function column_default( $item, $key, $column ) { |
49
|
|
|
// subclass should override this |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
protected function get_table_classes() { |
53
|
|
|
return array( 'wpsc-table' ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function display() { |
57
|
|
|
$this->before_table(); |
58
|
|
|
include( WPSC_TE_V2_SNIPPETS_PATH . '/table-display.php' ); |
59
|
|
|
$this->after_table(); |
60
|
|
|
} |
61
|
|
|
} |