WPDK  1.5.0
WordPress Development Kit
 All Data Structures Files Functions Variables Pages
wpdk-viewcontroller.php
Go to the documentation of this file.
1 <?php
2 
24 
32  public $__version = '0.9.22';
33 
41  public $id = '';
42 
50  public $title = '';
51 
59  public $view;
60 
68  public $viewHead;
69 
80  public function __construct( $id, $title )
81  {
82  $this->id = sanitize_title( $id );
83  $this->title = $title;
84  $this->view = new WPDKView( $id . '-view-root', array( 'wrap' ) );
85  $this->viewHead = new WPDKHeaderView( $id . '-header-view', $this->title );
86 
87  $this->view->addSubview( $this->viewHead );
88  }
89 
101  public static function initWithView( $id, $title, $view )
102  {
103  if ( !is_object( $view ) || !is_a( $view, 'WPDKView' ) ) {
104  return false;
105  }
106  else {
107  $instance = new WPDKViewController( $id, $title );
108  $instance->view->addSubview( $view );
109  }
110  return $instance;
111  }
112 
120  public function admin_head()
121  {
122  // To override
123  }
124 
133  public function _admin_head()
134  {
135  // To override by WPDK class
136  }
137 
144  public static function didHeadLoad()
145  {
146  // To override
147  }
148 
156  public function load()
157  {
158  // To override
159  }
160 
167  public static function willLoad()
168  {
169  // To override
170  }
171 
179  public function html()
180  {
182  $this->display();
183  return WPDKHTML::endCompress();
184  }
185 
191  public function display()
192  {
193  do_action( $this->id . '_will_view_appear', $this );
194 
195  // @deprecated
196  do_action( 'wpdk_view_controller_will_view_appear', $this->view, $this );
197 
198  $this->view->display();
199 
200  // @deprecated
201  do_action( 'wpdk_view_controller_did_view_appear', $this->view, $this );
202 
203  do_action( $this->id . '_did_view_appear', $this );
204  }
205 }
206 
217 class WPDKHeaderView extends WPDKView {
218 
226  public $title;
227 
238  public function __construct( $id, $title = '' )
239  {
240  parent::__construct( $id, 'clearfix wpdk-header-view' );
241 
242  // WPDKHeaderView property
243  $this->title = $title;
244  }
245 
251  public function draw()
252  {
253  ?>
254  <div data-type="wpdk-header-view" id="<?php echo $this->id ?>" class="wpdk-vc-header-icon"></div>
255  <h2><?php echo $this->title ?>
256  <?php
257 
258  // @todo Add action docs
259  do_action( 'wpdk_header_view_' . $this->id . '_title_did_appear', $this );
260 
261  // @deprecated
262  do_action( 'wpdk_header_view_title_did_appear', $this );
263  ?></h2>
264  <?php
265  do_action( 'wpdk_header_view_' . $this->id . '_after_title', $this );
266 
267  // @deprecated
268  do_action( 'wpdk_header_view_after_title', $this );
269  ?>
270  <?php
271  parent::draw();
272  }
273 
274 }