mirror of
https://github.com/flarum/framework.git
synced 2024-12-01 05:53:45 +08:00
move deprecated methods to trait for cleaner code until we remove it
This commit is contained in:
parent
aef56c055a
commit
4465e7648b
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
|
||||
{
|
||||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user