XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AbstractEditAction.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7class User_AbstractEditAction extends User_Action
8{
9 public $mObject = null;
10 public $mObjectHandler = null;
11 public $mActionForm = null;
12 public $mConfig;
13
17 public function _getId()
18 { }
19
23 public function &_getHandler()
24 { }
25
29 public function _setupActionForm()
30 { }
31
35 public function _setupObject()
36 {
37 $id = $this->_getId();
38
39 $this->mObjectHandler = $this->_getHandler();
40
41 $this->mObject = &$this->mObjectHandler->get($id);
42
43 if (null == $this->mObject && $this->isEnableCreate()) {
44 $this->mObject = &$this->mObjectHandler->create();
45 }
46 }
47
55 protected function _getPageAction()
56 {
57 return _EDIT;
58 }
59
63 public function isEnableCreate()
64 {
65 return true;
66 }
67
68 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
69 {
70 $this->mConfig = $moduleConfig;
71
72 $this->_setupActionForm();
73 $this->_setupObject();
74 }
75
76 public function getDefaultView(&$controller, &$xoopsUser)
77 {
78 if (null == $this->mObject) {
79 return USER_FRAME_VIEW_ERROR;
80 }
81
82 $this->mActionForm->load($this->mObject);
83
84 return USER_FRAME_VIEW_INPUT;
85 }
86
87 public function execute(&$controller, &$xoopsUser)
88 {
89 if (null == $this->mObject) {
90 return USER_FRAME_VIEW_ERROR;
91 }
92
93 if (null != xoops_getrequest('_form_control_cancel')) {
94 return USER_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 USER_FRAME_VIEW_INPUT;
104 }
105
106 $this->mActionForm->update($this->mObject);
107
108 return $this->_doExecute() ? USER_FRAME_VIEW_SUCCESS
109 : USER_FRAME_VIEW_ERROR;
110 }
111
115 public function _doExecute()
116 {
117 return $this->mObjectHandler->insert($this->mObject);
118 }
119}