Passed
Push — 1.11.x ( 4d8435...e590f3 )
by Angel Fernando Quiroz
11:50
created

FrmAdd::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\PluginBundle\LtiProvider\Form;
5
6
use Chamilo\PluginBundle\Entity\LtiProvider\Platform;
7
use FormValidator;
8
use LtiProviderPlugin;
9
10
/**
11
 * Class FrmAdd.
12
 */
13
class FrmAdd extends FormValidator
14
{
15
    /**
16
     * @var Platform|null
17
     */
18
    private $platform;
19
20
    /**
21
     * FrmAdd constructor.
22
     */
23
    public function __construct(
24
        string $name,
25
        array $attributes = [],
26
        Platform $platform = null
27
    ) {
28
        parent::__construct($name, 'POST', '', '', $attributes, self::LAYOUT_HORIZONTAL);
29
30
        $this->platform = $platform;
31
    }
32
33
    /**
34
     * Build the form.
35
     */
36
    public function build(): void
37
    {
38
        $plugin = LtiProviderPlugin::create();
39
40
        $this->addHeader($plugin->get_lang('ConnectionDetails'));
41
42
        $this->addText('issuer', $plugin->get_lang('PlatformName'));
43
        $this->addUrl('auth_login_url', $plugin->get_lang('AuthLoginUrl'));
44
        $this->addUrl('auth_token_url', $plugin->get_lang('AuthTokenUrl'));
45
        $this->addUrl('key_set_url', $plugin->get_lang('KeySetUrl'));
46
        $this->addText('client_id', $plugin->get_lang('ClientId'));
47
        $this->addText('deployment_id', $plugin->get_lang('DeploymentId'));
48
        $this->addText('kid', $plugin->get_lang('KeyId'));
49
50
        $this->addButtonCreate($plugin->get_lang('AddPlatform'));
51
        $this->applyFilter('__ALL__', 'trim');
52
    }
53
54
    public function setDefaultValues(): void
55
    {
56
        $defaults = [];
57
58
        if (!$this->platform) {
59
            $this->platform = new Platform();
60
        }
61
62
        $defaults['issuer'] = $this->platform->getIssuer();
63
        $defaults['auth_login_url'] = $this->platform->getAuthLoginUrl();
64
        $defaults['auth_token_url'] = $this->platform->getAuthTokenUrl();
65
        $defaults['key_set_url'] = $this->platform->getKeySetUrl();
66
        $defaults['client_id'] = $this->platform->getClientId();
67
        $defaults['deployment_id'] = $this->platform->getDeploymentId();
68
        $defaults['kid'] = $this->platform->getKid();
69
70
        $this->setDefaults($defaults);
71
    }
72
}
73