ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

PluginSettingsDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 class PluginSettingsDAO extends DAO {
19  function &_getCache($conferenceId, $schedConfId, $pluginName) {
20  static $settingCache;
21  if (!isset($settingCache)) {
22  $settingCache = array();
23  }
24  if (!isset($settingCache[$conferenceId])) {
25  $settingCache[$conferenceId] = array();
26  }
27  if (!isset($settingCache[$conferenceId][$schedConfId])) {
28  $settingCache[$conferenceId][$schedConfId] = array();
29  }
30  if (!isset($settingCache[$conferenceId][$schedConfId][$pluginName])) {
31  $cacheManager =& CacheManager::getManager();
32  $settingCache[$conferenceId][$schedConfId][$pluginName] = $cacheManager->getCache(
33  'pluginSettings-' . ((int) $conferenceId) . '-' . ((int) $schedConfId), $pluginName,
34  array($this, '_cacheMiss')
35  );
36  }
37  return $settingCache[$conferenceId][$schedConfId][$pluginName];
38  }
39 
48  function getSetting($conferenceId, $schedConfId, $pluginName, $name) {
49  $cache =& $this->_getCache($conferenceId, $schedConfId, $pluginName);
50  return $cache->get($name);
51  }
52 
53  function _cacheMiss(&$cache, $id) {
54  $contextParts = explode('-', $cache->getContext());
55  $schedConfId = array_pop($contextParts);
56  $conferenceId = array_pop($contextParts);
57  $settings =& $this->getPluginSettings($conferenceId, $schedConfId, $cache->getCacheId());
58  if (!isset($settings[$id])) {
59  // Make sure that even null values are cached
60  $cache->setCache($id, null);
61  return null;
62  }
63  return $settings[$id];
64  }
65 
73  function &getPluginSettings($conferenceId, $schedConfId, $pluginName) {
74  $pluginSettings[$pluginName] = array();
75 
76  $result =& $this->retrieve(
77  'SELECT setting_name, setting_value, setting_type FROM plugin_settings WHERE plugin_name = ? AND conference_id = ? AND sched_conf_id = ?', array($pluginName, $conferenceId, $schedConfId)
78  );
79 
80  if ($result->RecordCount() == 0) {
81  $returner = null;
82  $result->Close();
83  return $returner;
84 
85  } else {
86  while (!$result->EOF) {
87  $row =& $result->getRowAssoc(false);
88  $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
89  $pluginSettings[$pluginName][$row['setting_name']] = $value;
90  $result->MoveNext();
91  }
92  $result->close();
93  unset($result);
94 
95  $cache =& $this->_getCache($conferenceId, $schedConfId, $pluginName);
96  $cache->setEntireCache($pluginSettings[$pluginName]);
97 
98  return $pluginSettings[$pluginName];
99  }
100  }
101 
111  function updateSetting($conferenceId, $schedConfId, $pluginName, $name, $value, $type = null) {
112  $cache =& $this->_getCache($conferenceId, $schedConfId, $pluginName);
113  $cache->setCache($name, $value);
114 
115  $result = $this->retrieve(
116  'SELECT COUNT(*) FROM plugin_settings WHERE plugin_name = ? AND setting_name = ? AND conference_id = ? AND sched_conf_id = ?',
117  array($pluginName, $name, $conferenceId, $schedConfId)
118  );
119 
120  $value = $this->convertToDB($value, $type);
121  if ($result->fields[0] == 0) {
122  $returner = $this->update(
123  'INSERT INTO plugin_settings
124  (plugin_name, conference_id, sched_conf_id, setting_name, setting_value, setting_type)
125  VALUES
126  (?, ?, ?, ?, ?, ?)',
127  array($pluginName, $conferenceId, $schedConfId, $name, $value, $type)
128  );
129  } else {
130  $returner = $this->update(
131  'UPDATE plugin_settings SET
132  setting_value = ?,
133  setting_type = ?
134  WHERE plugin_name = ? AND setting_name = ? AND conference_id = ? AND sched_conf_id = ?',
135  array($value, $type, $pluginName, $name, $conferenceId, $schedConfId)
136  );
137  }
138 
139  $result->Close();
140  unset($result);
141 
142  return $returner;
143  }
144 
153  function deleteSetting($conferenceId, $schedConfId, $pluginName, $name) {
154  $cache =& $this->_getCache($conferenceId, $schedConfId, $pluginName);
155  $cache->setCache($name, null);
156 
157  return $this->update(
158  'DELETE FROM plugin_settings WHERE plugin_name = ? AND setting_name = ? AND conference_id = ? AND sched_conf_id = ?',
159  array($pluginName, $name, $conferenceId, $schedConfId)
160  );
161  }
162 
167  function deleteSettingsByPlugin($pluginName, $conferenceId = null, $schedConfId = null) {
168  if ( $conferenceId && $schedConfId) {
169  $cache =& $this->_getCache($conferenceId, $schedConfId, $pluginName);
170  $cache->flush();
171 
172  return $this->update(
173  'DELETE FROM plugin_settings WHERE plugin_name = ? AND conference_id = ? AND sched_conf_id = ?',
174  array($pluginName, $conferenceId, $schedConfId)
175  );
176  } else {
177  $cacheManager =& CacheManager::getManager();
178  // NB: this actually deletes all plugins' settings cache
179  $cacheManager->flush('pluginSettings');
180 
181  $params = array($pluginName);
182  if ($conferenceId) $params[] = $conferenceId;
183 
184  return $this->update(
185  'DELETE FROM plugin_settings WHERE plugin_name = ?' . (($conferenceId)?' AND conference_id = ?':''),
186  $params
187  );
188  }
189  }
190 
195  function deleteSettingsByConferenceId($conferenceId) {
196  return $this->update(
197  'DELETE FROM plugin_settings WHERE conference_id = ?', $conferenceId
198  );
199  }
200 
207  function _performReplacement($rawInput, $paramArray = array()) {
208  $value = preg_replace_callback('{{translate key="([^"]+)"}}', '_installer_plugin_regexp_callback', $rawInput);
209  foreach ($paramArray as $pKey => $pValue) {
210  $value = str_replace('{$' . $pKey . '}', $pValue, $value);
211  }
212  return $value;
213  }
214 
221  function &_buildObject (&$node, $paramArray = array()) {
222  $value = array();
223  foreach ($node->getChildren() as $element) {
224  $key = $element->getAttribute('key');
225  $childArray =& $element->getChildByName('array');
226  if (isset($childArray)) {
227  $content = $this->_buildObject($childArray, $paramArray);
228  } else {
229  $content = $this->_performReplacement($element->getValue(), $paramArray);
230  }
231  if (!empty($key)) {
232  $key = $this->_performReplacement($key, $paramArray);
233  $value[$key] = $content;
234  } else $value[] = $content;
235  }
236  return $value;
237  }
238 
247  function installSettings($conferenceId, $schedConfId, $pluginName, $filename, $paramArray = array()) {
248  $xmlParser = new XMLParser();
249  $tree = $xmlParser->parse($filename);
250 
251  if (!$tree) {
252  $xmlParser->destroy();
253  return false;
254  }
255 
256  foreach ($tree->getChildren() as $setting) {
257  $nameNode =& $setting->getChildByName('name');
258  $valueNode =& $setting->getChildByName('value');
259 
260  if (isset($nameNode) && isset($valueNode)) {
261  $type = $setting->getAttribute('type');
262  $name =& $nameNode->getValue();
263 
264  if ($type == 'object') {
265  $arrayNode =& $valueNode->getChildByName('array');
266  $value = $this->_buildObject($arrayNode, $paramArray);
267  } else {
268  $value = $this->_performReplacement($valueNode->getValue(), $paramArray);
269  }
270 
271  // Replace translate calls with translated content
272  $this->updateSetting($conferenceId, $schedConfId, $pluginName, $name, $value, $type);
273  }
274  }
275 
276  $xmlParser->destroy();
277 
278  }
279 }
280 
285  return __($matches[1]);
286 }
287 
288 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
& _getCache($conferenceId, $schedConfId, $pluginName)
Operations for retrieving and modifying plugin settings.
deleteSettingsByConferenceId($conferenceId)
$content
installSettings($conferenceId, $schedConfId, $pluginName, $filename, $paramArray=array())
updateSetting($conferenceId, $schedConfId, $pluginName, $name, $value, $type=null)
__($key, $params=array(), $locale=null)
convertFromDB($value, $type)
Definition: DAO.inc.php:296
& getPluginSettings($conferenceId, $schedConfId, $pluginName)
Generic class for parsing an XML document into a data structure.
& _buildObject(&$node, $paramArray=array())
_installer_plugin_regexp_callback($matches)
_performReplacement($rawInput, $paramArray=array())
convertToDB($value, &$type)
Definition: DAO.inc.php:352
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
deleteSettingsByPlugin($pluginName, $conferenceId=null, $schedConfId=null)
getSetting($conferenceId, $schedConfId, $pluginName, $name)
deleteSetting($conferenceId, $schedConfId, $pluginName, $name)