XOOPS  2.6.0
config.php
Go to the documentation of this file.
1 <?php
24 
36 {
43  private $_cHandler;
44 
51  private $_oHandler;
52 
60  private $_cachedConfigs = array();
61 
65  public function __construct()
66  {
67  $this->_cHandler = Xoops::getInstance()->getHandlerConfigitem();
68  $this->_oHandler = Xoops::getInstance()->getHandlerConfigoption();
69  }
70 
78  public function createConfig()
79  {
80  $instance = $this->_cHandler->create();
81  return $instance;
82  }
83 
92  public function getConfig($id, $withoptions = false)
93  {
94  /* @var $config XoopsConfigItem */
95  $config = $this->_cHandler->get($id);
96  if ($withoptions == true) {
97  $config->setConfOptions($this->getConfigOptions(new Criteria('conf_id', $id)));
98  }
99  return $config;
100  }
101 
110  {
111  if (!$this->_cHandler->insert($config)) {
112  return false;
113  }
114  $options = $config->getConfOptions();
115  $count = count($options);
116  $conf_id = $config->getVar('conf_id');
117  for ($i = 0; $i < $count; ++$i) {
118  $options[$i]->setVar('conf_id', $conf_id);
119  if (!$this->_oHandler->insert($options[$i])) {
120  foreach ($options[$i]->getErrors() as $msg) {
121  $config->setErrors($msg);
122  }
123  }
124  }
125  if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
126  unset($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
127  }
128  return true;
129  }
130 
139  {
140  if (!$this->_cHandler->delete($config)) {
141  return false;
142  }
143  $options = $config->getConfOptions();
144  $count = count($options);
145  if ($count == 0) {
146  $options = $this->getConfigOptions(new Criteria('conf_id', $config->getVar('conf_id')));
147  $count = count($options);
148  }
149  if (is_array($options) && $count > 0) {
150  for ($i = 0; $i < $count; ++$i) {
151  $this->_oHandler->delete($options[$i]);
152  }
153  }
154  if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
155  unset($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
156  }
157  return true;
158  }
159 
168  public function getConfigs(CriteriaElement $criteria = null, $id_as_key = false)
169  {
170  $criteria2 = new CriteriaCompo();
171  if ($criteria) {
172  $criteria2->add($criteria);
173  if (!$criteria->getSort()) {
174  $criteria2->setSort('conf_order');
175  $criteria2->setOrder('ASC');
176  }
177  } else {
178  $criteria2->setSort('conf_order');
179  $criteria2->setOrder('ASC');
180  }
181  return $this->_cHandler->getObjects($criteria2, $id_as_key);
182  }
183 
191  public function getConfigCount(CriteriaElement $criteria = null)
192  {
193  return $this->_cHandler->getCount($criteria);
194  }
195 
203  public function getConfigsByModule($module = 0)
204  {
205  $ret = array();
206  $criteria = new Criteria('conf_modid', intval($module));
207  $configs = $this->getConfigs($criteria, true);
208  if (is_array($configs)) {
209  foreach (array_keys($configs) as $i) {
210  $ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
211  }
212  }
213  $_cachedConfigs[$module] = $ret;
214  return $_cachedConfigs[$module];
215  }
216 
227  public function getConfigsByCat($category, $module = 0)
228  {
229  static $_cachedConfigs;
230  if (!empty($_cachedConfigs[$module][$category])) {
231  return $_cachedConfigs[$module][$category];
232  } else {
233  $ret = array();
234  $criteria = new CriteriaCompo(new Criteria('conf_modid', intval($module)));
235  if (!empty($category)) {
236  $criteria->add(new Criteria('conf_catid', intval($category)));
237  }
238  $configs = $this->getConfigs($criteria, true);
239  if (is_array($configs)) {
240  foreach (array_keys($configs) as $i) {
241  $ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
242  }
243  }
244  $_cachedConfigs[$module][$category] = $ret;
245  return $_cachedConfigs[$module][$category];
246  }
247  }
248 
254  public function createConfigOption()
255  {
256  $inst = $this->_oHandler->create();
257  return $inst;
258  }
259 
267  public function getConfigOption($id)
268  {
269  $inst = $this->_oHandler->get($id);
270  return $inst;
271  }
272 
281  public function getConfigOptions(CriteriaElement $criteria = null, $id_as_key = false)
282  {
283  return $this->_oHandler->getObjects($criteria, $id_as_key);
284  }
285 
294  {
295  return $this->_oHandler->getCount($criteria);
296  }
297 
306  public function getConfigList($conf_modid, $conf_catid = 0)
307  {
308  if (!empty($this->_cachedConfigs[$conf_modid][$conf_catid])) {
309  return $this->_cachedConfigs[$conf_modid][$conf_catid];
310  } else {
311  $criteria = new CriteriaCompo(new Criteria('conf_modid', $conf_modid));
312  if (empty($conf_catid)) {
313  $criteria->add(new Criteria('conf_catid', $conf_catid));
314  }
315  $criteria->setSort('conf_order');
316  $criteria->setOrder('ASC');
317  $configs = $this->_cHandler->getObjects($criteria);
318  $confcount = count($configs);
319  $ret = array();
320  for ($i = 0; $i < $confcount; ++$i) {
321  $ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
322  }
323  $this->_cachedConfigs[$conf_modid][$conf_catid] = $ret;
324  return $ret;
325  }
326  }
327 }
getConfigs(CriteriaElement $criteria=null, $id_as_key=false)
Definition: config.php:168
$i
Definition: dialog.php:68
insertConfig(XoopsConfigItem $config)
Definition: config.php:109
static getInstance()
Definition: Xoops.php:160
$options['editor']
getConfigOption($id)
Definition: config.php:267
getVar($key, $format= 's')
$id
Definition: admin_menu.php:36
return $config
Definition: config.php:31
getConfigCount(CriteriaElement $criteria=null)
Definition: config.php:191
getConfig($id, $withoptions=false)
Definition: config.php:92
getConfigList($conf_modid, $conf_catid=0)
Definition: config.php:306
$module
Definition: main.php:52
$configs
Definition: config.php:27
$criteria2
getConfigsByModule($module=0)
Definition: config.php:203
$criteria
deleteConfig(XoopsConfigItem $config)
Definition: config.php:138
if(!is_object($module)||!$module->getVar('isactive')) $msg
Definition: groupperm.php:38
getConfigsByCat($category, $module=0)
Definition: config.php:227
getConfigOptionsCount(CriteriaElement $criteria=null)
Definition: config.php:293
getConfigOptions(CriteriaElement $criteria=null, $id_as_key=false)
Definition: config.php:281