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)  

ConferenceSettingsDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('db.SettingsDAO');
20  function &_getCache($conferenceId) {
21  static $settingCache;
22  if (!isset($settingCache)) {
23  $settingCache = array();
24  }
25  if (!isset($settingCache[$conferenceId])) {
26  $cacheManager =& CacheManager::getManager();
27  $settingCache[$conferenceId] = $cacheManager->getCache(
28  'conferenceSettings', $conferenceId,
29  array($this, '_cacheMiss')
30  );
31  }
32  return $settingCache[$conferenceId];
33  }
34 
42  function &getSetting($conferenceId, $name, $locale = null) {
43  $cache =& $this->_getCache($conferenceId);
44  $returner = $cache->get($name);
45  if ($locale !== null) {
46  if (!isset($returner[$locale]) || !is_array($returner)) {
47  unset($returner);
48  $returner = null;
49  return $returner;
50  }
51  return $returner[$locale];
52  }
53  return $returner;
54  }
55 
56  function _cacheMiss(&$cache, $id) {
57  $settings =& $this->getConferenceSettings($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 
71  function &getConferenceSettings($conferenceId) {
72  $conferenceSettings = array();
73 
74  $result =& $this->retrieve(
75  'SELECT setting_name, setting_value, setting_type, locale FROM conference_settings WHERE conference_id = ?', $conferenceId
76  );
77 
78  while (!$result->EOF) {
79  $row =& $result->getRowAssoc(false);
80  $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
81  if ($row['locale'] == '') $conferenceSettings[$row['setting_name']] = $value;
82  else $conferenceSettings[$row['setting_name']][$row['locale']] = $value;
83  $result->MoveNext();
84  }
85  $result->Close();
86  unset($result);
87 
88  $cache =& $this->_getCache($conferenceId);
89  $cache->setEntireCache($conferenceSettings);
90 
91  return $conferenceSettings;
92  }
93 
102  function updateSetting($conferenceId, $name, $value, $type = null, $isLocalized = false) {
103  $cache =& $this->_getCache($conferenceId);
104  $cache->setCache($name, $value);
105 
106  $keyFields = array('setting_name', 'locale', 'conference_id');
107 
108  if (!$isLocalized) {
109  $value = $this->convertToDB($value, $type);
110  $this->replace('conference_settings',
111  array(
112  'conference_id' => $conferenceId,
113  'setting_name' => $name,
114  'setting_value' => $value,
115  'setting_type' => $type,
116  'locale' => ''
117  ),
118  $keyFields
119  );
120  } else {
121  if (is_array($value)) foreach ($value as $locale => $localeValue) {
122  $this->update('DELETE FROM conference_settings WHERE conference_id = ? AND setting_name = ? AND locale = ?', array($conferenceId, $name, $locale));
123  if (empty($localeValue)) continue;
124  $type = null;
125  $this->update('INSERT INTO conference_settings
126  (conference_id, setting_name, setting_value, setting_type, locale)
127  VALUES (?, ?, ?, ?, ?)',
128  array(
129  $conferenceId, $name, $this->convertToDB($localeValue, $type), $type, $locale
130  )
131  );
132  }
133  }
134  }
135 
142  function deleteSetting($conferenceId, $name, $locale = null) {
143  $cache =& $this->_getCache($conferenceId);
144  $cache->setCache($name, null);
145 
146  $params = array($conferenceId, $name);
147  $sql = 'DELETE FROM conference_settings WHERE conference_id = ? AND setting_name = ?';
148  if ($locale !== null) {
149  $params[] = $locale;
150  $sql .= ' AND locale = ?';
151  }
152 
153  return $this->update($sql, $params);
154  }
155 
160  function deleteSettingsByConference($conferenceId) {
161  $cache =& $this->_getCache($conferenceId);
162  $cache->flush();
163 
164  return $this->update(
165  'DELETE FROM conference_settings WHERE conference_id = ?', $conferenceId
166  );
167  }
168 
175  function _performReplacement($rawInput, $paramArray = array()) {
176  $value = preg_replace_callback('{{translate key="([^"]+)"}}', array(&$this, '_installer_regexp_callback'), $rawInput);
177  foreach ($paramArray as $pKey => $pValue) {
178  $value = str_replace('{$' . $pKey . '}', $pValue, $value);
179  }
180  return $value;
181  }
182 
189  function &_buildObject (&$node, $paramArray = array()) {
190  $value = array();
191  foreach ($node->getChildren() as $element) {
192  $key = $element->getAttribute('key');
193  $childArray =& $element->getChildByName('array');
194  if (isset($childArray)) {
195  $content = $this->_buildObject($childArray, $paramArray);
196  } else {
197  $content = $this->_performReplacement($element->getValue(), $paramArray);
198  }
199  if (!empty($key)) {
200  $key = $this->_performReplacement($key, $paramArray);
201  $value[$key] = $content;
202  } else $value[] = $content;
203  }
204  return $value;
205  }
206 
213  function installSettings($conferenceId, $filename, $paramArray = array()) {
214  $xmlParser = new XMLParser();
215  $tree = $xmlParser->parse($filename);
216 
217  if (!$tree) {
218  $xmlParser->destroy();
219  return false;
220  }
221 
222  foreach ($tree->getChildren() as $setting) {
223  $nameNode =& $setting->getChildByName('name');
224  $valueNode =& $setting->getChildByName('value');
225 
226  if (isset($nameNode) && isset($valueNode)) {
227  $type = $setting->getAttribute('type');
228  $isLocaleField = $setting->getAttribute('locale');
229  $name =& $nameNode->getValue();
230 
231  if ($type == 'object') {
232  $arrayNode =& $valueNode->getChildByName('array');
233  $value = $this->_buildObject($arrayNode, $paramArray);
234  } else {
235  $value = $this->_performReplacement($valueNode->getValue(), $paramArray);
236  }
237 
238  // Replace translate calls with translated content
239  $this->updateSetting(
240  $conferenceId,
241  $name,
242  $isLocaleField?array(AppLocale::getLocale() => $value):$value,
243  $type,
244  $isLocaleField
245  );
246  }
247  }
248 
249  $xmlParser->destroy();
250 
251  }
252 
260  function _performLocalizedReplacement($rawInput, $paramArray = array(), $locale = null) {
261  preg_match('{{translate key="([^"]+)"}}', $rawInput, $matches);
262  if ( isset($matches[1]) ) {
264  return __($matches[1], $paramArray, $locale);
265  }
266 
267  return $rawInput;
268  }
269 
277  function &_buildLocalizedObject (&$node, $paramArray = array(), $locale = null) {
278  $value = array();
279  foreach ($node->getChildren() as $element) {
280  $key = $element->getAttribute('key');
281  $childArray =& $element->getChildByName('array');
282  if (isset($childArray)) {
283  $content = $this->_buildLocalizedObject($childArray, $paramArray, $locale);
284  } else {
285  $content = $this->_performLocalizedReplacement($element->getValue(), $paramArray, $locale);
286  }
287  if (!empty($key)) {
288  $key = $this->_performLocalizedReplacement($key, $paramArray, $locale);
289  $value[$key] = $content;
290  } else $value[] = $content;
291  }
292  return $value;
293  }
294 
302  function reloadLocalizedDefaultSettings($conferenceId, $filename, $paramArray, $locale) {
303  $xmlParser = new XMLParser();
304  $tree = $xmlParser->parse($filename);
305 
306  if (!$tree) {
307  $xmlParser->destroy();
308  return false;
309  }
310 
311  foreach ($tree->getChildren() as $setting) {
312  $nameNode =& $setting->getChildByName('name');
313  $valueNode =& $setting->getChildByName('value');
314 
315  if (isset($nameNode) && isset($valueNode)) {
316  $type = $setting->getAttribute('type');
317  $isLocaleField = $setting->getAttribute('locale');
318  $name =& $nameNode->getValue();
319 
320  //skip all settings that are not locale fields
321  if (!$isLocaleField) continue;
322 
323  if ($type == 'object') {
324  $arrayNode =& $valueNode->getChildByName('array');
325  $value = $this->_buildLocalizedObject($arrayNode, $paramArray, $locale);
326  } else {
327  $value = $this->_performLocalizedReplacement($valueNode->getValue(), $paramArray, $locale);
328  }
329 
330  // Replace translate calls with translated content
331  $this->updateSetting(
332  $conferenceId,
333  $name,
334  array($locale => $value),
335  $type,
336  true
337  );
338  }
339  }
340 
341  $xmlParser->destroy();
342 
343  }
344 
348  function _installer_regexp_callback($matches) {
349  return __($matches[1]);
350  }
351 
352 }
353 
354 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
_performLocalizedReplacement($rawInput, $paramArray=array(), $locale=null)
const LOCALE_COMPONENT_OCS_MANAGER
& _buildObject(&$node, $paramArray=array())
_performReplacement($rawInput, $paramArray=array())
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
installSettings($conferenceId, $filename, $paramArray=array())
requireComponents($components, $locale=null)
$content
Class for Conference Settings DAO. Operations for retrieving and modifying conference settings.
& getConferenceSettings($conferenceId)
& getSetting($conferenceId, $name, $locale=null)
deleteSetting($conferenceId, $name, $locale=null)
& _buildLocalizedObject(&$node, $paramArray=array(), $locale=null)
__($key, $params=array(), $locale=null)
convertFromDB($value, $type)
Definition: DAO.inc.php:296
Generic class for parsing an XML document into a data structure.
reloadLocalizedDefaultSettings($conferenceId, $filename, $paramArray, $locale)
convertToDB($value, &$type)
Definition: DAO.inc.php:352
Operations for retrieving and modifying settings.
replace($table, $arrFields, $keyCols)
Definition: DAO.inc.php:214
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
const LOCALE_COMPONENT_OCS_DEFAULT
updateSetting($conferenceId, $name, $value, $type=null, $isLocalized=false)