modlexiconentry.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * Database abstraction of a Lexicon Entry. Used only for overrides on existing entries as a way of allowing
  12. * customization without sacrificing upgradability of file-based lexicon topics.
  13. *
  14. * @property string $name The name, or key, of the lexicon entry that is being overridden
  15. * @property string $value The value to override the entry with
  16. * @property string $topic The topic of the overridden entry
  17. * @property string $namespace The namespace of the overridden entry
  18. * @property string $language The language of the overridden entry
  19. * @property datetime $createdon The time that this entry was created
  20. * @property string $editedon The last time that this entry was edited
  21. * @see modLexicon
  22. * @package modx
  23. */
  24. class modLexiconEntry extends xPDOSimpleObject {
  25. /**
  26. * Clears the cache for the entry
  27. *
  28. * @access public
  29. * @return boolean True if successful
  30. */
  31. public function clearCache() {
  32. if ($this->xpdo && $this->xpdo->lexicon) {
  33. return $this->xpdo->lexicon->clearCache($this->get('language').'/'.$this->get('namespace').'/'.$this->get('topic').'.cache.php');
  34. }
  35. return false;
  36. }
  37. /**
  38. * Overrides xPDOObject::save to clear lexicon cache on saving.
  39. *
  40. * {@inheritdoc}
  41. */
  42. public function save($cacheFlag= null) {
  43. if ($this->_new) {
  44. if (!$this->get('createdon')) $this->set('createdon', strftime('%Y-%m-%d %H:%M:%S'));
  45. }
  46. $saved= parent :: save($cacheFlag);
  47. if ($saved && empty($this->xpdo->config[xPDO::OPT_SETUP])) {
  48. $this->clearCache();
  49. }
  50. return $saved;
  51. }
  52. }