-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathReports.php
More file actions
106 lines (89 loc) · 3.88 KB
/
Reports.php
File metadata and controls
106 lines (89 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Model\Admin;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\User;
class Reports
{
public function zap($zapId)
{
$zapId = Hooks::fire('model.admin.reports.zap_report.zap_id', $zapId);
$result = DB::table('reports')->where('id', $zapId);
$result = Hooks::fireDB('model.admin.reports.zap_report.query', $result);
$result = $result->findOneCol('zapped');
$setZapReport = ['zapped' => time(), 'zapped_by' => User::get()->id];
$setZapReport = Hooks::fire('model.admin.reports.set_zap_report', $setZapReport);
// Update report to indicate it has been zapped
if (!$result) {
DB::table('reports')
->where('id', $zapId)
->findOne()
->set($setZapReport)
->save();
}
// Remove zapped reports to keep only last 10
$threshold = DB::table('reports')
->whereNotNull('zapped')
->orderByDesc('zapped')
->offset(10)
->limit(1)
->findOneCol('zapped');
if ($threshold) {
DB::table('reports')
->whereLte('zapped', $threshold)
->deleteMany();
}
return true;
}
public static function hasReports()
{
Hooks::fire('get_reports_start');
$resultHeader = DB::table('reports')->whereNull('zapped');
$resultHeader = Hooks::fireDB('get_reports_query', $resultHeader);
return (bool) $resultHeader->findOne();
}
public function reports()
{
$reports = [];
$selectReports = ['r.id', 'r.topic_id', 'r.forum_id', 'r.reported_by', 'r.created', 'r.message', 'pid' => 'p.id', 't.subject', 'f.forum_name', 'reporter' => 'u.username'];
$reports = DB::table('reports')
->tableAlias('r')
->selectMany($selectReports)
->leftOuterJoin('posts', ['r.post_id', '=', 'p.id'], 'p')
->leftOuterJoin('topics', ['r.topic_id', '=', 't.id'], 't')
->leftOuterJoin('forums', ['r.forum_id', '=', 'f.id'], 'f')
->leftOuterJoin('users', ['r.reported_by', '=', 'u.id'], 'u')
->whereNull('r.zapped')
->orderByDesc('created');
$reports = Hooks::fireDB('model.admin.reports.get_reports.query', $reports);
$reports = $reports->findArray();
$reports = Hooks::fire('model.admin.reports.get_reports', $reports);
return $reports;
}
public function zappedReports()
{
$zappedReports = [];
$selectZappedReports = ['r.id', 'r.topic_id', 'r.forum_id', 'r.reported_by', 'r.message', 'r.zapped', 'zapped_by_id' => 'r.zapped_by', 'pid' => 'p.id', 't.subject', 'f.forum_name', 'reporter' => 'u.username', 'zapped_by' => 'u2.username'];
$zappedReports = DB::table('reports')
->tableAlias('r')
->selectMany($selectZappedReports)
->leftOuterJoin('posts', ['r.post_id', '=', 'p.id'], 'p')
->leftOuterJoin('topics', ['r.topic_id', '=', 't.id'], 't')
->leftOuterJoin('forums', ['r.forum_id', '=', 'f.id'], 'f')
->leftOuterJoin('users', ['r.reported_by', '=', 'u.id'], 'u')
->leftOuterJoin('users', ['r.zapped_by', '=', 'u2.id'], 'u2')
->whereNotNull('r.zapped')
->orderByDesc('zapped')
->limit(10);
$zappedReports = Hooks::fireDB('model.admin.reports.get_zapped_reports.query', $zappedReports);
$zappedReports = $zappedReports->findArray();
$zappedReports = Hooks::fire('model.admin.reports.get_zapped_reports', $zappedReports);
return $zappedReports;
}
}