removed references to preferences column, now we need to refactor how notification ppreferences is integrated into the current app

This commit is contained in:
Daniël Klabbers 2019-07-09 22:16:51 +02:00
parent 6cfc9182f4
commit d6fc3a91a6
3 changed files with 25 additions and 3 deletions

View File

@ -9,9 +9,7 @@
* file that was distributed with this source code.
*/
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Schema\Builder;
use Illuminate\Support\Arr;
return [
'up' => function (Builder $builder) {

View File

@ -0,0 +1,19 @@
<?php
namespace Flarum\User;
use Flarum\Database\AbstractModel;
/**
* @property int $user_id
* @property string $type
* @property string $channel
* @property bool $enabled
*/
class NotificationPreference extends AbstractModel
{
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@ -448,6 +448,11 @@ class User extends AbstractModel
})->count();
}
public function notificationPreferences()
{
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.
@ -461,7 +466,7 @@ class User extends AbstractModel
return $value['default'];
}, static::$preferences);
$user = Arr::only((array) json_decode($value, true), array_keys(static::$preferences));
$user = Arr::only($this->notificationPreferences->toArray(), array_keys(static::$preferences));
return array_merge($defaults, $user);
}