mirror of
https://github.com/flarum/core.git
synced 2025-08-17 22:01:44 +02:00
cleaned up the Tag model and obsoleted/unused property
This commit is contained in:
@@ -34,7 +34,6 @@ class TagSerializer extends AbstractSerializer
|
|||||||
'backgroundUrl' => $tag->background_path,
|
'backgroundUrl' => $tag->background_path,
|
||||||
'backgroundMode' => $tag->background_mode,
|
'backgroundMode' => $tag->background_mode,
|
||||||
'icon' => $tag->icon,
|
'icon' => $tag->icon,
|
||||||
'iconUrl' => $tag->icon_path,
|
|
||||||
'discussionCount' => (int) $tag->discussion_count,
|
'discussionCount' => (int) $tag->discussion_count,
|
||||||
'position' => $tag->position === null ? null : (int) $tag->position,
|
'position' => $tag->position === null ? null : (int) $tag->position,
|
||||||
'defaultSort' => $tag->default_sort,
|
'defaultSort' => $tag->default_sort,
|
||||||
|
@@ -18,23 +18,38 @@ use Flarum\Group\Permission;
|
|||||||
use Flarum\User\User;
|
use Flarum\User\User;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @property int $id
|
||||||
|
* @property string $name
|
||||||
|
* @property string $slug
|
||||||
|
* @property string $description
|
||||||
|
* @property string $color
|
||||||
|
* @property string $background_path
|
||||||
|
* @property string $background_mode
|
||||||
|
* @property int $position
|
||||||
|
* @property int $parent_id
|
||||||
|
* @property string $default_sort
|
||||||
|
* @property bool $is_restricted
|
||||||
|
* @property bool $is_hidden
|
||||||
|
* @property int $discussion_count
|
||||||
|
* @property \Carbon\Carbon $last_posted_at
|
||||||
|
* @property int $last_posted_discussion_id
|
||||||
|
* @property int $last_posted_user_id
|
||||||
|
* @property string $icon
|
||||||
|
*/
|
||||||
class Tag extends AbstractModel
|
class Tag extends AbstractModel
|
||||||
{
|
{
|
||||||
use ScopeVisibilityTrait;
|
use ScopeVisibilityTrait;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $table = 'tags';
|
protected $table = 'tags';
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected $dates = ['last_posted_at'];
|
protected $dates = ['last_posted_at'];
|
||||||
|
|
||||||
/**
|
protected $casts = [
|
||||||
* {@inheritdoc}
|
'is_hidden' => 'bool',
|
||||||
*/
|
'is_restricted' => 'bool'
|
||||||
|
];
|
||||||
|
|
||||||
public static function boot()
|
public static function boot()
|
||||||
{
|
{
|
||||||
parent::boot();
|
parent::boot();
|
||||||
@@ -51,6 +66,7 @@ class Tag extends AbstractModel
|
|||||||
* @param string $slug
|
* @param string $slug
|
||||||
* @param string $description
|
* @param string $description
|
||||||
* @param string $color
|
* @param string $color
|
||||||
|
* @param string $icon
|
||||||
* @param bool $isHidden
|
* @param bool $isHidden
|
||||||
* @return static
|
* @return static
|
||||||
*/
|
*/
|
||||||
@@ -68,43 +84,26 @@ class Tag extends AbstractModel
|
|||||||
return $tag;
|
return $tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
||||||
*/
|
|
||||||
public function parent()
|
public function parent()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(self::class);
|
return $this->belongsTo(self::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
||||||
*/
|
|
||||||
public function lastPostedDiscussion()
|
public function lastPostedDiscussion()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Discussion::class, 'last_posted_discussion_id');
|
return $this->belongsTo(Discussion::class, 'last_posted_discussion_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
||||||
*/
|
|
||||||
public function lastPostedUser()
|
public function lastPostedUser()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'last_posted_user_id');
|
return $this->belongsTo(User::class, 'last_posted_user_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
|
||||||
*/
|
|
||||||
public function discussions()
|
public function discussions()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Discussion::class);
|
return $this->belongsToMany(Discussion::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Refresh a tag's last discussion details.
|
|
||||||
*
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function refreshLastPostedDiscussion()
|
public function refreshLastPostedDiscussion()
|
||||||
{
|
{
|
||||||
if ($lastPostedDiscussion = $this->discussions()->latest('last_posted_at')->first()) {
|
if ($lastPostedDiscussion = $this->discussions()->latest('last_posted_at')->first()) {
|
||||||
@@ -114,12 +113,6 @@ class Tag extends AbstractModel
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the tag's last discussion details.
|
|
||||||
*
|
|
||||||
* @param Discussion $discussion
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public function setLastPostedDiscussion(Discussion $discussion)
|
public function setLastPostedDiscussion(Discussion $discussion)
|
||||||
{
|
{
|
||||||
$this->last_posted_at = $discussion->last_posted_at;
|
$this->last_posted_at = $discussion->last_posted_at;
|
||||||
@@ -173,13 +166,7 @@ class Tag extends AbstractModel
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected static function getIdsWherePermission(User $user, string $permission, bool $condition = true): array
|
||||||
* @param User $user
|
|
||||||
* @param string $permission
|
|
||||||
* @param bool $condition
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
protected static function getIdsWherePermission(User $user, $permission, $condition = true)
|
|
||||||
{
|
{
|
||||||
static $tags;
|
static $tags;
|
||||||
|
|
||||||
@@ -209,22 +196,12 @@ class Tag extends AbstractModel
|
|||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function getIdsWhereCan(User $user, string $permission): array
|
||||||
* @param User $user
|
|
||||||
* @param string $permission
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getIdsWhereCan(User $user, $permission)
|
|
||||||
{
|
{
|
||||||
return static::getIdsWherePermission($user, $permission, true);
|
return static::getIdsWherePermission($user, $permission, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function getIdsWhereCannot(User $user, string $permission): array
|
||||||
* @param User $user
|
|
||||||
* @param string $permission
|
|
||||||
* @return array
|
|
||||||
*/
|
|
||||||
public static function getIdsWhereCannot(User $user, $permission)
|
|
||||||
{
|
{
|
||||||
return static::getIdsWherePermission($user, $permission, false);
|
return static::getIdsWherePermission($user, $permission, false);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user