XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ImageCreateAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_MODULE_PATH . '/legacy/class/AbstractEditAction.class.php';
17require_once XOOPS_MODULE_PATH . '/legacy/admin/forms/ImageAdminEditForm.class.php';
18
20{
21 public function _getId()
22 {
23 return 0;
24 }
25
26 public function &_getHandler()
27 {
28 $handler =& xoops_getmodulehandler('image', 'legacy');
29 return $handler;
30 }
31
32 public function _setupActionForm()
33 {
34 $this->mActionForm =new Legacy_ImageAdminCreateForm();
35 $this->mActionForm->prepare();
36 }
37
38 public function getDefaultView(&$controller, &$xoopsUser)
39 {
40 $flag = parent::getDefaultView($controller, $xoopsUser);
41
42 if (LEGACY_FRAME_VIEW_INPUT === $flag && $this->_enableCatchImgcat()) {
43 $this->mActionForm->set('imgcat_id', xoops_getrequest('imgcat_id'));
44 }
45
46 return $flag;
47 }
48
49 public function _enableCatchImgcat()
50 {
51 return true;
52 }
53
54 public function _doExecute()
55 {
56 $handler =& xoops_getmodulehandler('imagecategory', 'legacy');
57 $category =& $handler->get($this->mActionForm->get('imgcat_id'));
58
59 //
60 // [TODO]
61 // Should the following procedure be after parent::_doExecute()?
62 //
63 if ('file' === $category->get('imgcat_storetype')) {
64 $this->_storeFile();
65 } else {
66 $this->_storeDB();
67 }
68
69 return parent::_doExecute();
70 }
71
72 public function _storeFile()
73 {
74 if (null === $this->mActionForm->mFormFile) {
75 return null;
76 }
77
78 //
79 // If there is an old file, delete it
80 //
81 if (null !== $this->mActionForm->mOldFileName) {
82 @unlink(XOOPS_UPLOAD_PATH . '/' . $this->mActionForm->mOldFileName);
83
84 // Get a body name of the old file.
85 $match = [];
86 if (preg_match("/(.+)\.\w+$/", $this->mActionForm->mOldFileName, $match)) {
87 $this->mActionForm->mFormFile->setBodyName($match[1]);
88 }
89 }
90
91 $this->mObject->set('image_name', $this->mActionForm->mFormFile->getFileName());
92
93 return $this->mActionForm->mFormFile->saveAs(XOOPS_UPLOAD_PATH);
94 }
95
96 public function _storeDB()
97 {
98 }
99
100 public function executeViewInput(&$controller, &$xoopsUser, &$render)
101 {
102 $this->mObject->loadImagecategory();
103
104 $render->setTemplateName('image_edit.html');
105 $render->setAttribute('actionForm', $this->mActionForm);
106 $render->setAttribute('object', $this->mObject);
107
108 $handler =& xoops_getmodulehandler('imagecategory', 'legacy');
109 $categoryArr =& $handler->getObjects();
110 $render->setAttribute('categoryArr', $categoryArr);
111 }
112
113 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
114 {
115 $controller->executeForward('./index.php?action=ImageList&imgcat_id=' . $this->mActionForm->get('imgcat_id'));
116 }
117
118 public function executeViewError(&$controller, &$xoopsUser, &$render)
119 {
120 $controller->executeRedirect('./index.php?action=ImagecategoryList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
121 }
122
123 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
124 {
125 $controller->executeForward('./index.php?action=ImagecategoryList');
126 }
127}