Passed
Push — main ( 6e6ff6...082362 )
by Iain
05:02
created

SubscriptionPlanSection::preSave()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright Iain Cambridge 2020-2023.
7
 *
8
 * Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license.
9
 *
10
 * Change Date: TBD ( 3 years after 2.2.0 release )
11
 *
12
 * On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file.
13
 */
14
15
namespace Parthenon\Billing\Athena;
16
17
use Parthenon\Athena\AbstractSection;
18
use Parthenon\Athena\EntityForm;
19
use Parthenon\Athena\ListView;
20
use Parthenon\Athena\Repository\CrudRepositoryInterface;
21
use Parthenon\Billing\Entity\SubscriptionPlan;
22
use Parthenon\Billing\Form\Type\SubscriptionPlanLimitType;
23
use Parthenon\Billing\Repository\SubscriptionLimitRepositoryInterface;
24
use Parthenon\Billing\Repository\SubscriptionPlanRepositoryInterface;
25
26
class SubscriptionPlanSection extends AbstractSection
27
{
28
    public function __construct(
29
        private SubscriptionPlanRepositoryInterface $subscriptionPlanRepository,
30
        private SubscriptionLimitRepositoryInterface $subscriptionLimitRepository,
31
    ) {
32
    }
33
34
    public function getUrlTag(): string
35
    {
36
        return 'billing-subscription-plan';
37
    }
38
39
    public function getRepository(): CrudRepositoryInterface
40
    {
41
        return $this->subscriptionPlanRepository;
42
    }
43
44
    public function getEntity()
45
    {
46
        return new SubscriptionPlan();
47
    }
48
49
    public function getMenuSection(): string
50
    {
51
        return 'Billing';
52
    }
53
54
    public function getMenuName(): string
55
    {
56
        return 'Subscription Plan';
57
    }
58
59
    public function buildEntityForm(EntityForm $entityForm): EntityForm
60
    {
61
        $choices = $this->subscriptionLimitRepository->getAll();
62
63
        $entityForm->section('Main')
64
                ->field('name', 'text')
65
                ->field('public', 'checkbox')
66
                ->field('external_reference', 'text', ['required' => false])
67
                ->field('is_free', 'checkbox')
68
                ->field('is_per_seat', 'checkbox')
69
                ->field('user_count', 'text')
70
            ->end()
71
            ->section('Limits')
72
                ->field('limits', 'collection',
73
                    [
74
                        'entry_type' => SubscriptionPlanLimitType::class,
75
                        'entry_options' => [
76
                            'label' => false,
77
                            'choices' => $choices,
78
                        ],
79
                        'allow_add' => true,
80
                        'allow_delete' => true,
81
                        'by_reference' => false,
82
                        'delete_empty' => true,
83
                    ]
84
                )
85
            ->end();
86
87
        return $entityForm;
88
    }
89
90
    public function buildListView(ListView $listView): ListView
91
    {
92
        $listView->addField('name', 'text');
93
94
        return $listView;
95
    }
96
}
97