1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Apps\Controller\Admin\Profile; |
4
|
|
|
|
5
|
|
|
use Apps\ActiveRecord\Profile; |
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\Network\Request; |
11
|
|
|
use Ffcms\Core\Network\Response; |
12
|
|
|
use Apps\Model\Front\Profile\FormSettings as FrontFormSettings; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Trait ActionUpdate |
16
|
|
|
* @package Apps\Controller\Admin\Profile |
17
|
|
|
* @property Request $request |
18
|
|
|
* @property Response $response |
19
|
|
|
* @property View $view |
20
|
|
|
*/ |
21
|
|
|
trait ActionUpdate |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Edit user profile action |
25
|
|
|
* @param string $id |
26
|
|
|
* @return null|string |
27
|
|
|
* @throws NotFoundException |
28
|
|
|
* @throws \Ffcms\Core\Exception\SyntaxException |
29
|
|
|
*/ |
30
|
|
|
public function profileUpdate($id): ?string |
31
|
|
|
{ |
32
|
|
|
if (!Any::isInt($id) || $id < 1) { |
33
|
|
|
throw new NotFoundException(__('Wrong profile query id')); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// get user profile via id |
37
|
|
|
$profile = Profile::find($id); |
38
|
|
|
if (!$profile) { |
39
|
|
|
throw new NotFoundException(__('User profile with id %id% not exist', ['id' => $id])); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
// check if user id for this profile_id is exist |
43
|
|
|
if (!App::$User->isExist($profile->user_id)) { |
44
|
|
|
throw new NotFoundException(__('User record not found: %id%', ['id' => $profile->user_id])); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
// initialize settings form and process it |
48
|
|
|
$model = new FrontFormSettings($profile->user); |
49
|
|
|
if ($model->send() && $model->validate()) { |
50
|
|
|
$model->save(); |
51
|
|
|
App::$Session->getFlashBag()->add('success', __('Profile is updated')); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $this->view->render('profile/update', [ |
55
|
|
|
'model' => $model, |
56
|
|
|
'profile' => $profile |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
} |