|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Model\Admin\User; |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
use Apps\ActiveRecord\CommentAnswer; |
|
7
|
|
|
use Apps\ActiveRecord\CommentPost; |
|
8
|
|
|
use Apps\ActiveRecord\Content; |
|
9
|
|
|
use Apps\ActiveRecord\ContentRating; |
|
10
|
|
|
use Apps\ActiveRecord\ContentTag; |
|
11
|
|
|
use Apps\ActiveRecord\FeedbackPost; |
|
12
|
|
|
use Apps\ActiveRecord\User; |
|
13
|
|
|
use Apps\ActiveRecord\WallAnswer; |
|
14
|
|
|
use Apps\ActiveRecord\WallPost; |
|
15
|
|
|
use Ffcms\Core\Arch\Model; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class FormUserClear |
|
19
|
|
|
* @package Apps\Model\Admin\User |
|
20
|
|
|
*/ |
|
21
|
|
|
class FormUserClear extends Model |
|
22
|
|
|
{ |
|
23
|
|
|
public $comments; |
|
24
|
|
|
public $content; |
|
25
|
|
|
public $feedback; |
|
26
|
|
|
public $wall; |
|
27
|
|
|
|
|
28
|
|
|
/** @var User */ |
|
29
|
|
|
private $_user; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* FormUserClear constructor. Pass user model inside |
|
33
|
|
|
* @param User $user |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(User $user) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->_user = $user; |
|
38
|
|
|
parent::__construct(true); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Validation rules |
|
43
|
|
|
* @return array |
|
44
|
|
|
*/ |
|
45
|
|
|
public function rules(): array |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
[['comments', 'content', 'feedback', 'wall'], 'required'], |
|
49
|
|
|
[['comments', 'content', 'feedback', 'wall'], 'boolean'] |
|
50
|
|
|
]; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Display labels |
|
55
|
|
|
* @return array |
|
56
|
|
|
*/ |
|
57
|
|
|
public function labels(): array |
|
58
|
|
|
{ |
|
59
|
|
|
return [ |
|
60
|
|
|
'comments' => __('Comments and answers'), |
|
61
|
|
|
'content' => __('Content'), |
|
62
|
|
|
'feedback' => __('Feedback requests'), |
|
63
|
|
|
'wall' => __('Wall posts and answers') |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Make delete |
|
69
|
|
|
* @throws \Exception |
|
70
|
|
|
*/ |
|
71
|
|
|
public function make() |
|
72
|
|
|
{ |
|
73
|
|
|
if ((bool)$this->comments) { |
|
74
|
|
|
CommentPost::where('user_id', $this->_user->id)->delete(); |
|
75
|
|
|
CommentAnswer::where('user_id', $this->_user->id)->delete(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if ((bool)$this->content) { |
|
79
|
|
|
$contents = Content::where('author_id', $this->_user->id); |
|
80
|
|
|
$ids = $contents->pluck('id')->toArray(); |
|
81
|
|
|
if ($ids && count($ids) > 0) { |
|
|
|
|
|
|
82
|
|
|
ContentTag::whereIn('content_id', $ids)->delete(); |
|
83
|
|
|
ContentRating::whereIn('content_id', $ids)->delete(); |
|
84
|
|
|
$contents->delete(); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ((bool)$this->feedback) { |
|
89
|
|
|
FeedbackPost::where('user_id', $this->_user->id) |
|
90
|
|
|
->update(['readed' => true, 'closed' => true]); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if ((bool)$this->wall) { |
|
94
|
|
|
WallPost::where('sender_id', $this->_user->id)->delete(); |
|
95
|
|
|
WallAnswer::where('user_id', $this->_user->id)->delete(); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Get user object |
|
101
|
|
|
* @return User |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getUser() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->_user; |
|
106
|
|
|
} |
|
107
|
|
|
} |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.