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