| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJTServicesDashboardPageService { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
private $config; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @var mixed |
| 22 |
*/ |
| 23 |
private $controller; |
| 24 |
|
| 25 |
/** |
| 26 |
* put your comment there... |
| 27 |
* |
| 28 |
* @var mixed |
| 29 |
*/ |
| 30 |
private $controllerFactory; |
| 31 |
|
| 32 |
/** |
| 33 |
* put your comment there... |
| 34 |
* |
| 35 |
* @var mixed |
| 36 |
*/ |
| 37 |
private $dashboardsConfig; |
| 38 |
|
| 39 |
/** |
| 40 |
* put your comment there... |
| 41 |
* |
| 42 |
* @var mixed |
| 43 |
*/ |
| 44 |
protected $menuFilterName = 'admin_menu'; |
| 45 |
|
| 46 |
/** |
| 47 |
* put your comment there... |
| 48 |
* |
| 49 |
* @var mixed |
| 50 |
*/ |
| 51 |
protected $menus; |
| 52 |
|
| 53 |
/** |
| 54 |
* put your comment there... |
| 55 |
* |
| 56 |
*/ |
| 57 |
public function __construct() {} |
| 58 |
|
| 59 |
/** |
| 60 |
* put your comment there... |
| 61 |
* |
| 62 |
*/ |
| 63 |
public function _adminMenuHook() { |
| 64 |
# Define menus |
| 65 |
$callback = array( $this, '_display' ); |
| 66 |
$this->defineMenus( $callback ); |
| 67 |
# Bind to menus load event and map it to for load callback |
| 68 |
foreach ( $this->menus as $hookSlug => $menu ) { |
| 69 |
# Bind load event |
| 70 |
add_action( "load-{$hookSlug}", array( & $this, '_pageLoad' ) ); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* put your comment there... |
| 76 |
* |
| 77 |
*/ |
| 78 |
public function _display() { |
| 79 |
|
| 80 |
# Save state |
| 81 |
$this->controller->saveState(); |
| 82 |
|
| 83 |
# Output |
| 84 |
echo $this->controller->getResponse(); |
| 85 |
|
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* put your comment there... |
| 90 |
* |
| 91 |
*/ |
| 92 |
public function _pageLoad() { |
| 93 |
# Get current hook slug |
| 94 |
$hookSlug = substr( current_filter(), strlen( 'load-' ) ) ; |
| 95 |
# Get menu associated to current request hook slug |
| 96 |
$menu =& $this->menus[ $hookSlug ]; |
| 97 |
$menuConfig =& $menu[ 'config' ]; |
| 98 |
# Get request route |
| 99 |
$router = new CJTServicesHTTPRequestRouter( $this->config[ 'requestParams' ] ); |
| 100 |
$router->getRoute( $menuConfig[ 'route' ] ); |
| 101 |
# Get controller |
| 102 |
$this->controller =& $this->getControllerFactory()->getController( array_merge( $this->config, $menuConfig ) ); |
| 103 |
# Dispatch call |
| 104 |
$this->controller->dispatch( $menuConfig[ 'route' ][ 'action' ] ); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* put your comment there... |
| 109 |
* |
| 110 |
* @param mixed $slug |
| 111 |
* @param mixed $hookSlug |
| 112 |
* @return CJTServicesDashboardPageService |
| 113 |
*/ |
| 114 |
protected function addMenu($slug, $hookSlug) { |
| 115 |
# Add menu and hold its configuration reference |
| 116 |
$this->menus[ $hookSlug ] = array( 'slug' => $slug, 'config' => & $this->dashboardsConfig[ $slug ] ); |
| 117 |
# Chain |
| 118 |
return $this; |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* put your comment there... |
| 123 |
* |
| 124 |
* @param mixed $dispatchController |
| 125 |
* @param mixed $config |
| 126 |
* @param mixed $dashboardConfigs |
| 127 |
* @return CJTServicesDashboardPageService |
| 128 |
*/ |
| 129 |
public function & attach(& $controllerFactory, $config, $dashboardConfigs) { |
| 130 |
# Set |
| 131 |
$this->controllerFactory =& $controllerFactory; |
| 132 |
$this->config =& $config; |
| 133 |
$this->dashboardsConfig =& $dashboardConfigs; |
| 134 |
# Chain |
| 135 |
return $this; |
| 136 |
} |
| 137 |
|
| 138 |
/** |
| 139 |
* put your comment there... |
| 140 |
* |
| 141 |
*/ |
| 142 |
protected abstract function defineMenus(& $callback); |
| 143 |
|
| 144 |
/** |
| 145 |
* put your comment there... |
| 146 |
* |
| 147 |
*/ |
| 148 |
public function getDashboardsConfig() { |
| 149 |
return $this->dashboardsConfig; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* put your comment there... |
| 154 |
* |
| 155 |
*/ |
| 156 |
public function & getControllerFactory() { |
| 157 |
return $this->controllerFactory; |
| 158 |
} |
| 159 |
|
| 160 |
/** |
| 161 |
* put your comment there... |
| 162 |
* |
| 163 |
*/ |
| 164 |
public function & start() { |
| 165 |
# Define menus when admin menu hooks is fired |
| 166 |
add_action( $this->menuFilterName, array( $this, '_adminMenuHook' ) ); |
| 167 |
# Chain |
| 168 |
return $this; |
| 169 |
} |
| 170 |
|
| 171 |
} |