modcontextsetting.class.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of MODX Revolution.
  4. *
  5. * Copyright (c) MODX, LLC. All Rights Reserved.
  6. *
  7. * For complete copyright and license information, see the COPYRIGHT and LICENSE
  8. * files found in the top-level directory of this distribution.
  9. */
  10. /**
  11. * Represents a context-specific configuration setting.
  12. *
  13. * These settings are loaded and will be merged with the already loaded system
  14. * level settings, then merged again with user level settings for authenticated
  15. * users.
  16. *
  17. * @property string $context_key The key of the Context this Setting applies to
  18. * @property string $key The key of the Setting
  19. * @property string $value The value of the Setting
  20. * @property string $xtype The xtype that is used to render the Setting input in the manager
  21. * @property string $namespace The Namespace of the setting
  22. * @property string $area The area of the Setting
  23. * @property timestamp $editedon The last edited on time of this Setting
  24. *
  25. * @property modX|xPDO $xpdo
  26. *
  27. * @package modx
  28. */
  29. class modContextSetting extends xPDOObject {
  30. /**
  31. * Updates the Lexicon Entry translation for this Context Setting
  32. *
  33. * @param string $key The key of the setting
  34. * @param string $value The new value of the setting
  35. * @param array $options An array of options related to the setting
  36. * @return bool
  37. */
  38. public function updateTranslation($key,$value = '',array $options = array()) {
  39. if (!is_array($options) || empty($options)) return false;
  40. $options['namespace'] = $this->xpdo->getOption('namespace',$options,'core');
  41. $options['cultureKey'] = $this->xpdo->getOption('cultureKey',$options,'en');
  42. $options['topic'] = $options['namespace'] == 'core' ? 'setting' : 'default';
  43. $saved = false;
  44. $entries = $this->xpdo->lexicon->getFileTopic($options['cultureKey'],$options['namespace'],$options['topic']);
  45. $entry = $this->xpdo->getObject('modLexiconEntry',array(
  46. 'name' => $key,
  47. 'namespace' => $options['namespace'],
  48. 'language' => $options['cultureKey'],
  49. 'topic' => $options['topic'],
  50. ));
  51. if ((!empty($entries[$key]) && $entries[$key] == $value) || strcmp($key,$value) == 0 || empty($value)) {
  52. if ($entry) {
  53. $saved = $entry->remove();
  54. $this->xpdo->lexicon->clearCache($options['cultureKey'].'/'.$options['namespace'].'/'.$options['topic'].'.cache.php');
  55. }
  56. } else {
  57. if ($entry == null) {
  58. $entry = $this->xpdo->newObject('modLexiconEntry');
  59. $entry->set('name',$key);
  60. $entry->set('namespace',$options['namespace']);
  61. $entry->set('language',$options['cultureKey']);
  62. $entry->set('topic',$options['topic']);
  63. }
  64. $entry->set('value',$value);
  65. $saved = $entry->save();
  66. $entry->clearCache();
  67. }
  68. return $saved;
  69. }
  70. }