diff --git a/src/User/Concerns/DeprecatedUserPreferences.php b/src/User/Concerns/DeprecatedUserPreferences.php new file mode 100644 index 000000000..153c56349 --- /dev/null +++ b/src/User/Concerns/DeprecatedUserPreferences.php @@ -0,0 +1,78 @@ +notificationPreferences->toArray(), array_keys(static::$preferences)); + + return array_merge($defaults, $user); + } + + /** + * Encode an array of preferences for storage in the database. + * + * @param mixed $value + * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. + */ + public function setPreferencesAttribute($value) + { + } + + /** + * Get the value of a preference for this user. + * + * @param string $key + * @param mixed $default + * @return mixed + * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. + */ + public function getPreference($key, $default = null) + { + return Arr::get($this->preferences, $key, $default); + } + + /** + * Set the value of a preference for this user. + * + * @param string $key + * @param mixed $value + * @return $this + * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. + */ + public function setPreference($key, $value) + { + } + + /** + * Get the key for a preference which flags whether or not the user will + * receive a notification for $type via $method. + * + * @param string $type + * @param string $method + * @return string + * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used, use NotificationPreference::getPreferenceKey. + */ + public static function getNotificationPreferenceKey($type, $method) + { + } +} diff --git a/src/User/User.php b/src/User/User.php index 1c0598998..b74651981 100644 --- a/src/User/User.php +++ b/src/User/User.php @@ -57,6 +57,7 @@ use Illuminate\Support\Arr; */ class User extends AbstractModel { + use Concerns\DeprecatedUserPreferences; use EventGeneratorTrait; use ScopeVisibilityTrait; @@ -453,35 +454,6 @@ class User extends AbstractModel return $this->hasMany(NotificationPreference::class); } - /** - * Get the values of all registered preferences for this user, by - * transforming their stored preferences and merging them with the defaults. - * - * @param string $value - * @return array - * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. - */ - public function getPreferencesAttribute($value) - { - $defaults = array_map(function ($value) { - return $value['default']; - }, static::$preferences); - - $user = Arr::only($this->notificationPreferences->toArray(), array_keys(static::$preferences)); - - return array_merge($defaults, $user); - } - - /** - * Encode an array of preferences for storage in the database. - * - * @param mixed $value - * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. - */ - public function setPreferencesAttribute($value) - { - } - /** * Check whether or not the user should receive an alert for a notification * type. @@ -510,31 +482,6 @@ class User extends AbstractModel ->exists(); } - /** - * Get the value of a preference for this user. - * - * @param string $key - * @param mixed $default - * @return mixed - * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. - */ - public function getPreference($key, $default = null) - { - return Arr::get($this->preferences, $key, $default); - } - - /** - * Set the value of a preference for this user. - * - * @param string $key - * @param mixed $value - * @return $this - * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used. - */ - public function setPreference($key, $value) - { - } - /** * Set the user as being last seen just now. * @@ -736,19 +683,6 @@ class User extends AbstractModel static::$preferences[$key] = compact('transformer', 'default'); } - /** - * Get the key for a preference which flags whether or not the user will - * receive a notification for $type via $method. - * - * @param string $type - * @param string $method - * @return string - * @deprecated 0.1.0-beta.11: `users.preferences` is no longer used, use NotificationPreference::getPreferenceKey. - */ - public static function getNotificationPreferenceKey($type, $method) - { - } - /** * Refresh the user's comments count. *