classes/db/SettingsDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00015 //$Id$
00016 
00017 class SettingsDAO extends DAO {
00021    function SettingsDAO() {
00022       parent::DAO();
00023    }
00024 
00031    function _performReplacement($rawInput, $paramArray = array()) {
00032       $value = preg_replace_callback('{{translate key="([^"]+)"}}', array(&$this, '_installer_regexp_callback'), $rawInput);
00033       foreach ($paramArray as $pKey => $pValue) {
00034          $value = str_replace('{$' . $pKey . '}', $pValue, $value);
00035       }
00036       return $value;
00037    }
00038 
00045    function &_buildObject (&$node, $paramArray = array()) {
00046       $value = array();
00047       foreach ($node->getChildren() as $element) {
00048          $key = $element->getAttribute('key');
00049          $childArray =& $element->getChildByName('array');
00050          if (isset($childArray)) {
00051             $content = $this->_buildObject($childArray, $paramArray);
00052          } else {
00053             $content = $this->_performReplacement($element->getValue(), $paramArray);
00054          }
00055          if (!empty($key)) {
00056             $key = $this->_performReplacement($key, $paramArray);
00057             $value[$key] = $content;
00058          } else $value[] = $content;
00059       }
00060       return $value;
00061    }
00062 
00069    function installSettings($id, $filename, $paramArray = array()) {
00070       $xmlParser = new XMLParser();
00071       $tree = $xmlParser->parse($filename);
00072 
00073       if (!$tree) {
00074          $xmlParser->destroy();
00075          return false;
00076       }
00077 
00078       foreach ($tree->getChildren() as $setting) {
00079          $nameNode =& $setting->getChildByName('name');
00080          $valueNode =& $setting->getChildByName('value');
00081 
00082          if (isset($nameNode) && isset($valueNode)) {
00083             $type = $setting->getAttribute('type');
00084             $isLocaleField = $setting->getAttribute('locale');
00085             $name =& $nameNode->getValue();
00086 
00087             if ($type == 'date') {
00088                $value = strtotime($valueNode->getValue());
00089             } elseif ($type == 'object') {
00090                $arrayNode =& $valueNode->getChildByName('array');
00091                $value = $this->_buildObject($arrayNode, $paramArray);
00092             } else {
00093                $value = $this->_performReplacement($valueNode->getValue(), $paramArray);
00094             }
00095 
00096             // Replace translate calls with translated content
00097             $this->updateSetting(
00098                $id,
00099                $name,
00100                $isLocaleField?array(AppLocale::getLocale() => $value):$value,
00101                $type,
00102                $isLocaleField
00103             );
00104          }
00105       }
00106 
00107       $xmlParser->destroy();
00108 
00109    }
00110 
00114    function _installer_regexp_callback($matches) {
00115       return __($matches[1]);
00116    }
00117 }
00118 
00119 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7