2025-07-23 15:41:01 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models\Boards;
|
|
|
|
|
|
2025-12-09 09:39:41 +09:00
|
|
|
use App\Models\Members\User;
|
2025-11-30 21:05:33 +09:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
2025-07-23 15:41:01 +09:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-11-30 21:05:33 +09:00
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
2025-07-23 15:41:01 +09:00
|
|
|
|
2025-08-21 09:50:15 +09:00
|
|
|
/**
|
2025-11-30 21:05:33 +09:00
|
|
|
* 게시판 모델
|
|
|
|
|
*
|
|
|
|
|
* @property int $id
|
|
|
|
|
* @property int|null $tenant_id
|
|
|
|
|
* @property bool $is_system 시스템 게시판 여부 (true=전체 테넌트 공개)
|
|
|
|
|
* @property string|null $board_type 게시판 유형 (notice, qna, faq, free 등)
|
|
|
|
|
* @property string $board_code 게시판 코드
|
|
|
|
|
* @property string $name 게시판명
|
|
|
|
|
* @property string|null $description 설명
|
|
|
|
|
* @property string $editor_type 에디터 타입
|
|
|
|
|
* @property bool $allow_files 파일 첨부 허용
|
|
|
|
|
* @property int $max_file_count 최대 파일 수
|
|
|
|
|
* @property int $max_file_size 최대 파일 크기 (KB)
|
|
|
|
|
* @property array|null $extra_settings 추가 설정 (권한, 옵션 등)
|
|
|
|
|
* @property bool $is_active 활성 여부
|
|
|
|
|
*
|
2025-08-21 09:50:15 +09:00
|
|
|
* @mixin IdeHelperBoard
|
|
|
|
|
*/
|
2025-07-23 15:41:01 +09:00
|
|
|
class Board extends Model
|
|
|
|
|
{
|
2025-11-30 21:05:33 +09:00
|
|
|
use SoftDeletes;
|
|
|
|
|
|
2025-07-23 15:41:01 +09:00
|
|
|
protected $table = 'boards';
|
2025-11-06 17:45:49 +09:00
|
|
|
|
2025-07-23 15:41:01 +09:00
|
|
|
protected $fillable = [
|
2025-11-30 21:05:33 +09:00
|
|
|
'tenant_id',
|
|
|
|
|
'is_system',
|
|
|
|
|
'board_type',
|
|
|
|
|
'board_code',
|
|
|
|
|
'name',
|
|
|
|
|
'description',
|
|
|
|
|
'editor_type',
|
|
|
|
|
'allow_files',
|
|
|
|
|
'max_file_count',
|
|
|
|
|
'max_file_size',
|
|
|
|
|
'extra_settings',
|
|
|
|
|
'is_active',
|
|
|
|
|
'created_by',
|
|
|
|
|
'updated_by',
|
|
|
|
|
'deleted_by',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'is_system' => 'boolean',
|
|
|
|
|
'is_active' => 'boolean',
|
|
|
|
|
'allow_files' => 'boolean',
|
|
|
|
|
'extra_settings' => 'array',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $attributes = [
|
|
|
|
|
'is_system' => false,
|
|
|
|
|
'is_active' => true,
|
|
|
|
|
'allow_files' => true,
|
|
|
|
|
'max_file_count' => 5,
|
|
|
|
|
'max_file_size' => 20480,
|
|
|
|
|
'editor_type' => 'wysiwyg',
|
2025-07-23 15:41:01 +09:00
|
|
|
];
|
|
|
|
|
|
2025-11-30 21:05:33 +09:00
|
|
|
// =========================================================================
|
|
|
|
|
// Scopes
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 현재 테넌트에서 접근 가능한 게시판
|
|
|
|
|
* - 시스템 게시판 (is_system = true)
|
|
|
|
|
* - 해당 테넌트 게시판 (tenant_id = 현재 테넌트)
|
|
|
|
|
*/
|
|
|
|
|
public function scopeAccessible(Builder $query, int $tenantId): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where(function ($q) use ($tenantId) {
|
|
|
|
|
$q->where('is_system', true)
|
|
|
|
|
->orWhere('tenant_id', $tenantId);
|
|
|
|
|
})->where('is_active', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 시스템 게시판만 (mng용)
|
|
|
|
|
*/
|
|
|
|
|
public function scopeSystemOnly(Builder $query): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('is_system', true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테넌트 게시판만
|
|
|
|
|
*/
|
|
|
|
|
public function scopeTenantOnly(Builder $query, int $tenantId): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('is_system', false)
|
|
|
|
|
->where('tenant_id', $tenantId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 게시판 유형으로 필터링
|
|
|
|
|
*/
|
|
|
|
|
public function scopeOfType(Builder $query, string $type): Builder
|
|
|
|
|
{
|
|
|
|
|
return $query->where('board_type', $type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
// Relationships
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
2025-11-06 17:45:49 +09:00
|
|
|
public function customFields()
|
|
|
|
|
{
|
2025-11-30 21:05:33 +09:00
|
|
|
return $this->hasMany(BoardSetting::class, 'board_id')
|
|
|
|
|
->orderBy('sort_order');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function fields()
|
|
|
|
|
{
|
|
|
|
|
return $this->customFields();
|
2025-07-23 15:41:01 +09:00
|
|
|
}
|
2025-11-06 17:45:49 +09:00
|
|
|
|
|
|
|
|
public function posts()
|
|
|
|
|
{
|
2025-07-23 15:41:01 +09:00
|
|
|
return $this->hasMany(Post::class, 'board_id');
|
|
|
|
|
}
|
2025-11-30 21:05:33 +09:00
|
|
|
|
|
|
|
|
public function tenant()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(\App\Models\Tenant::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function creator()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function updater()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(User::class, 'updated_by');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// =========================================================================
|
|
|
|
|
// Helper Methods
|
|
|
|
|
// =========================================================================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* extra_settings에서 특정 키 값 가져오기
|
|
|
|
|
*/
|
|
|
|
|
public function getSetting(string $key, $default = null)
|
|
|
|
|
{
|
|
|
|
|
return data_get($this->extra_settings, $key, $default);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* extra_settings에 값 설정하기
|
|
|
|
|
*/
|
|
|
|
|
public function setSetting(string $key, $value): self
|
|
|
|
|
{
|
|
|
|
|
$settings = $this->extra_settings ?? [];
|
|
|
|
|
data_set($settings, $key, $value);
|
|
|
|
|
$this->extra_settings = $settings;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 읽기 권한 확인
|
|
|
|
|
*/
|
|
|
|
|
public function canRead(User $user): bool
|
|
|
|
|
{
|
|
|
|
|
$roles = $this->getSetting('permissions.read', ['*']);
|
|
|
|
|
|
|
|
|
|
return in_array('*', $roles) || $user->hasAnyRole($roles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 쓰기 권한 확인
|
|
|
|
|
*/
|
|
|
|
|
public function canWrite(User $user): bool
|
|
|
|
|
{
|
|
|
|
|
$roles = $this->getSetting('permissions.write', ['*']);
|
|
|
|
|
|
|
|
|
|
return in_array('*', $roles) || $user->hasAnyRole($roles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 관리 권한 확인
|
|
|
|
|
*/
|
|
|
|
|
public function canManage(User $user): bool
|
|
|
|
|
{
|
|
|
|
|
$roles = $this->getSetting('permissions.manage', ['admin']);
|
|
|
|
|
|
|
|
|
|
return $user->hasAnyRole($roles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 시스템 게시판 여부 확인
|
|
|
|
|
*/
|
|
|
|
|
public function isSystemBoard(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->is_system === true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 테넌트 게시판 여부 확인
|
|
|
|
|
*/
|
|
|
|
|
public function isTenantBoard(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->is_system === false;
|
|
|
|
|
}
|
2025-07-23 15:41:01 +09:00
|
|
|
}
|