Completed
Push — master ( c6a753...e758eb )
by Mike
02:16
created

View::view()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 11
rs 9.4285
1
<?php
2
namespace testContent\Abstracts;
3
4
5
/**
6
 * Class to generate a view for the admin page.
7
 *
8
 * @abstract
9
 * @package    WordPress
10
 * @subpackage Test Content
11
 * @author     Old Town Media
12
 */
13
abstract class View{
14
15
	/**
16
	 * title
17
	 * Title of the tab.
18
	 *
19
	 * @var string
20
	 * @access protected
21
	 */
22
	protected $title;
23
24
	/**
25
	 * type
26
	 * Type of objects we'll be dealing with i.e.: post or term.
27
	 *
28
	 * @var string
29
	 * @access protected
30
	 */
31
	protected $type;
32
33
	/**
34
	 * priority
35
	 * SPriority to pass into the actions.
36
	 *
37
	 * @var int
38
	 * @access protected
39
	 */
40
	protected $priority;
41
42
	/**
43
	 * Registers our view with appropriate actions.
44
	 *
45
	 * @see tab, view
46
	 */
47
	public function register_view(){
48
49
		add_action( 'tc-admin-tabs', array( $this, 'tab' ), $this->priority );
50
		add_action( 'tc-admin-sections', array( $this, 'view' ), $this->priority );
51
52
	}
53
54
55
	/**
56
	 * Builf the HTML for our tab navigation item.
57
	 *
58
	 * Each view has a tab and tab navigation - this function compiles our
59
	 * navigation tab. Rarely extended.
60
	 */
61
	public function tab(){
62
		$html = "";
63
64
		$html .= "<a class='nav-tab' href='javascript:void(0)'>";
65
			$html .= $this->title;
66
		$html .= "</a>";
67
68
		echo $html;
69
70
	}
71
72
73
	/**
74
	 * Build the HTML for the actual tab content.
75
	 *
76
	 * Each view has a tab and tab navigation - this function compiles our
77
	 * tab content. Rarely extended
78
	 *
79
	 * @see actions_section, options_section
80
	 */
81
	public function view(){
82
		$html = '';
83
84
		$html .= "<section class='test-content-tab'>";
85
			$html .= $this->actions_section();
86
			$html .= $this->options_section();
87
		$html .= "</section>";
88
89
		echo $html;
90
91
	}
92
93
94
	/**
95
	 * Holder function to build the tab main content. Extend this with your content.
96
	 *
97
	 * @access protected
98
	 *
99
	 * @return string HTML content.
100
	 */
101
	protected function actions_section(){
102
		$html = '';
103
		return $html;
104
	}
105
106
107
	/**
108
	 * Starter for an options section for the view.
109
	 *
110
	 * Options are where you could add various options and triggers such as author,
111
	 * quantity, or any other customization of the created/deleted data.
112
	 *
113
	 * @access protected
114
	 *
115
	 * @param string $html Existing HTML content.
116
	 * @return string HTML section content.
117
	 */
118
	protected function options_section( $html = '' ){
119
		$html .= "<div class='test-data-cpt'>";
120
			$html .= "<h3>";
121
				$html .= "<span class='label'>".__( 'Quantity', 'otm-test-content' )."</span>";
122
				$html .= "<input type='number' value='0' class='quantity-adjustment' for='".$this->type."' placeholder='".__( '', 'otm-test-content' )."'> ";
123
			$html .= "</h3>";
124
		$html .= "</div>";
125
126
		return $html;
127
	}
128
129
130
	/**
131
	 * Builds action buttons for creating or deleting content.
132
	 *
133
	 * @access protected
134
	 *
135
	 * @param string $action Type of action to take - i.e.: create or delete.
136
	 * @param string $slug Slug ID of the object to create i.e.: page or category.
137
	 * @param string $text Text to display in the button.
138
	 * @return string HTML.
139
	 */
140
	protected function build_button( $action, $slug, $text ){
141
		$html = $dashicon = '';
142
143
		if ( $action == 'create' ){
144
			$dashicon = 'dashicons-plus';
145
		} elseif ( $action == 'delete' ){
146
			$dashicon = 'dashicons-trash';
147
		}
148
149
		$html .= "<a href='javascript:void(0);' ";
150
			$html .= " data-type='" . $this->type . "'";
151
			$html .= " data-slug='" . $slug . "'";
152
			$html .= " data-todo='" . $action . "'";
153
			$html .= " class='button-primary handle-test-data'";
154
		$html .= "/>";
155
			$html .= "<span class='dashicons " . $dashicon . "'></span>";
156
			$html .= $text;
157
		$html .= "</a>";
158
159
		return $html;
160
161
	}
162
163
}
164