Open Journal Systems  3.3.0
TimeZoneDAO.inc.php
1 <?php
2 
18 class TimeZoneDAO extends DAO {
19  var $cache;
20 
24  function __construct() {
25  // Parent constructor intentionally not called
26  }
27 
31  function getFilename() {
32  return "lib/pkp/registry/timeZones.xml";
33  }
34 
35  function &_getTimeZoneCache() {
36  $cache =& Registry::get('allTimeZones', true, null);
37  if ($cache === null) {
38  $cacheManager = CacheManager::getManager();
39  $cache = $cacheManager->getFileCache(
40  'timeZone', 'list',
41  array($this, '_timeZoneCacheMiss')
42  );
43 
44  // Check to see if the data is outdated
45  $cacheTime = $cache->getCacheTime();
46  if ($cacheTime !== null && $cacheTime < filemtime($this->getFilename())) {
47  $cache->flush();
48  }
49  }
50  return $cache;
51  }
52 
53  function _timeZoneCacheMiss($cache, $id) {
54  $timeZones =& Registry::get('allTimeZonesData', true, null);
55  if ($timeZones === null) {
56  // Reload time zone registry file
57  $xmlDao = new XMLDAO();
58  $data = $xmlDao->parseStruct($this->getFilename(), array('timezones', 'entry'));
59  $timeZones = array();
60  if (isset($data['timezones'])) {
61  foreach ($data['entry'] as $timeZoneData) {
62  $timeZones[$timeZoneData['attributes']['key']] = $timeZoneData['attributes']['name'];
63  }
64  }
65  asort($timeZones);
66  $cache->setEntireCache($timeZones);
67  }
68  return null;
69  }
70 
75  function &getTimeZones() {
76  $cache =& $this->_getTimeZoneCache();
77  return $cache->getContents();
78  }
79 }
80 
81 
TimeZoneDAO\__construct
__construct()
Definition: TimeZoneDAO.inc.php:24
XMLDAO
Operations for retrieving and modifying objects from an XML data source.
Definition: XMLDAO.inc.php:19
TimeZoneDAO\getFilename
getFilename()
Definition: TimeZoneDAO.inc.php:31
CacheManager\getManager
static getManager()
Definition: CacheManager.inc.php:27
Registry\get
static & get($key, $createIfEmpty=false, $createWithDefault=null)
Definition: Registry.inc.php:35
TimeZoneDAO\getTimeZones
& getTimeZones()
Definition: TimeZoneDAO.inc.php:75
TimeZoneDAO\_getTimeZoneCache
& _getTimeZoneCache()
Definition: TimeZoneDAO.inc.php:35
TimeZoneDAO\$cache
$cache
Definition: TimeZoneDAO.inc.php:19
TimeZoneDAO\_timeZoneCacheMiss
_timeZoneCacheMiss($cache, $id)
Definition: TimeZoneDAO.inc.php:53
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
TimeZoneDAO
Definition: TimeZoneDAO.inc.php:18