modusersetting.class.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 user setting which overrides system and context settings.
  12. *
  13. *
  14. * @param int $user The ID of the User
  15. * @property string $key The key of the Setting
  16. * @property string $value The value of the Setting
  17. * @property string $xtype The xtype that is used to render the Setting input in the manager
  18. * @property string $namespace The Namespace of the setting
  19. * @property string $area The area of the Setting
  20. * @property timestamp $editedon The last edited on time of this Setting
  21. * @package modx
  22. */
  23. class modUserSetting extends xPDOObject {
  24. /**
  25. * Update the translation for the setting
  26. *
  27. * @param string $key The key of the Setting to update
  28. * @param string $value The value of the Setting to update
  29. * @param array $options An array of options for the update
  30. * @return bool
  31. */
  32. public function updateTranslation($key,$value = '',array $options = array()) {
  33. if (!is_array($options) || empty($options)) return false;
  34. $options['namespace'] = $this->xpdo->getOption('namespace',$options,'core');
  35. $options['cultureKey'] = $this->xpdo->getOption('cultureKey',$options,'en');
  36. $options['topic'] = $options['namespace'] == 'core' ? 'setting' : 'default';
  37. $saved = false;
  38. $entries = $this->xpdo->lexicon->getFileTopic($options['cultureKey'],$options['namespace'],$options['topic']);
  39. $entry = $this->xpdo->getObject('modLexiconEntry',array(
  40. 'name' => $key,
  41. 'namespace' => $options['namespace'],
  42. 'language' => $options['cultureKey'],
  43. 'topic' => $options['topic'],
  44. ));
  45. if ((!empty($entries[$key]) && $entries[$key] == $value) || strcmp($key,$value) == 0 || empty($value)) {
  46. if ($entry) {
  47. $saved = $entry->remove();
  48. $this->xpdo->lexicon->clearCache($options['cultureKey'].'/'.$options['namespace'].'/'.$options['topic'].'.cache.php');
  49. }
  50. } else {
  51. if ($entry == null) {
  52. $entry = $this->xpdo->newObject('modLexiconEntry');
  53. $entry->set('name',$key);
  54. $entry->set('namespace',$options['namespace']);
  55. $entry->set('language',$options['cultureKey']);
  56. $entry->set('topic',$options['topic']);
  57. }
  58. $entry->set('value',$value);
  59. $saved = $entry->save();
  60. $entry->clearCache();
  61. }
  62. return $saved;
  63. }
  64. }