1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright (C) 2020-2025 Iain Cambridge |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as published by |
10
|
|
|
* the Free Software Foundation, either version 2.1 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Lesser General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace Parthenon\Payments\Athena; |
23
|
|
|
|
24
|
|
|
use Parthenon\Athena\EntityForm; |
25
|
|
|
use Parthenon\Athena\ListView; |
26
|
|
|
use Parthenon\Athena\ReadView; |
27
|
|
|
use Parthenon\Payments\Entity\Subscription; |
28
|
|
|
use Parthenon\Payments\Plan\Plan; |
29
|
|
|
use Parthenon\Payments\Plan\PlanManagerInterface; |
30
|
|
|
use Parthenon\Payments\Repository\SubscriberRepositoryInterface; |
31
|
|
|
use Parthenon\User\Athena\TeamSection; |
32
|
|
|
use Parthenon\User\Repository\UserRepositoryInterface; |
33
|
|
|
|
34
|
|
|
class UserSubscriberSection extends TeamSection |
35
|
|
|
{ |
36
|
|
|
public function __construct(private SubscriberRepositoryInterface|UserRepositoryInterface $subscriberRepository, private PlanManagerInterface $planManager) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($this->subscriberRepository); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function buildListView(ListView $listView): ListView |
42
|
|
|
{ |
43
|
|
|
$listView = parent::buildListView($listView); |
44
|
|
|
$listView->addField('identifier', 'text', link: true) |
45
|
|
|
->addField('subscription.planName', 'text') |
46
|
|
|
->addField('subscription.status', 'text') |
47
|
|
|
->addField('subscription.validUntil', 'text'); |
48
|
|
|
|
49
|
|
|
return $listView; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function buildEntityForm(EntityForm $entityForm): EntityForm |
53
|
|
|
{ |
54
|
|
|
$entityForm = parent::buildEntityForm($entityForm); |
55
|
|
|
|
56
|
|
|
$planNames = array_map(function (Plan $plan) { |
57
|
|
|
return $plan->getName(); |
58
|
|
|
}, $this->planManager->getPlans()); |
59
|
|
|
|
60
|
|
|
$entityForm->section('plan') |
61
|
|
|
->field('subscription.planName', 'choice', ['choices' => array_combine($planNames, $planNames)]) |
62
|
|
|
->field('subscription.status', 'choice', ['choices' => array_combine(Subscription::STATUS_ARRAY, Subscription::STATUS_ARRAY)]) |
63
|
|
|
->field('subscription.validUntil', 'date') |
64
|
|
|
->end(); |
65
|
|
|
|
66
|
|
|
return $entityForm; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function buildReadView(ReadView $readView): ReadView |
70
|
|
|
{ |
71
|
|
|
$readView = parent::buildReadView($readView); |
72
|
|
|
|
73
|
|
|
$readView->section('plan') |
74
|
|
|
->field('subscription.planName') |
75
|
|
|
->field('subscription.validUntil') |
76
|
|
|
->field('subscription.status') |
77
|
|
|
->end(); |
78
|
|
|
|
79
|
|
|
return $readView; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|