User::addCustomAssets()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Admin\Http\Controllers\Admin\Form;
6
7
use AbterPhp\Admin\Domain\Entities\User as Entity;
8
use AbterPhp\Admin\Domain\Entities\UserLanguage;
9
use AbterPhp\Admin\Form\Factory\User as FormFactory;
10
use AbterPhp\Admin\Http\Controllers\Admin\FormAbstract;
11
use AbterPhp\Admin\Orm\UserRepo as Repo;
12
use AbterPhp\Framework\Assets\AssetManager;
13
use AbterPhp\Framework\Domain\Entities\IStringerEntity;
14
use AbterPhp\Framework\I18n\ITranslator;
15
use AbterPhp\Framework\Session\FlashService;
16
use Cocur\Slugify\Slugify;
17
use League\Flysystem\FilesystemException;
18
use Opulence\Events\Dispatchers\IEventDispatcher;
19
use Opulence\Routing\Urls\UrlGenerator;
20
use Opulence\Sessions\ISession;
21
use Psr\Log\LoggerInterface;
22
23
/**
24
 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
25
 */
26
class User extends FormAbstract
27
{
28
    public const ENTITY_PLURAL   = 'users';
29
    public const ENTITY_SINGULAR = 'user';
30
31
    public const ENTITY_TITLE_SINGULAR = 'admin:user';
32
    public const ENTITY_TITLE_PLURAL   = 'admin:users';
33
34
    public const VAR_ALL_USER_GROUPS    = 'allUserGroups';
35
    public const VAR_ALL_USER_LANGUAGES = 'allUserLanguages';
36
37
    protected Slugify $slugify;
38
39
    protected AssetManager $assetManager;
40
41
    protected string $frontendSalt;
42
43
    protected string $resource = 'users';
44
45
    /**
46
     * User constructor.
47
     *
48
     * @param FlashService     $flashService
49
     * @param LoggerInterface  $logger
50
     * @param ITranslator      $translator
51
     * @param UrlGenerator     $urlGenerator
52
     * @param Repo             $repo
53
     * @param ISession         $session
54
     * @param FormFactory      $formFactory
55
     * @param IEventDispatcher $eventDispatcher
56
     * @param AssetManager     $assetManager
57
     * @param string           $frontendSalt
58
     */
59
    public function __construct(
60
        FlashService $flashService,
61
        LoggerInterface $logger,
62
        ITranslator $translator,
63
        UrlGenerator $urlGenerator,
64
        Repo $repo,
65
        ISession $session,
66
        FormFactory $formFactory,
67
        IEventDispatcher $eventDispatcher,
68
        AssetManager $assetManager,
69
        string $frontendSalt
70
    ) {
71
        parent::__construct(
72
            $flashService,
73
            $logger,
74
            $translator,
75
            $urlGenerator,
76
            $repo,
77
            $session,
78
            $formFactory,
79
            $eventDispatcher
80
        );
81
82
        $this->assetManager = $assetManager;
83
        $this->frontendSalt = $frontendSalt;
84
    }
85
86
    /**
87
     * @param string $entityId
88
     *
89
     * @return Entity
90
     */
91
    public function createEntity(string $entityId): IStringerEntity
92
    {
93
        $userLanguage = new UserLanguage(
94
            '',
95
            '',
96
            ''
97
        );
98
99
        return new Entity(
100
            $entityId,
101
            '',
102
            '',
103
            '',
104
            true,
105
            true,
106
            $userLanguage
107
        );
108
    }
109
110
    /**
111
     * @param IStringerEntity|null $entity
112
     *
113
     * @throws FilesystemException
114
     */
115
    protected function addCustomAssets(?IStringerEntity $entity = null)
116
    {
117
        parent::addCustomAssets($entity);
118
119
        $footer = $this->getResourceName(static::RESOURCE_FOOTER);
120
121
        $this->assetManager->addJs($footer, '/admin-assets/vendor/sha3/sha3.js');
122
        $this->assetManager->addJsVar($footer, 'frontendSalt', $this->frontendSalt);
123
        $this->assetManager->addJs($footer, '/admin-assets/vendor/zxcvbn/zxcvbn.min.js');
124
        $this->assetManager->addJs($footer, '/admin-assets/js/user.js');
125
        $this->assetManager->addJs($footer, '/admin-assets/js/required.js');
126
        $this->assetManager->addJs($footer, '/admin-assets/js/validation.js');
127
    }
128
}
129