XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ActionFrame.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7define('LEGACYRENDER_FRAME_PERFORM_SUCCESS', 1);
8define('LEGACYRENDER_FRAME_PERFORM_FAIL', 2);
9define('LEGACYRENDER_FRAME_INIT_SUCCESS', 3);
10
11define('LEGACYRENDER_FRAME_VIEW_NONE', 1);
12define('LEGACYRENDER_FRAME_VIEW_SUCCESS', 2);
13define('LEGACYRENDER_FRAME_VIEW_ERROR', 3);
14define('LEGACYRENDER_FRAME_VIEW_INDEX', 4);
15define('LEGACYRENDER_FRAME_VIEW_INPUT', 5);
16define('LEGACYRENDER_FRAME_VIEW_PREVIEW', 6);
17define('LEGACYRENDER_FRAME_VIEW_CANCEL', 7);
18
20{
21 public $mActionName = null;
22 public $mAction = null;
23 public $mAdminFlag = null;
24
28 public $mCreateAction = null;
29 public function __construct($admin)
30 {
31 $this->mAdminFlag = $admin;
32 $this->mCreateAction =new XCube_Delegate();
33 $this->mCreateAction->register('LegacyRender_ActionFrame.CreateAction');
34 $this->mCreateAction->add([&$this, '_createAction']);
35 }
36
37 public function setActionName($name)
38 {
39 $this->mActionName = $name;
40
41 //
42 // Temp FIXME!
43 //
44 $root =& XCube_Root::getSingleton();
45 $root->mContext->setAttribute('actionName', $name);
46 $root->mContext->mModule->setAttribute('actionName', $name);
47 }
48
49 public function _createAction(&$actionFrame)
50 {
51 if (is_object($actionFrame->mAction)) {
52 return;
53 }
54
55 //
56 // Create action object by mActionName
57 //
58 $className = 'LegacyRender_' . ucfirst($actionFrame->mActionName) . 'Action';
59 $fileName = ucfirst($actionFrame->mActionName) . 'Action';
60 if ($actionFrame->mAdminFlag) {
61 $fileName = XOOPS_MODULE_PATH . "/legacyRender/admin/actions/{$fileName}.class.php";
62 } else {
63 $fileName = XOOPS_MODULE_PATH . "/legacyRender/actions/{$fileName}.class.php";
64 }
65
66 if (!file_exists($fileName)) {
67 die();
68 }
69
70 require_once $fileName;
71
72 if (XC_CLASS_EXISTS($className)) {
73 $actionFrame->mAction =new $className($actionFrame->mAdminFlag);
74 }
75 }
76
77 public function execute(&$controller)
78 {
79 if (!preg_match("/^\w+$/", $this->mActionName)) {
80 die();
81 }
82
83 //
84 // Create action object by mActionName
85 //
86 $this->mCreateAction->call(new XCube_Ref($this));
87
88 if (!(is_object($this->mAction) && $this->mAction instanceof \LegacyRender_Action)) {
89 die(); //< TODO
90 }
91
92 $handler =& xoops_gethandler('config');
93 $moduleConfig =& $handler->getConfigsByDirname('legacyRender');
94
95 $this->mAction->prepare($controller, $controller->mRoot->mContext->mXoopsUser, $moduleConfig);
96
97 if (!$this->mAction->hasPermission($controller, $controller->mRoot->mContext->mXoopsUser)) {
98 if ($this->mAdminFlag) {
99 $controller->executeForward(XOOPS_URL . '/admin.php');
100 } else {
101 $controller->executeForward(XOOPS_URL);
102 }
103 }
104
105 if ('POST' == xoops_getenv('REQUEST_METHOD')) {
106 $viewStatus = $this->mAction->execute($controller, $controller->mRoot->mContext->mXoopsUser);
107 } else {
108 $viewStatus = $this->mAction->getDefaultView($controller, $controller->mRoot->mContext->mXoopsUser);
109 }
110
111 switch ($viewStatus) {
112 case LEGACYRENDER_FRAME_VIEW_SUCCESS:
113 $this->mAction->executeViewSuccess($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
114 break;
115
116 case LEGACYRENDER_FRAME_VIEW_ERROR:
117 $this->mAction->executeViewError($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
118 break;
119
120 case LEGACYRENDER_FRAME_VIEW_INDEX:
121 $this->mAction->executeViewIndex($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
122 break;
123
124 case LEGACYRENDER_FRAME_VIEW_INPUT:
125 $this->mAction->executeViewInput($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
126 break;
127
128 case LEGACYRENDER_FRAME_VIEW_PREVIEW:
129 $this->mAction->executeViewPreview($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
130 break;
131
132 case LEGACYRENDER_FRAME_VIEW_CANCEL:
133 $this->mAction->executeViewCancel($controller, $controller->mRoot->mContext->mXoopsUser, $controller->mRoot->mContext->mModule->getRenderTarget());
134 break;
135 }
136 }
137}
138
140{
144 public $_mAdminFlag = false;
145
146 public function __construct($adminFlag = false)
147 {
148 $this->_mAdminFlag = $adminFlag;
149 }
150
151 public function hasPermission(&$controller, &$xoopsUser)
152 {
153 return true;
154 }
155
156 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
157 {
158 }
159
160 public function getDefaultView(&$controller, &$xoopsUser)
161 {
162 return LEGACYRENDER_FRAME_VIEW_NONE;
163 }
164
165 public function execute(&$controller, &$xoopsUser)
166 {
167 return LEGACYRENDER_FRAME_VIEW_NONE;
168 }
169
170 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
171 {
172 }
173
174 public function executeViewError(&$controller, &$xoopsUser, &$render)
175 {
176 }
177
178 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
179 {
180 }
181
182 public function executeViewInput(&$controller, &$xoopsUser, &$render)
183 {
184 }
185
186 public function executeViewPreview(&$controller, &$xoopsUser, &$render)
187 {
188 }
189
190 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
191 {
192 }
193}
[Final] Used for the simple mechanism for common delegation in XCube.