|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Newbb; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* NewBB 5.0x, the forum module for XOOPS project |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
9
|
|
|
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html) |
|
10
|
|
|
* @author Taiwen Jiang (phppp or D.J.) <[email protected]> |
|
11
|
|
|
* @since 4.00 |
|
12
|
|
|
* @package module::newbb |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
\defined('NEWBB_FUNCTIONS_INI') || require $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php'); |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class ReportHandler |
|
21
|
|
|
*/ |
|
22
|
|
|
class ReportHandler extends \XoopsPersistableObjectHandler |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @param \XoopsDatabase|null $db |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
28
|
|
|
{ |
|
29
|
|
|
parent::__construct($db, 'newbb_report', Report::class, 'report_id', ''); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param $posts |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getByPost($posts) |
|
37
|
|
|
{ |
|
38
|
|
|
$ret = []; |
|
39
|
|
|
if (!$posts) { |
|
40
|
|
|
return $ret; |
|
41
|
|
|
} |
|
42
|
|
|
if (!\is_array($posts)) { |
|
43
|
|
|
$posts = [$posts]; |
|
44
|
|
|
} |
|
45
|
|
|
$post_criteria = new \Criteria('post_id', '(' . \implode(', ', $posts) . ')', 'IN'); |
|
46
|
|
|
$ret = $this->getAll($post_criteria); |
|
47
|
|
|
|
|
48
|
|
|
return $ret; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param int|array $forums |
|
53
|
|
|
* @param string $order |
|
54
|
|
|
* @param int $perpage |
|
55
|
|
|
* @param $start |
|
56
|
|
|
* @param int $report_result |
|
57
|
|
|
* @param int $reportId |
|
58
|
|
|
* @return array |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getAllReports($forums = 0, $order = 'ASC', $perpage = 0, &$start, $report_result = 0, $reportId = 0) |
|
61
|
|
|
{ |
|
62
|
|
|
$forumCriteria = ''; |
|
63
|
|
|
$row = []; |
|
64
|
|
|
if ('DESC' === $order) { |
|
65
|
|
|
$operator_for_position = '>'; |
|
66
|
|
|
} else { |
|
67
|
|
|
$order = 'ASC'; |
|
68
|
|
|
$operator_for_position = '<'; |
|
69
|
|
|
} |
|
70
|
|
|
$order_criteria = " ORDER BY r.report_id $order"; |
|
71
|
|
|
|
|
72
|
|
|
if ($perpage <= 0) { |
|
73
|
|
|
$perpage = 10; |
|
74
|
|
|
} |
|
75
|
|
|
if (empty($start)) { |
|
76
|
|
|
$start = 0; |
|
77
|
|
|
} |
|
78
|
|
|
$result_criteria = ' AND r.report_result = ' . $report_result; |
|
79
|
|
|
|
|
80
|
|
|
if ($forums) { |
|
81
|
|
|
$forumCriteria = ''; |
|
82
|
|
|
} elseif (!\is_array($forums)) { |
|
83
|
|
|
$forums = [$forums]; |
|
84
|
|
|
$forumCriteria = ' AND p.forum_id IN (' . \implode(',', $forums) . ')'; |
|
85
|
|
|
} |
|
86
|
|
|
$tables_criteria = ' FROM ' . $this->db->prefix('newbb_report') . ' r, ' . $this->db->prefix('newbb_posts') . ' p WHERE r.post_id= p.post_id'; |
|
87
|
|
|
|
|
88
|
|
|
if ($reportId) { |
|
89
|
|
|
$result = $this->db->query('SELECT COUNT(*) as report_count' . $tables_criteria . $forumCriteria . $result_criteria . " AND report_id $operator_for_position $reportId" . $order_criteria); |
|
90
|
|
|
if ($result) { |
|
91
|
|
|
$row = $this->db->fetchArray($result); |
|
92
|
|
|
} |
|
93
|
|
|
$position = $row['report_count']; |
|
94
|
|
|
$start = (int)($position / $perpage) * $perpage; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$sql = 'SELECT r.*, p.subject, p.topic_id, p.forum_id' . $tables_criteria . $forumCriteria . $result_criteria . $order_criteria; |
|
98
|
|
|
$result = $this->db->query($sql, $perpage, $start); |
|
99
|
|
|
$ret = []; |
|
100
|
|
|
//$reportHandler = Newbb\Helper::getInstance()->getHandler('Report'); |
|
101
|
|
|
while (false !== ($myrow = $this->db->fetchArray($result))) { |
|
102
|
|
|
$ret[] = $myrow; // return as array |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
return $ret; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @return bool|void |
|
110
|
|
|
*/ |
|
111
|
|
|
public function synchronization() |
|
112
|
|
|
{ |
|
113
|
|
|
// return; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* clean orphan items from database |
|
118
|
|
|
* |
|
119
|
|
|
* @param string $table_link |
|
120
|
|
|
* @param string $field_link |
|
121
|
|
|
* @param string $field_object |
|
122
|
|
|
* @return bool true on success |
|
123
|
|
|
*/ |
|
124
|
|
|
public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan() |
|
125
|
|
|
{ |
|
126
|
|
|
return parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id'); |
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|