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