private_settings.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Private settings for entities
  4. * Private settings provide metadata like storage of settings for plugins
  5. * and users.
  6. *
  7. * @package Elgg.Core
  8. * @subpackage PrivateSettings
  9. */
  10. /**
  11. * Returns entities based upon private settings. Also accepts all
  12. * options available to elgg_get_entities(). Supports
  13. * the singular option shortcut.
  14. *
  15. * @see elgg_get_entities
  16. *
  17. * @param array $options Array in format:
  18. *
  19. * private_setting_names => null|ARR private setting names
  20. *
  21. * private_setting_values => null|ARR metadata values
  22. *
  23. * private_setting_name_value_pairs => null|ARR (
  24. * name => 'name',
  25. * value => 'value',
  26. * 'operand' => '=',
  27. * )
  28. * Currently if multiple values are sent via
  29. * an array (value => array('value1', 'value2')
  30. * the pair's operand will be forced to "IN".
  31. *
  32. * private_setting_name_value_pairs_operator => null|STR The operator to use for combining
  33. * (name = value) OPERATOR (name = value); default AND
  34. *
  35. * private_setting_name_prefix => STR A prefix to apply to all private settings. Used to
  36. * namespace plugin user settings or by plugins to namespace
  37. * their own settings.
  38. *
  39. *
  40. * @return mixed int If count, int. If not count, array. false on errors.
  41. * @since 1.8.0
  42. */
  43. function elgg_get_entities_from_private_settings(array $options = array()) {
  44. return _elgg_services()->privateSettings->getEntities($options);
  45. }
  46. /**
  47. * Gets a private setting for an entity.
  48. *
  49. * Plugin authors can set private data on entities. By default
  50. * private data will not be searched or exported.
  51. *
  52. * @note Internal: Private data is used to store settings for plugins
  53. * and user settings.
  54. *
  55. * @param int $entity_guid The entity GUID
  56. * @param string $name The name of the setting
  57. *
  58. * @return mixed The setting value, or null if does not exist
  59. * @see set_private_setting()
  60. * @see get_all_private_settings()
  61. * @see remove_private_setting()
  62. * @see remove_all_private_settings()
  63. */
  64. function get_private_setting($entity_guid, $name) {
  65. return _elgg_services()->privateSettings->get($entity_guid, $name);
  66. }
  67. /**
  68. * Return an array of all private settings.
  69. *
  70. * @param int $entity_guid The entity GUID
  71. *
  72. * @return string[] empty array if no settings
  73. * @see set_private_setting()
  74. * @see get_private_settings()
  75. * @see remove_private_setting()
  76. * @see remove_all_private_settings()
  77. */
  78. function get_all_private_settings($entity_guid) {
  79. return _elgg_services()->privateSettings->getAll($entity_guid);
  80. }
  81. /**
  82. * Sets a private setting for an entity.
  83. *
  84. * @param int $entity_guid The entity GUID
  85. * @param string $name The name of the setting
  86. * @param string $value The value of the setting
  87. *
  88. * @return bool
  89. * @see get_private_setting()
  90. * @see get_all_private_settings()
  91. * @see remove_private_setting()
  92. * @see remove_all_private_settings()
  93. */
  94. function set_private_setting($entity_guid, $name, $value) {
  95. return _elgg_services()->privateSettings->set($entity_guid, $name, $value);
  96. }
  97. /**
  98. * Deletes a private setting for an entity.
  99. *
  100. * @param int $entity_guid The Entity GUID
  101. * @param string $name The name of the setting
  102. *
  103. * @return bool
  104. * @see get_private_setting()
  105. * @see get_all_private_settings()
  106. * @see set_private_setting()
  107. * @see remove_all_private_settings()
  108. */
  109. function remove_private_setting($entity_guid, $name) {
  110. return _elgg_services()->privateSettings->remove($entity_guid, $name);
  111. }
  112. /**
  113. * Deletes all private settings for an entity.
  114. *
  115. * @param int $entity_guid The Entity GUID
  116. *
  117. * @return bool
  118. * @see get_private_setting()
  119. * @see get_all_private_settings()
  120. * @see set_private_setting()
  121. * @see remove_private_settings()
  122. */
  123. function remove_all_private_settings($entity_guid) {
  124. return _elgg_services()->privateSettings->removeAllForEntity($entity_guid);
  125. }