PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/src/applications/design/controller/DesignController.php

https://gitlab.com/wuhang2003/phpwind
PHP | 337 lines | 261 code | 37 blank | 39 comment | 46 complexity | cb7f113028aaa91d4eb8929c91cfa68b MD5 | raw file
  1. <?php
  2. Wind::import('LIB:base.PwBaseController');
  3. /**
  4. * the last known user to change this file in the repository <$LastChangedBy: gao.wanggao $>
  5. * @author $Author: gao.wanggao $ Foxsee@aliyun.com
  6. * @copyright ©2003-2103 phpwind.com
  7. * @license http://www.phpwind.com
  8. * @version $Id: DesignController.php 29033 2013-06-05 02:56:40Z gao.wanggao $
  9. * @package
  10. */
  11. class DesignController extends PwBaseController {
  12. public function beforeAction($handlerAdapter) {
  13. parent::beforeAction($handlerAdapter);
  14. }
  15. public function moduleAction() {
  16. $moduleId = (int)$this->getInput('moduleid', 'post');
  17. Wind::import('SRV:design.bo.PwDesignModuleBo');
  18. $bo = new PwDesignModuleBo($moduleId);
  19. $module = $bo->getModule();
  20. if ($module['isused']) $this->setTemplate('');
  21. $bo->setStdId();
  22. $key = Wekit::load('design.srv.display.PwDesignDisplay')->bindDataKey($moduleId);
  23. $data[$key] = $bo->getData(true, false);
  24. $this->setOutput($data, '__design_data');
  25. list($theme,)= $this->getForward()->getWindView()->getTheme();
  26. if (is_array($theme)) list($theme, $pack) = $theme;
  27. if (!$theme) $theme = 'default';
  28. WindFolder::rm(Wind::getRealDir('DATA:compile.template.'.$theme.'.design.segment.'), true);
  29. $this->setTemplate('TPL:design.segment.module');
  30. }
  31. public function getmodulepermissionsAction() {
  32. $other = array('html', 'searchbar', 'image');
  33. $tab = array();
  34. $moduleId = (int)$this->getInput('moduleid', 'post');
  35. $pageid = (int)$this->getInput('pageid', 'post');
  36. $module = $this->_getModuleDs()->getModule($moduleId);
  37. if(!$module || !$module['isused']) $this->showError("DESIGN:module.is.delete");
  38. Wekit::load('design.PwDesignPermissions');
  39. $permissions = $this->_getPermissionsService()->getPermissionsForModule($this->loginUser->uid, $moduleId, $pageid);
  40. if ($permissions <= PwDesignPermissions::NEED_CHECK) $this->showError("DESIGN:permissions.fail");
  41. switch ($permissions) {
  42. case '4':
  43. if ($module['module_type'] == PwDesignModule::TYPE_DRAG) {
  44. $tab = array('data','push','add','title','style','property','template','delete');
  45. } else {
  46. $tab = array('data','push','add','title','property','template','delete');
  47. }
  48. break;
  49. case '3':
  50. if ($module['module_type'] == PwDesignModule::TYPE_DRAG) {
  51. $tab = array('data','push','add','title','style','property','template');
  52. } else {
  53. $tab = array('data','push','add','title','property','template');
  54. }
  55. break;
  56. case '2':
  57. if (in_array($module['model_flag'], $other)) {
  58. $tab = array('property');
  59. } else {
  60. $tab = array('data','push','add');
  61. }
  62. break;
  63. default:
  64. $this->showError("DESIGN:permissions.fail");
  65. }
  66. //对config里的tab进行过滤
  67. Wind::import('SRV:design.bo.PwDesignModelBo');
  68. $bo = new PwDesignModelBo($module['model_flag']);
  69. $modelInfo = $bo->getModel();
  70. if (is_array($modelInfo['tab'])) {
  71. foreach ($tab AS $k=>$v) {
  72. if (in_array($v, $modelInfo['tab'])) $_tab[] = $tab[$k];
  73. }
  74. $tab = $_tab;
  75. }
  76. $this->setOutput($tab, 'data');
  77. $this->showMessage("operate.success");
  78. }
  79. public function dosavepageAction() {
  80. $_tmp1 = $_tmp2 = $isunique = false;
  81. $pageid = (int)$this->getInput('pageid', 'post');
  82. $uniqueid = (int)$this->getInput('uniqueid', 'post');
  83. $uri = $this->getInput('uri', 'post');
  84. $segments = (array)$this->getInput('segment', 'post');
  85. $type = $this->getInput('type', 'post');
  86. Wekit::load('design.PwDesignPermissions');
  87. $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid,$pageid);
  88. Wind::import('SRV:design.bo.PwDesignPageBo');
  89. $pageBo = new PwDesignPageBo($pageid);
  90. if ($pageBo->getLock()) $this->showError('DESIGN:page.edit.other.user');
  91. //兼容其它类型模块
  92. if ($permissions >= PwDesignPermissions::IS_PUSH ){
  93. $service = $this->_getPageSaveService();
  94. if ($type == 'isunique') $_tmp1 = true;
  95. foreach ($segments AS $segment) {
  96. if ($segment) $_tmp2 = true;
  97. }
  98. if ($_tmp1 && $_tmp2) $isunique = true;
  99. $resource = $service->getNewPageId($pageid, $uniqueid, $isunique);
  100. if ($resource instanceof PwError) $this->showError($resource->getError());
  101. $resource = $service->updateSegment($segments, $resource);
  102. if ($resource instanceof PwError) $this->showError($resource->getError());
  103. } else {
  104. Wind::import('SRV:design.dm.PwDesignPageDm');
  105. $ds = $this->_getPageDs();
  106. $dm = new PwDesignPageDm($pageid);
  107. $dm->setDesignLock(0, 0);
  108. $ds->updatePage($dm);
  109. }
  110. $this->_getDesignService()->clearCompile();
  111. $this->_getBakService()->doBak($pageid);
  112. //$this->setOutput(urldecode($uri), 'data');
  113. $this->showMessage("operate.success", urldecode($uri));
  114. }
  115. /**
  116. * 恢复上一次数据
  117. * Enter description here ...
  118. */
  119. public function dorestoreAction() {
  120. $pageid = (int)$this->getInput('pageid', 'post');
  121. $step = (int)$this->getInput('step', 'post');
  122. $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid,$pageid);
  123. if ($permissions < PwDesignPermissions::IS_DESIGN ) $this->showError("DESIGN:permissions.fail");
  124. Wind::import('SRV:design.bo.PwDesignPageBo');
  125. $pageBo = new PwDesignPageBo($pageid);
  126. if ($pageBo->getLock()) $this->showError('DESIGN:page.edit.other.user');
  127. $this->_getRestoreService()->doRestoreBak($pageid);
  128. $this->_getDesignService()->clearCompile();
  129. $this->showMessage("operate.success");
  130. }
  131. /**
  132. * 更新当前页数据
  133. * Enter description here ...
  134. */
  135. public function docacheAction() {
  136. $pageid = (int)$this->getInput('pageid', 'post');
  137. $pageInfo = $this->_getPageDs()->getPage($pageid);
  138. if (!$pageInfo) $this->showError("operate.fail");
  139. $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid,$pageid);
  140. if ($permissions < PwDesignPermissions::IS_PUSH ) $this->showError("DESIGN:permissions.fail");
  141. Wind::import('SRV:design.bo.PwDesignPageBo');
  142. $pageBo = new PwDesignPageBo($pageid);
  143. if ($pageBo->getLock()) $this->showError('DESIGN:page.edit.other.user');
  144. $list = $this->_getModuleDs()->getByPageid($pageid);
  145. Wind::import('SRV:design.srv.data.PwAutoData');
  146. foreach ($list AS $id=>$v) {
  147. $id = (int)$id;
  148. if ($id < 1) continue;
  149. $srv = new PwAutoData($id);
  150. $srv->addAutoData();
  151. }
  152. $this->_getDesignService()->clearCompile();
  153. $this->showMessage("operate.success");
  154. }
  155. /**
  156. * 清空当前页设计数据
  157. * Enter description here ...
  158. * @see ImportController->dorunAction
  159. */
  160. public function doclearAction() {
  161. $pageid = (int)$this->getInput('pageid', 'post');
  162. Wind::import('SRV:design.bo.PwDesignPageBo');
  163. $pageBo = new PwDesignPageBo($pageid);
  164. $pageInfo = $pageBo->getPage();
  165. if (!$pageInfo) $this->showError("operate.fail");
  166. $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid,$pageid);
  167. if ($permissions < PwDesignPermissions::IS_DESIGN ) $this->showError("DESIGN:permissions.fail");
  168. Wind::import('SRV:design.bo.PwDesignPageBo');
  169. $pageBo = new PwDesignPageBo($pageid);
  170. if ($pageBo->getLock()) $this->showError('DESIGN:page.edit.other.user');
  171. $ids = explode(',', $pageInfo['module_ids']);
  172. $names = explode(',', $pageInfo['module_names']);
  173. $moduleDs = $this->_getModuleDs();
  174. $bakDs = $this->_getBakDs();
  175. $dataDs = $this->_getDataDs();
  176. $pushDs = $this->_getPushDs();
  177. $imageSrv = Wekit::load('design.srv.PwDesignImage');
  178. // module
  179. $moduleDs->deleteByPageId($pageid);
  180. // data && push
  181. foreach ($ids AS $id) {
  182. $dataDs->deleteByModuleId($id);
  183. $pushDs->deleteByModuleId($id);
  184. $imageSrv->clearFolder($id);
  185. }
  186. //structure
  187. $ds = $this->_getStructureDs();
  188. foreach ($names AS $name) {
  189. $ds->deleteStruct($name);
  190. }
  191. //segment
  192. $this->_getSegmentDs()->deleteSegmentByPageid($pageid);
  193. //bak
  194. $bakDs->deleteByPageId($pageid);
  195. $tplPath = $pageBo->getTplPath();
  196. $this->_getDesignService()->clearTemplate($pageid, $tplPath);
  197. if ($pageInfo['page_type'] == PwDesignPage::PORTAL) {
  198. Wind::import('SRV:design.dm.PwDesignPortalDm');
  199. $dm = new PwDesignPortalDm($pageInfo['page_unique']);
  200. $dm->setTemplate($tplPath);
  201. $this->_getPortalDs()->updatePortal($dm);
  202. $srv = Wekit::load('design.srv.PwDesignService');
  203. $result = $srv->defaultTemplate($pageid, $tplPath);
  204. } else {
  205. $this->_getPageDs()->deletePage($pageid);
  206. }
  207. $this->_getDesignService()->clearCompile();
  208. $this->showMessage("operate.success");
  209. }
  210. /**
  211. * 被占用退出
  212. * Enter description here ...
  213. */
  214. public function exitAction() {
  215. $uri = $this->getInput('uri', 'post');
  216. $this->setOutput(urldecode($uri), 'data');
  217. $this->showMessage("operate.success");
  218. }
  219. public function doexitAction() {
  220. $pageid = (int)$this->getInput('pageid', 'post');
  221. $uri = $this->getInput('uri', 'post');
  222. $pageDs = $this->_getPageDs();
  223. $pageInfo = $pageDs->getPage($pageid);
  224. if (!$pageInfo) $this->showError("operate.fail");
  225. $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid,$pageid);
  226. if ($permissions < PwDesignPermissions::NEED_CHECK ) $this->showError("DESIGN:permissions.fail");
  227. Wind::import('SRV:design.bo.PwDesignPageBo');
  228. $pageBo = new PwDesignPageBo($pageid);
  229. if ($pageBo->getLock()) $this->showError('DESIGN:page.edit.other.user');
  230. $srv =$this->_getRestoreService();
  231. $srv->doRestoreSnap($pageid);
  232. //编辑模式解锁
  233. Wind::import('SRV:design.dm.PwDesignPageDm');
  234. $dm = new PwDesignPageDm($pageid);
  235. $dm->setDesignLock(0, 0);
  236. $this->_getPageDs()->updatePage($dm);
  237. $this->_getDesignService()->clearCompile();
  238. //$this->setOutput(urldecode($uri), 'data');
  239. $this->showMessage("operate.success", urldecode($uri));
  240. }
  241. /**
  242. * 设计模计轮循加锁
  243. * Enter description here ...
  244. */
  245. public function lockdesignAction() {
  246. $pageid = (int)$this->getInput('pageid', 'post');
  247. $pageInfo = $this->_getPageDs()->getPage($pageid);
  248. if (!$pageInfo) $this->showError("operate.fail");
  249. Wekit::load('design.PwDesignPermissions');
  250. $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid,$pageid);
  251. if ($permissions <= PwDesignPermissions::NEED_CHECK) $this->showError("DESIGN:permissions.fail");
  252. list($uid,$time) = explode('|', $pageInfo['design_lock']);
  253. if ($uid != $this->loginUser->uid) $this->showError("operate.fail");
  254. Wind::import('SRV:design.dm.PwDesignPageDm');
  255. $dm = new PwDesignPageDm($pageid);
  256. $dm->setDesignLock($this->loginUser->uid, Pw::getTime());
  257. $this->_getPageDs()->updatePage($dm);
  258. $this->showMessage("operate.success");
  259. }
  260. private function _getDesignService() {
  261. return Wekit::load('design.srv.PwDesignService');
  262. }
  263. private function _getRestoreService() {
  264. return Wekit::load('design.srv.PwRestoreService');
  265. }
  266. private function _getBakService() {
  267. return Wekit::load('design.srv.PwPageBakService');
  268. }
  269. private function _getPageSaveService() {
  270. return Wekit::load('design.srv.PwDesignPageSave');
  271. }
  272. private function _getPermissionsService() {
  273. return Wekit::load('design.srv.PwDesignPermissionsService');
  274. }
  275. private function _getStructureDs() {
  276. return Wekit::load('design.PwDesignStructure');
  277. }
  278. private function _getModuleDs() {
  279. return Wekit::load('design.PwDesignModule');
  280. }
  281. private function _getPageDs() {
  282. return Wekit::load('design.PwDesignPage');
  283. }
  284. private function _getBakDs() {
  285. return Wekit::load('design.PwDesignBak');
  286. }
  287. private function _getSegmentDs() {
  288. return Wekit::load('design.PwDesignSegment');
  289. }
  290. private function _getDataDs() {
  291. return Wekit::load('design.PwDesignData');
  292. }
  293. private function _getPushDs() {
  294. return Wekit::load('design.PwDesignPush');
  295. }
  296. private function _getPortalDs() {
  297. return Wekit::load('design.PwDesignPortal');
  298. }
  299. }
  300. ?>