-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User input eraser add, content app imrpove, etc
- Loading branch information
Showing
20 changed files
with
401 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
<?php | |||
|
|||
namespace Apps\Controller\Admin\User; | |||
|
|||
|
|||
use Apps\ActiveRecord\User; | |||
use Apps\Model\Admin\User\FormUserClear; | |||
use Ffcms\Core\App; | |||
use Ffcms\Core\Arch\View; | |||
use Ffcms\Core\Exception\NotFoundException; | |||
use Ffcms\Core\Network\Request; | |||
use Ffcms\Core\Network\Response; | |||
|
|||
/** | |||
* Trait ActionClear | |||
* @package Apps\Controller\Admin\User | |||
* @property Request $request | |||
* @property Response $response | |||
* @property View $view | |||
*/ | |||
trait ActionClear | |||
{ | |||
|
|||
/** Cleanup user added data - content, comments, feedback | |||
* @param string $id | |||
* @return string|null | |||
* @throws NotFoundException | |||
* @throws \Ffcms\Core\Exception\SyntaxException | |||
*/ | |||
public function clear($id): ?string | |||
{ | |||
// find user object by passed id | |||
$user = User::with('profile')->find($id); | |||
if (!$user) { | |||
throw new NotFoundException(__('User not found')); | |||
} | |||
|
|||
// initialize and process form model | |||
$model = new FormUserClear($user); | |||
if ($model->send() && $model->validate()) { | |||
$model->make(); | |||
App::$Session->getFlashBag()->add('success', __('User input data clear successful')); | |||
$this->response->redirect('user/index'); | |||
} | |||
|
|||
// render output view | |||
return $this->view->render('user/user_clear', [ | |||
'model' => $model | |||
]); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,107 @@ | |||
<?php | |||
|
|||
namespace Apps\Model\Admin\User; | |||
|
|||
|
|||
use Apps\ActiveRecord\CommentAnswer; | |||
use Apps\ActiveRecord\CommentPost; | |||
use Apps\ActiveRecord\Content; | |||
use Apps\ActiveRecord\ContentRating; | |||
use Apps\ActiveRecord\ContentTag; | |||
use Apps\ActiveRecord\FeedbackPost; | |||
use Apps\ActiveRecord\User; | |||
use Apps\ActiveRecord\WallAnswer; | |||
use Apps\ActiveRecord\WallPost; | |||
use Ffcms\Core\Arch\Model; | |||
|
|||
/** | |||
* Class FormUserClear | |||
* @package Apps\Model\Admin\User | |||
*/ | |||
class FormUserClear extends Model | |||
{ | |||
public $comments; | |||
public $content; | |||
public $feedback; | |||
public $wall; | |||
|
|||
/** @var User */ | |||
private $_user; | |||
|
|||
/** | |||
* FormUserClear constructor. Pass user model inside | |||
* @param User $user | |||
*/ | |||
public function __construct(User $user) | |||
{ | |||
$this->_user = $user; | |||
parent::__construct(true); | |||
} | |||
|
|||
/** | |||
* Validation rules | |||
* @return array | |||
*/ | |||
public function rules(): array | |||
{ | |||
return [ | |||
[['comments', 'content', 'feedback', 'wall'], 'required'], | |||
[['comments', 'content', 'feedback', 'wall'], 'boolean'] | |||
]; | |||
} | |||
|
|||
/** | |||
* Display labels | |||
* @return array | |||
*/ | |||
public function labels(): array | |||
{ | |||
return [ | |||
'comments' => __('Comments and answers'), | |||
'content' => __('Content'), | |||
'feedback' => __('Feedback requests'), | |||
'wall' => __('Wall posts and answers') | |||
]; | |||
} | |||
|
|||
/** | |||
* Make delete | |||
* @throws \Exception | |||
*/ | |||
public function make() | |||
{ | |||
if ((bool)$this->comments) { | |||
CommentPost::where('user_id', $this->_user->id)->delete(); | |||
CommentAnswer::where('user_id', $this->_user->id)->delete(); | |||
} | |||
|
|||
if ((bool)$this->content) { | |||
$contents = Content::where('author_id', $this->_user->id); | |||
$ids = $contents->pluck('id')->toArray(); | |||
if ($ids && count($ids) > 0) { | |||
ContentTag::whereIn('content_id', $ids)->delete(); | |||
ContentRating::whereIn('content_id', $ids)->delete(); | |||
$contents->delete(); | |||
} | |||
} | |||
|
|||
if ((bool)$this->feedback) { | |||
FeedbackPost::where('user_id', $this->_user->id) | |||
->update(['readed' => true, 'closed' => true]); | |||
} | |||
|
|||
if ((bool)$this->wall) { | |||
WallPost::where('sender_id', $this->_user->id)->delete(); | |||
WallAnswer::where('user_id', $this->_user->id)->delete(); | |||
} | |||
} | |||
|
|||
/** | |||
* Get user object | |||
* @return User | |||
*/ | |||
public function getUser() | |||
{ | |||
return $this->_user; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.