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