classes/schedConf/SchedConfSettingsDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('db.SettingsDAO');
00020 class SchedConfSettingsDAO extends SettingsDAO {
00021    function &_getCache($schedConfId) {
00022       static $settingCache;
00023 
00024       if (!isset($settingCache)) {
00025          $settingCache = array();
00026       }
00027       if (!isset($settingCache[$schedConfId])) {
00028          $cacheManager =& CacheManager::getManager();
00029          $settingCache[$schedConfId] = $cacheManager->getCache(
00030             'schedConfSettings', $schedConfId,
00031             array($this, '_cacheMiss')
00032          );
00033       }
00034       return $settingCache[$schedConfId];
00035    }
00036 
00044    function &getSetting($schedConfId, $name, $locale = null) {
00045       $cache =& $this->_getCache($schedConfId);
00046       $returner = $cache->get($name);
00047       if ($locale !== null) {
00048          if (!isset($returner[$locale]) || !is_array($returner)) {
00049             unset($returner);
00050             $returner = null;
00051             return $returner;
00052          }
00053          return $returner[$locale];
00054       }
00055       return $returner;
00056    }
00057 
00058    function _cacheMiss(&$cache, $id) {
00059       $settings =& $this->getSchedConfSettings($cache->getCacheId());
00060       if (!isset($settings[$id])) {
00061          // Make sure that even null values are cached
00062          $cache->setCache($id, null);
00063          return null;
00064       }
00065       return $settings[$id];
00066    }
00067 
00073    function &getSchedConfSettings($schedConfId) {
00074       $schedConfSettings = array();
00075 
00076       $result =& $this->retrieve(
00077          'SELECT setting_name, setting_value, setting_type, locale FROM sched_conf_settings WHERE sched_conf_id = ?', $schedConfId 
00078       );
00079 
00080       if ($result->RecordCount() == 0) {
00081          $returner = null;
00082          $result->Close();
00083          return $returner;
00084 
00085       } else {
00086          while (!$result->EOF) {
00087             $row =& $result->getRowAssoc(false);
00088             $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
00089             if ($row['locale'] == '') $schedConfSettings[$row['setting_name']] = $value;
00090             else $schedConfSettings[$row['setting_name']][$row['locale']] = $value;
00091             $result->MoveNext();
00092          }
00093          $result->close();
00094          unset($result);
00095 
00096          $cache =& $this->_getCache($schedConfId);
00097          $cache->setEntireCache($schedConfSettings);
00098 
00099          return $schedConfSettings;
00100       }
00101    }
00102 
00111    function updateSetting($schedConfId, $name, $value, $type = null, $isLocalized = false) {
00112       $cache =& $this->_getCache($schedConfId);
00113       $cache->setCache($name, $value);
00114 
00115       $keyFields = array('setting_name', 'locale', 'sched_conf_id');
00116 
00117       if (!$isLocalized) {
00118          $value = $this->convertToDB($value, $type);
00119          $this->replace('sched_conf_settings',
00120             array(
00121                'sched_conf_id' => $schedConfId,
00122                'setting_name' => $name,
00123                'setting_value' => $value,
00124                'setting_type' => $type,
00125                'locale' => ''
00126             ),
00127             $keyFields
00128          );
00129       } else {
00130          $this->update('DELETE FROM sched_conf_settings WHERE sched_conf_id = ? AND setting_name = ?', array($schedConfId, $name));
00131          if (is_array($value)) foreach ($value as $locale => $localeValue) {
00132             if (empty($localeValue)) continue;
00133             $type = null;
00134             $this->update('INSERT INTO sched_conf_settings
00135                (sched_conf_id, setting_name, setting_value, setting_type, locale)
00136                VALUES (?, ?, ?, ?, ?)',
00137                array(
00138                   $schedConfId, $name, $this->convertToDB($localeValue, $type), $type, $locale
00139                )
00140             );
00141          }
00142       }
00143    }
00144 
00151    function deleteSetting($schedConfId, $name, $locale = null) {
00152       $cache =& $this->_getCache($schedConfId);
00153       $cache->setCache($name, null);
00154 
00155       $params = array($schedConfId, $name);
00156       $sql = 'DELETE FROM sched_conf_settings WHERE sched_conf_id = ? AND setting_name = ?';
00157       if ($locale !== null) {
00158          $params[] = $locale;
00159          $sql .= ' AND locale = ?';
00160       }
00161       return $this->update($sql, $params);
00162    }
00163 
00168    function deleteSettingsBySchedConf($schedConfId) {
00169       $cache =& $this->_getCache($schedConfId);
00170       $cache->flush();
00171 
00172       return $this->update(
00173             'DELETE FROM sched_conf_settings WHERE sched_conf_id = ?', $schedConfId
00174       );
00175    }
00176 }
00177 
00178 ?>

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