mirror of
https://github.com/flarum/core.git
synced 2025-08-06 16:36:47 +02:00
move deprecated methods to trait for cleaner code until we remove it
This commit is contained in:
78
src/User/Concerns/DeprecatedUserPreferences.php
Normal file
78
src/User/Concerns/DeprecatedUserPreferences.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Flarum\User\Concerns;
|
||||||
|
|
||||||
|
use Flarum\User\User;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
trait DeprecatedUserPreferences
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@@ -57,6 +57,7 @@ use Illuminate\Support\Arr;
|
|||||||
*/
|
*/
|
||||||
class User extends AbstractModel
|
class User extends AbstractModel
|
||||||
{
|
{
|
||||||
|
use Concerns\DeprecatedUserPreferences;
|
||||||
use EventGeneratorTrait;
|
use EventGeneratorTrait;
|
||||||
use ScopeVisibilityTrait;
|
use ScopeVisibilityTrait;
|
||||||
|
|
||||||
@@ -453,35 +454,6 @@ class User extends AbstractModel
|
|||||||
return $this->hasMany(NotificationPreference::class);
|
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
|
* Check whether or not the user should receive an alert for a notification
|
||||||
* type.
|
* type.
|
||||||
@@ -510,31 +482,6 @@ class User extends AbstractModel
|
|||||||
->exists();
|
->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.
|
* Set the user as being last seen just now.
|
||||||
*
|
*
|
||||||
@@ -736,19 +683,6 @@ class User extends AbstractModel
|
|||||||
static::$preferences[$key] = compact('transformer', 'default');
|
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.
|
* Refresh the user's comments count.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user