1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Pratiksh\Adminetic\Http\Livewire\Admin\Activity; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
|
|
|
|
6
|
|
|
use Carbon\Carbon; |
7
|
|
|
use Livewire\Component; |
8
|
|
|
use Livewire\WithPagination; |
9
|
|
|
use Spatie\Activitylog\Models\Activity; |
10
|
|
|
|
11
|
|
|
class ActivityTable extends Component |
12
|
|
|
{ |
13
|
|
|
use WithPagination; |
14
|
|
|
|
15
|
|
|
protected $paginationTheme = 'bootstrap'; |
16
|
|
|
|
17
|
|
|
public $log_name; |
18
|
|
|
public $log_names; |
19
|
|
|
|
20
|
|
|
public $description; |
21
|
|
|
|
22
|
|
|
public $model; |
23
|
|
|
public $models; |
24
|
|
|
|
25
|
|
|
public $user_id; |
26
|
|
|
public $users; |
27
|
|
|
public $descriptions; |
28
|
|
|
|
29
|
|
|
public $start_date; |
30
|
|
|
public $end_date; |
31
|
|
|
public $data; |
32
|
|
|
public $interval = 30; |
33
|
|
|
public $to_from = 1; |
34
|
|
|
public $delete_limit = 30; |
35
|
|
|
|
36
|
|
|
public $activity_count = 0; |
37
|
|
|
|
38
|
|
|
protected $listeners = ['date_range_filter' => 'dateRangeFilter', 'date_filter' => 'dateFilter']; |
39
|
|
|
|
40
|
|
|
public function mount($model = null) |
41
|
|
|
{ |
42
|
|
|
$this->model = $model; |
43
|
|
|
$activities = Activity::all(); |
44
|
|
|
$this->descriptions = !is_null($activities) ? array_unique($activities->pluck('description')->toArray()) : null; |
45
|
|
|
$this->log_names = array_unique($activities->pluck('log_name')->toArray()); |
46
|
|
|
$this->models = array_unique($activities->pluck('subject_type')->toArray()); |
47
|
|
|
$this->users = User::find($activities->pluck('causer_id')->toArray()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function deleteAll() |
51
|
|
|
{ |
52
|
|
|
Activity::truncate(); |
53
|
|
|
$this->emit('activity_success', 'All Activities Deleted Successfully'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function deleteWithLimit() |
57
|
|
|
{ |
58
|
|
|
if (!is_null($this->delete_limit)) { |
|
|
|
|
59
|
|
|
Activity::whereDate('created_at', '<', Carbon::now()->subDays($this->delete_limit))->delete(); |
60
|
|
|
$this->emit('activity_success', 'All activities Deleted except last ' . $this->delete_limit . 'days activities'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function dateFilter($date) |
65
|
|
|
{ |
66
|
|
|
$date = Carbon::create($date); |
67
|
|
|
$to_from = $this->to_from; |
68
|
|
|
|
69
|
|
|
if ($to_from == 1) { |
70
|
|
|
$this->start_date = $date; |
71
|
|
|
$this->end_date = $date->addDays($this->interval ?? 30); |
72
|
|
|
} elseif ($to_from == 2) { |
73
|
|
|
$this->end_date = $date; |
74
|
|
|
$this->start_date = $date->subDays($this->interval ?? 30); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function dateRangeFilter($start_date, $end_date) |
79
|
|
|
{ |
80
|
|
|
$this->start_date = Carbon::create($start_date); |
81
|
|
|
$this->end_date = Carbon::create($end_date); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function deleteActivity(Activity $activity) |
85
|
|
|
{ |
86
|
|
|
$activity->delete(); |
87
|
|
|
$this->emit('activity_success', 'Activity Deleted Successfully'); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function updated() |
91
|
|
|
{ |
92
|
|
|
$this->resetPage(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function render() |
96
|
|
|
{ |
97
|
|
|
$activities = $this->getActivities(); |
98
|
|
|
|
99
|
|
|
return view('adminetic::livewire.admin.activity.activity-table', compact('activities')); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
private function getActivities() |
103
|
|
|
{ |
104
|
|
|
$data = Activity::query(); |
105
|
|
|
// Filter By Log Name |
106
|
|
|
if (!is_null($this->log_name)) { |
107
|
|
|
$data = $data->where('log_name', $this->log_name); |
108
|
|
|
} |
109
|
|
|
// Filter By Model |
110
|
|
|
if (!is_null($this->model)) { |
111
|
|
|
$data = $data->where('subject_type', $this->model); |
112
|
|
|
} |
113
|
|
|
// Filter By User |
114
|
|
|
if (!is_null($this->user_id)) { |
115
|
|
|
$data = $data->where('causer_id', $this->user_id); |
116
|
|
|
} |
117
|
|
|
// Filter By Date |
118
|
|
|
if (!is_null($this->start_date) && !is_null($this->end_date)) { |
119
|
|
|
$data = $data->whereDate('created_at', [$this->start_date, $this->end_date]); |
120
|
|
|
} |
121
|
|
|
// Filter Description |
122
|
|
|
if (!is_null($this->description)) { |
123
|
|
|
$data = $data->where('description', $this->description); |
124
|
|
|
} |
125
|
|
|
$this->activity_count = with($data)->count(); |
126
|
|
|
$this->emit('initialize_activity'); |
127
|
|
|
|
128
|
|
|
return |
129
|
|
|
$data->latest()->paginate(10); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function resetActivities() |
133
|
|
|
{ |
134
|
|
|
$this->log_name = null; |
135
|
|
|
$this->model = null; |
136
|
|
|
$this->user_id = null; |
137
|
|
|
$this->start_date = null; |
138
|
|
|
$this->end_date = null; |
139
|
|
|
$this->description = null; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths