helpers
1 month ago
tables
1 month ago
aIProviderInterface.php
1 month ago
assets.php
1 month ago
baseObject.php
1 month ago
builderBlock.php
1 month ago
controller.php
1 month ago
date.php
1 month ago
db.php
1 month ago
dispatcher.php
1 month ago
errors.php
1 month ago
field.php
1 month ago
fieldAdapter.php
1 month ago
frame.php
1 month ago
helper.php
1 month ago
html.php
1 month ago
installer.php
1 month ago
installerDbUpdater.php
1 month ago
integration.php
1 month ago
modInstaller.php
1 month ago
model.php
1 month ago
module.php
1 month ago
req.php
1 month ago
response.php
1 month ago
table.php
1 month ago
uri.php
1 month ago
user.php
1 month ago
utils.php
1 month ago
validator.php
1 month ago
view.php
1 month ago
controller.php
145 lines
| 1 | <?php |
| 2 | if ( ! defined( 'ABSPATH' ) ) { |
| 3 | exit; |
| 4 | } |
| 5 | abstract class WaicController { |
| 6 | protected $_models = array(); |
| 7 | protected $_views = array(); |
| 8 | protected $_task = ''; |
| 9 | protected $_defaultView = ''; |
| 10 | protected $_code = ''; |
| 11 | public function __construct( $code ) { |
| 12 | $this->setCode($code); |
| 13 | $this->_defaultView = $this->getCode(); |
| 14 | } |
| 15 | public function init() { |
| 16 | /*load model and other preload data goes here*/ |
| 17 | } |
| 18 | protected function _onBeforeInit() { |
| 19 | } |
| 20 | protected function _onAfterInit() { |
| 21 | } |
| 22 | public function setCode( $code ) { |
| 23 | $this->_code = $code; |
| 24 | } |
| 25 | public function getCode() { |
| 26 | return $this->_code; |
| 27 | } |
| 28 | public function exec( $task = '' ) { |
| 29 | if (method_exists($this, $task)) { |
| 30 | $this->_task = $task; //For multicontrollers module version - who know, maybe that's will be?)) |
| 31 | return $this->$task(); |
| 32 | } |
| 33 | return null; |
| 34 | } |
| 35 | public function getView( $name = '' ) { |
| 36 | if (empty($name)) { |
| 37 | $name = $this->getCode(); |
| 38 | } |
| 39 | if (!isset($this->_views[$name])) { |
| 40 | $this->_views[$name] = $this->_createView($name); |
| 41 | } |
| 42 | return $this->_views[$name]; |
| 43 | } |
| 44 | public function getModel( $name = '' ) { |
| 45 | if (!$name) { |
| 46 | $name = $this->_code; |
| 47 | } |
| 48 | if (!isset($this->_models[$name])) { |
| 49 | $this->_models[$name] = $this->_createModel($name); |
| 50 | } |
| 51 | return $this->_models[$name]; |
| 52 | } |
| 53 | protected function _createModel( $name = '' ) { |
| 54 | if (empty($name)) { |
| 55 | $name = $this->getCode(); |
| 56 | } |
| 57 | $parentModule = WaicFrame::_()->getModule( $this->getCode() ); |
| 58 | $className = ''; |
| 59 | if (waicImport($parentModule->getModDir() . 'models' . WAIC_DS . $name . '.php')) { |
| 60 | $className = waicToeGetClassName($name . 'Model'); |
| 61 | } |
| 62 | |
| 63 | if ($className) { |
| 64 | $model = new $className(); |
| 65 | $model->setCode( $this->getCode() ); |
| 66 | return $model; |
| 67 | } |
| 68 | return null; |
| 69 | } |
| 70 | protected function _createView( $name = '' ) { |
| 71 | if (empty($name)) { |
| 72 | $name = $this->getCode(); |
| 73 | } |
| 74 | $parentModule = WaicFrame::_()->getModule( $this->getCode() ); |
| 75 | $className = ''; |
| 76 | |
| 77 | if (waicImport($parentModule->getModDir() . 'views' . WAIC_DS . $name . '.php')) { |
| 78 | $className = waicToeGetClassName($name . 'View'); |
| 79 | } |
| 80 | |
| 81 | if ($className) { |
| 82 | $view = new $className(); |
| 83 | $view->setCode( $this->getCode() ); |
| 84 | return $view; |
| 85 | } |
| 86 | return null; |
| 87 | } |
| 88 | public function display( $viewName = '' ) { |
| 89 | $view = $this->getView($viewName); |
| 90 | if (null === $view) { |
| 91 | $view = $this->getView(); //Get default view |
| 92 | } |
| 93 | if ($view) { |
| 94 | $view->display(); |
| 95 | } |
| 96 | } |
| 97 | /** |
| 98 | * Retrive permissions for controller methods if exist. |
| 99 | * If need - should be redefined in each controller where it required. |
| 100 | * |
| 101 | * @return array with permissions |
| 102 | * Can be used on of sub-array - WAIC_METHODS or WAIC_USERLEVELS |
| 103 | */ |
| 104 | public function getPermissions() { |
| 105 | return array(); |
| 106 | } |
| 107 | /** |
| 108 | * Methods that require nonce to be generated |
| 109 | * If need - should be redefined in each controller where it required. |
| 110 | * |
| 111 | * @return array |
| 112 | */ |
| 113 | public function getNotNoncedMethods() { |
| 114 | return array(); |
| 115 | } |
| 116 | /** |
| 117 | * Methods that do not require user rights control |
| 118 | */ |
| 119 | public function getFrontMethods() { |
| 120 | return array(); |
| 121 | } |
| 122 | public function getModule() { |
| 123 | return WaicFrame::_()->getModule( $this->getCode() ); |
| 124 | } |
| 125 | protected function _prepareTextLikeSearch( $val ) { |
| 126 | return ''; // Should be re-defined for each type |
| 127 | } |
| 128 | protected function _prepareModelBeforeListSelect( $model ) { |
| 129 | return $model->setSelectFields('*'); |
| 130 | } |
| 131 | |
| 132 | protected function _prepareListForTbl( $data ) { |
| 133 | return $data; |
| 134 | } |
| 135 | protected function _prepareSearchField( $searchField ) { |
| 136 | return $searchField; |
| 137 | } |
| 138 | protected function _prepareSearchString( $searchString ) { |
| 139 | return $searchString; |
| 140 | } |
| 141 | protected function _prepareSortOrder( $sortOrder ) { |
| 142 | return $sortOrder; |
| 143 | } |
| 144 | } |
| 145 |