XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ThemeListAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_MODULE_PATH . '/legacy/admin/forms/ThemeSelectForm.class.php';
17
18/***
19 * @internal
20 * This action shows the list of selectable themes to user.
21 *
22 * [Notice]
23 * XOOPS Cube Legacy can have many themes with different render-systems.
24 * The render-system should not control how to change the themes.
25 * Because this action can't list up themes of other render-systems.
26 * The action to change themes should be in Legacy. And, each render-system
27 * should send theme information through delegate-mechanism.
28 * Therefore, this class is a test for that. We may move this action from
29 * LegacyRender module. If you want to check the concept of this strategy, see
30 * ThemeSelect preload in Legacy module.
31 */
32class Legacy_ThemeListAction extends Legacy_Action
33{
34 public $mThemes = null;
35 public $mObjectHandler = null;
36 public $mActionForm = null;
37 public $mMainTheme = null;
38
39 public function prepare(&$controller, &$xoopsUser)
40 {
41 $this->_setupObject();
42 $this->_setupActionForm();
43
44 $handler =& xoops_gethandler('config');
45
46 $criteria =new CriteriaCompo();
47 $criteria->add(new Criteria('conf_name', 'theme_set'));
48 $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
49
50 $configs =& $handler->getConfigs($criteria);
51 $this->mMainTheme = $configs[0]->get('conf_value');
52 }
53
54 public function _setupObject()
55 {
56 $handler =& xoops_getmodulehandler('theme');
57 $this->mThemes =& $handler->getObjects();
58 }
59
60 public function _setupActionForm()
61 {
62 $this->mActionForm =new Legacy_ThemeSelectForm();
63 $this->mActionForm->prepare();
64 }
65
66 public function getDefaultView(&$controller, &$xoopsUser)
67 {
68 $configHandler =& xoops_gethandler('config');
69
70 $criteria =new CriteriaCompo();
71 $criteria->add(new Criteria('conf_name', 'theme_set_allowed'));
72 $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
73
74 $configs =& $configHandler->getConfigs($criteria);
75 $selectedThemeArr = unserialize($configs[0]->get('conf_value'));
76
77 $this->mActionForm->load($selectedThemeArr);
78
79 return LEGACY_FRAME_VIEW_INDEX;
80 }
81
82 public function execute(&$controller, &$xoopsUser)
83 {
84 $this->mActionForm->fetch();
85 $this->mActionForm->validate();
86
87 if ($this->mActionForm->hasError()) {
88 return $this->getDefaultView($controller, $xoopsUser);
89 }
90
91 //
92 // save selectable themes.
93 //
94 $configHandler =& xoops_gethandler('config');
95
96 $criteria =new CriteriaCompo();
97 $criteria->add(new Criteria('conf_name', 'theme_set_allowed'));
98 $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
99
100 $configs =& $configHandler->getConfigs($criteria);
101 $t_themeArr = $this->mActionForm->getSelectableTheme();
102 $configs[0]->set('conf_value', serialize($t_themeArr));
103 if (!$configHandler->insertConfig($configs[0])) {
104 die(); // FIXME:
105 }
106
107 //
108 // save selected theme.
109 //
110 $themeName = $this->mActionForm->getChooseTheme();
111
112 if (null !== $themeName) {
113 $criteria =new CriteriaCompo();
114 $criteria->add(new Criteria('conf_name', 'theme_set'));
115 $criteria->add(new Criteria('conf_catid', XOOPS_CONF));
116
117 $configs =& $configHandler->getConfigs($criteria);
118
119 $configs[0]->set('conf_value', $themeName);
120 if ($configHandler->insertConfig($configs[0])) {
121 $controller->mRoot->mContext->setThemeName($themeName);
122 $this->mMainTheme = $themeName;
123 }
124 }
125
126 XCube_DelegateUtils::call('Legacy.Event.ThemeSettingChanged', $this->mMainTheme, $t_themeArr);
127
128 return $this->getDefaultView($controller, $xoopsUser);
129 }
130
131 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
132 {
133 $render->setTemplateName('theme_list.html');
134 $render->setAttribute('themes', $this->mThemes);
135 $render->setAttribute('actionForm', $this->mActionForm);
136 $render->setAttribute('currentThemeName', $this->mMainTheme);
137 }
138}