WowPress-Tailwind/theme/wowpress/Models/Complaint.php

48 lines
1.1 KiB
PHP
Raw Normal View History

2024-06-19 21:10:42 +02:00
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
class Complaint extends Model{
protected $table = "wowpress_complaints";
public $timestamps = true;
2024-06-19 21:10:42 +02:00
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public static function getAll(){
if(current_user_can('wowpress_edit_complaints')){
return static::all()->sortBy(fn ($a) => $a->deleted_at);
}else{
return static::where('user_id',get_current_user_id())
->where('deleted_at',null)
->get();
}
}
public function canTrash(){
return current_user_can('wowpress_edit_complaints') || $this->user_id == get_current_user_id();
}
public function trash(){
$this->deleted_at = date('Y-m-d H:i:s');
$this->save();
}
public function restore(){
$this->deleted_at = null;
$this->save();
}
public function user(){
return $this->belongsTo(User::class);
}
public function canEdit(){
return current_user_can('wowpress_edit_complaints') && (get_current_user_id() != $this->user_id);
}
2024-06-19 21:10:42 +02:00
}