modusergroupsetting.class.php 2.7 KB

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