You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

preferences.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @author Jakob Sack
  7. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. /**
  24. * This class provides an easy way for storing user preferences.
  25. */
  26. OC_Preferences::$object = new \OC\Preferences(OC_DB::getConnection());
  27. class OC_Preferences{
  28. public static $object;
  29. /**
  30. * @brief Get all users using the preferences
  31. * @return array with user ids
  32. *
  33. * This function returns a list of all users that have at least one entry
  34. * in the preferences table.
  35. */
  36. public static function getUsers() {
  37. return self::$object->getUsers();
  38. }
  39. /**
  40. * @brief Get all apps of a user
  41. * @param string $user user
  42. * @return integer[] with app ids
  43. *
  44. * This function returns a list of all apps of the user that have at least
  45. * one entry in the preferences table.
  46. */
  47. public static function getApps( $user ) {
  48. return self::$object->getApps( $user );
  49. }
  50. /**
  51. * @brief Get the available keys for an app
  52. * @param string $user user
  53. * @param string $app the app we are looking for
  54. * @return array with key names
  55. *
  56. * This function gets all keys of an app of an user. Please note that the
  57. * values are not returned.
  58. */
  59. public static function getKeys( $user, $app ) {
  60. return self::$object->getKeys( $user, $app );
  61. }
  62. /**
  63. * @brief Gets the preference
  64. * @param string $user user
  65. * @param string $app app
  66. * @param string $key key
  67. * @param string $default = null, default value if the key does not exist
  68. * @return string the value or $default
  69. *
  70. * This function gets a value from the preferences table. If the key does
  71. * not exist the default value will be returned
  72. */
  73. public static function getValue( $user, $app, $key, $default = null ) {
  74. return self::$object->getValue( $user, $app, $key, $default );
  75. }
  76. /**
  77. * @brief sets a value in the preferences
  78. * @param string $user user
  79. * @param string $app app
  80. * @param string $key key
  81. * @param string $value value
  82. * @return bool
  83. *
  84. * Adds a value to the preferences. If the key did not exist before, it
  85. * will be added automagically.
  86. */
  87. public static function setValue( $user, $app, $key, $value ) {
  88. self::$object->setValue( $user, $app, $key, $value );
  89. return true;
  90. }
  91. /**
  92. * @brief Deletes a key
  93. * @param string $user user
  94. * @param string $app app
  95. * @param string $key key
  96. *
  97. * Deletes a key.
  98. */
  99. public static function deleteKey( $user, $app, $key ) {
  100. self::$object->deleteKey( $user, $app, $key );
  101. return true;
  102. }
  103. /**
  104. * @brief Remove app of user from preferences
  105. * @param string $user user
  106. * @param string $app app
  107. * @return bool
  108. *
  109. * Removes all keys in preferences belonging to the app and the user.
  110. */
  111. public static function deleteApp( $user, $app ) {
  112. self::$object->deleteApp( $user, $app );
  113. return true;
  114. }
  115. /**
  116. * @brief Remove user from preferences
  117. * @param string $user user
  118. * @return bool
  119. *
  120. * Removes all keys in preferences belonging to the user.
  121. */
  122. public static function deleteUser( $user ) {
  123. self::$object->deleteUser( $user );
  124. return true;
  125. }
  126. /**
  127. * @brief Remove app from all users
  128. * @param string $app app
  129. * @return bool
  130. *
  131. * Removes all keys in preferences belonging to the app.
  132. */
  133. public static function deleteAppFromAllUsers( $app ) {
  134. self::$object->deleteAppFromAllUsers( $app );
  135. return true;
  136. }
  137. }