Completed
Push — master ( 154491...c4a929 )
by Justin
12:26 queued 05:28
created

WPSC_Table   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 59
rs 10
wmc 13
lcom 1
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A print_column_headers() 0 6 2
A before_table() 0 3 1
A after_table() 0 3 1
A column_default() 0 3 1
A get_table_classes() 0 3 1
A display() 0 5 1
B display_rows() 0 22 5
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
}