1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: if (!defined('XOOPS_ROOT_PATH')) exit();
12:
13: class Legacy_AbstractEditAction extends Legacy_Action
14: {
15: var $mObject = null;
16: var $mObjectHandler = null;
17: var $mActionForm = null;
18:
19: function _getId()
20: {
21: }
22:
23: function &_getHandler()
24: {
25: }
26:
27: function _setupActionForm()
28: {
29: }
30:
31: function _setupObject()
32: {
33: $id = $this->_getId();
34:
35: $this->mObjectHandler =& $this->_getHandler();
36:
37: $this->mObject =& $this->mObjectHandler->get($id);
38:
39: if ($this->mObject == null && $this->isEnableCreate()) {
40: $this->mObject =& $this->mObjectHandler->create();
41: }
42: }
43:
44: function isEnableCreate()
45: {
46: return true;
47: }
48:
49: function prepare(&$controller, &$xoopsUser)
50: {
51: $this->_setupObject();
52: $this->_setupActionForm();
53: }
54:
55: function getDefaultView(&$controller, &$xoopsUser)
56: {
57: if ($this->mObject == null) {
58: return LEGACY_FRAME_VIEW_ERROR;
59: }
60:
61: $this->mActionForm->load($this->mObject);
62:
63: return LEGACY_FRAME_VIEW_INPUT;
64: }
65:
66: function execute(&$controller, &$xoopsUser)
67: {
68: if ($this->mObject == null) {
69: return LEGACY_FRAME_VIEW_ERROR;
70: }
71:
72: if (xoops_getrequest('_form_control_cancel') != null) {
73: return LEGACY_FRAME_VIEW_CANCEL;
74: }
75:
76: $this->mActionForm->load($this->mObject);
77:
78: $this->mActionForm->fetch();
79: $this->mActionForm->validate();
80:
81: if($this->mActionForm->hasError()) {
82: return LEGACY_FRAME_VIEW_INPUT;
83: }
84:
85: $this->mActionForm->update($this->mObject);
86:
87: return $this->_doExecute($this->mObject) ? LEGACY_FRAME_VIEW_SUCCESS
88: : LEGACY_FRAME_VIEW_ERROR;
89: }
90:
91: function _doExecute()
92: {
93: return $this->mObjectHandler->insert($this->mObject);
94: }
95: }
96:
97: ?>
98: