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

48 lines
1.1 KiB
PHP
Raw Permalink 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())
2024-09-20 09:43:17 +02:00
->where('deleted_at','0000-00-00 00:00:00')
->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(){
2024-06-27 23:06:15 +02:00
return current_user_can('wowpress_edit_complaints');# && (get_current_user_id() != $this->user_id);
}
2024-06-19 21:10:42 +02:00
}