|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin\User; |
|
4
|
|
|
|
|
5
|
|
|
use Apps\Model\Admin\User\FormUserDelete; |
|
6
|
|
|
use Ffcms\Core\App; |
|
7
|
|
|
use Ffcms\Core\Arch\View; |
|
8
|
|
|
use Ffcms\Core\Exception\NotFoundException; |
|
9
|
|
|
use Ffcms\Core\Helper\Type\Any; |
|
10
|
|
|
use Ffcms\Core\Helper\Type\Arr; |
|
11
|
|
|
use Ffcms\Core\Network\Request; |
|
12
|
|
|
use Ffcms\Core\Network\Response; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Trait ActionDelete |
|
16
|
|
|
* @package Apps\Controller\Admin\User |
|
17
|
|
|
* @property Request $request |
|
18
|
|
|
* @property Response $response |
|
19
|
|
|
* @property View $view |
|
20
|
|
|
*/ |
|
21
|
|
|
trait ActionDelete |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Delete user row from database |
|
25
|
|
|
* @param string|null $id |
|
26
|
|
|
* @return string |
|
27
|
|
|
* @throws \Exception |
|
28
|
|
|
*/ |
|
29
|
|
|
public function delete(?string $id = null): ?string |
|
30
|
|
|
{ |
|
31
|
|
|
// check if id is passed or get data from GET as array ids |
|
32
|
|
|
if (!Any::isInt($id) || $id < 1) { |
|
33
|
|
|
$ids = $this->request->query->get('selected'); |
|
34
|
|
|
if (!Any::isArray($ids) || !Arr::onlyNumericValues($ids)) { |
|
35
|
|
|
throw new NotFoundException('Bad conditions'); |
|
36
|
|
|
} |
|
37
|
|
|
$id = $ids; |
|
38
|
|
|
} else { |
|
39
|
|
|
$id = [$id]; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
// initialize delete model |
|
43
|
|
|
$model = new FormUserDelete($id); |
|
44
|
|
|
|
|
45
|
|
|
// check if users is found |
|
46
|
|
|
if ($model->users === null) { |
|
47
|
|
|
throw new NotFoundException(__('Users are not found')); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
// check if delete is submited |
|
51
|
|
|
if ($model->send() && $model->validate()) { |
|
52
|
|
|
$model->delete(); |
|
53
|
|
|
App::$Session->getFlashBag()->add('success', __('Users and them data are successful removed')); |
|
54
|
|
|
$this->response->redirect('user/index'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// set view response |
|
58
|
|
|
return $this->view->render('user_delete', [ |
|
59
|
|
|
'model' => $model |
|
60
|
|
|
]); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|