1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: class User_AbstractEditAction extends User_Action
6: {
7: var $mObject = null;
8: var $mObjectHandler = null;
9: var $mActionForm = null;
10: var $mConfig;
11:
12: 13: 14:
15: function _getId()
16: {
17: }
18:
19: 20: 21:
22: function &_getHandler()
23: {
24: }
25:
26: 27: 28:
29: function _setupActionForm()
30: {
31: }
32:
33: 34: 35:
36: function _setupObject()
37: {
38: $id = $this->_getId();
39:
40: $this->mObjectHandler = $this->_getHandler();
41:
42: $this->mObject =& $this->mObjectHandler->get($id);
43:
44: if ($this->mObject == null && $this->isEnableCreate()) {
45: $this->mObject =& $this->mObjectHandler->create();
46: }
47: }
48:
49: 50: 51: 52: 53: 54: 55:
56: protected function _getPageAction()
57: {
58: return _EDIT;
59: }
60:
61: 62: 63:
64: function isEnableCreate()
65: {
66: return true;
67: }
68:
69: function prepare(&$controller, &$xoopsUser, $moduleConfig)
70: {
71: $this->mConfig = $moduleConfig;
72:
73: $this->_setupActionForm();
74: $this->_setupObject();
75: }
76:
77: function getDefaultView(&$controller, &$xoopsUser)
78: {
79: if ($this->mObject == null) {
80: return USER_FRAME_VIEW_ERROR;
81: }
82:
83: $this->mActionForm->load($this->mObject);
84:
85: return USER_FRAME_VIEW_INPUT;
86: }
87:
88: function execute(&$controller, &$xoopsUser)
89: {
90: if ($this->mObject == null) {
91: return USER_FRAME_VIEW_ERROR;
92: }
93:
94: if (xoops_getrequest('_form_control_cancel') != null) {
95: return USER_FRAME_VIEW_CANCEL;
96: }
97:
98: $this->mActionForm->load($this->mObject);
99:
100: $this->mActionForm->fetch();
101: $this->mActionForm->validate();
102:
103: if($this->mActionForm->hasError()) {
104: return USER_FRAME_VIEW_INPUT;
105: }
106:
107: $this->mActionForm->update($this->mObject);
108:
109: return $this->_doExecute($this->mObject) ? USER_FRAME_VIEW_SUCCESS
110: : USER_FRAME_VIEW_ERROR;
111: }
112:
113: 114: 115:
116: function _doExecute()
117: {
118: return $this->mObjectHandler->insert($this->mObject);
119: }
120: }
121:
122: ?>
123: