Blame view

backend/modules/user/controllers/OwnprofileController.php 1.82 KB
d1f8bd40   Alexey Boroda   first commit
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
  <?php
  
  namespace backend\modules\user\controllers;
  
  use Yii;
  use yii\web\NotFoundHttpException;
  //
  use thread\app\base\controllers\BackendController;
  use thread\actions\Update;
  use thread\actions\fileapi\{
      DeleteAction, UploadAction
  };
  //
  use backend\modules\user\models\{
      Profile
  };
  
  /**
   * Class OwnprofileController
   *
   * @package backend\modules\user\controllers
   * @author FilamentV <vortex.filament@gmail.com>
   * @copyright (c), Thread
   */
  class OwnprofileController extends BackendController
  {
      public $name = 'ownprofile';
      public $title = "Profile";
      protected $model = Profile::class;
      public $defaultAction = 'update';
      public $actionListLinkStatus = ['/user/user/list'];
  
      /**
       * @return mixed
       * @throws NotFoundHttpException
       * @throws \Exception
       */
      public function init()
      {
  
          if (Yii::$app->getRequest()->get('id') != Yii::$app->getUser()->id) {
              throw new NotFoundHttpException();
          }
  
          return parent::init();
      }
  
      /**
       *
       * @return array
       */
      public function actions()
      {
          $model = Profile::findByUserId(Yii::$app->getUser()->id);
          $user = $model->user;
  
          return [
              'update' => [
                  'class' => Update::class,
                  'modelClass' => $this->model,
                  'redirect' => function () {
                      return $_POST['save_and_exit'] ? ['/user/user/list'] : ['update', 'id' => $this->action->getModel()->id];
                  }
              ],
              'fileupload' => [
                  'class' => UploadAction::class,
                  'path' => $this->module->getAvatarUploadPath($user)
              ],
              'filedelete' => [
                  'class' => DeleteAction::class,
                  'path' => $this->module->getAvatarUploadPath($user)
              ],
          ];
      }
  }