|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* Copyright Humbly Arrogant Ltd 2020-2022. |
|
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.0.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\Subscriptions\Athena; |
|
16
|
|
|
|
|
17
|
|
|
use Parthenon\Athena\EntityForm; |
|
18
|
|
|
use Parthenon\Athena\ListView; |
|
19
|
|
|
use Parthenon\Athena\ReadView; |
|
20
|
|
|
use Parthenon\Subscriptions\Entity\Subscription; |
|
21
|
|
|
use Parthenon\Subscriptions\Plan\Plan; |
|
22
|
|
|
use Parthenon\Subscriptions\Plan\PlanManagerInterface; |
|
23
|
|
|
use Parthenon\Subscriptions\Repository\SubscriberRepositoryInterface; |
|
24
|
|
|
use Parthenon\User\Athena\TeamSection; |
|
25
|
|
|
use Parthenon\User\Repository\UserRepositoryInterface; |
|
26
|
|
|
|
|
27
|
|
|
class UserSubscriberSection extends TeamSection |
|
28
|
|
|
{ |
|
29
|
|
|
public function __construct(private SubscriberRepositoryInterface|UserRepositoryInterface $subscriberRepository, private PlanManagerInterface $planManager) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($this->subscriberRepository); |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function buildListView(ListView $listView): ListView |
|
35
|
|
|
{ |
|
36
|
|
|
$listView = parent::buildListView($listView); |
|
37
|
|
|
$listView->addField('identifier', 'text', link: true) |
|
38
|
|
|
->addField('subscription.planName', 'text') |
|
39
|
|
|
->addField('subscription.status', 'text') |
|
40
|
|
|
->addField('subscription.validUntil', 'text'); |
|
41
|
|
|
|
|
42
|
|
|
return $listView; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function buildEntityForm(EntityForm $entityForm): EntityForm |
|
46
|
|
|
{ |
|
47
|
|
|
$entityForm = parent::buildEntityForm($entityForm); |
|
48
|
|
|
|
|
49
|
|
|
$planNames = array_map(function (Plan $plan) { |
|
50
|
|
|
return $plan->getName(); |
|
51
|
|
|
}, $this->planManager->getPlans()); |
|
52
|
|
|
|
|
53
|
|
|
$entityForm->section('plan') |
|
54
|
|
|
->field('subscription.planName', 'choice', ['choices' => array_combine($planNames, $planNames)]) |
|
55
|
|
|
->field('subscription.status', 'choice', ['choices' => array_combine(Subscription::STATUS_ARRAY, Subscription::STATUS_ARRAY)]) |
|
56
|
|
|
->field('subscription.validUntil', 'date') |
|
57
|
|
|
->end(); |
|
58
|
|
|
|
|
59
|
|
|
return $entityForm; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function buildReadView(ReadView $readView): ReadView |
|
63
|
|
|
{ |
|
64
|
|
|
$readView = parent::buildReadView($readView); |
|
65
|
|
|
|
|
66
|
|
|
$readView->section('plan') |
|
67
|
|
|
->field('subscription.planName') |
|
68
|
|
|
->field('subscription.validUntil') |
|
69
|
|
|
->field('subscription.status') |
|
70
|
|
|
->end(); |
|
71
|
|
|
|
|
72
|
|
|
return $readView; |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|