mkey.remarks

  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
107
108
109
<?php
/*
Зоны:
1 - весь сайт(блок)
Причины:
1 - Грубость и оскорбления
2 - СПАМ, реклама
3 - Педофилия
4 - Иное
*/
class Remark {
static function add($user_id, $zone, $active_time, $moder, $comment, $reason, $inf = false) {
$time = time();
// Для бесконечного блока
if($inf) {
$stmt = DB::getInstance()->prepare("
UPDATE `users` SET `die` = 1 WHERE `id` = ? LIMIT 1
");
$stmt->bind_param('i', $user_id);
$stmt->execute();
$stmt->close();
}
# Отправляем запрос на добавление
$stmt = DB::getInstance()->prepare("
INSERT INTO `remarks` (`user_id`, `zone`, `active_time`, `moder`, `comment`, `reason`, `add_time`)
VALUES (?, ?, ?, ?, ?, ?, ?)
");
$stmt->bind_param('iiiisii', $user_id, $zone, $active_time, $moder, $comment, $reason, $time);
$stmt->execute();
$remark_id = $stmt->insert_id;
$stmt->close();
UserCounter::up($user_id, 'remarks', 1);
return $remark_id;
}
static function del($remark_id) {
$stmt = DB::getInstance()->prepare("
DELETE FROM `remarks` WHERE `id` = ?
");
$stmt->bind_param('i', $remark_id);
$stmt->execute();
$stmt->close();
}
static function getInfo($remark_id) {
$result = DB::getInstance() -> query("
SELECT * FROM `remarks` WHERE `id` = '{$remark_id}' LIMIT 1
");
$data = $result->fetch_assoc();
if(!empty($data)) return $data;
else return false;
}
static function getList($user_id) {
$result = DB::getInstance() -> query("
SELECT `id`, `zone`, `add_time`, `active_time` FROM `remarks`
WHERE `user_id` = {$user_id} ORDER BY `id` DESC
");
$remarks = [];
while($row = $result -> fetch_assoc()) $remarks[] = $row;
return $remarks;
}
static function getActiveBlock($user_id) {
$time = time();
$result = DB::getInstance() -> query("
SELECT * FROM `remarks`
WHERE `user_id` = {$user_id} AND `zone` = 1 AND `active_time` > {$time} - `add_time`
ORDER BY `id` DESC LIMIT 1
");
$data = $result->fetch_assoc();
if(!empty($data)) return $data;
else return false;
}
static function zone($zone) {
switch($zone) {
case 1: return 'Блок';
}
}
static function reason($reason) {
switch($reason) {
case 1: return 'Грубость и оскорбления';
case 2: return 'СПАМ, реклама';
case 3: return 'Педофилия';
case 4: return 'Иное';
}
}
static function isActive($add_time, $active_time) {
return (time() - $add_time > $active_time) ? false : true;
}
static function leftTime($add_time, $active_time) {
return $active_time - (time() - $add_time);
}
}
?>