-
Notifications
You must be signed in to change notification settings - Fork 4
/
Plugin.php
173 lines (157 loc) · 5.14 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php namespace Responsiv\Subscribe;
use Event;
use Backend;
use Responsiv\Subscribe\Classes\SubscriptionEngine;
use RainLab\User\Models\User as UserModel;
use October\Rain\Database\Relations\Relation;
use System\Classes\PluginBase;
/**
* Subscribe Plugin Information File
*/
class Plugin extends PluginBase
{
public $require = ['Responsiv.Pay'];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'Subscribe',
'description' => 'Subscription manager',
'author' => 'Responsiv Internet',
'icon' => 'icon-leaf'
];
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
$this->registerSubscriptionEvents();
/*
* Console commands
*/
$this->registerConsoleCommand('subscribe.run', 'Responsiv\Subscribe\Console\SubscriptionRun');
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
Relation::morphMap([
'subscribe-service' => \Responsiv\Subscribe\Models\Service::class
]);
$this->extendUserModel();
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return [
\Responsiv\Subscribe\Components\Subscribe::class => 'subscribe',
\Responsiv\Subscribe\Components\Payment::class => 'subscribePayment',
\Responsiv\Subscribe\Components\PlanList::class => 'subscribePlanList',
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return [
'responsiv.subscribe.manage_memberships' => [
'tab' => 'Subscribe',
'label' => 'Manage subscriptions'
],
'responsiv.subscribe.manage_plans' => [
'tab' => 'Subscribe',
'label' => 'Manage subscription plans'
],
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'Membership Settings',
'description' => 'Configure settings that apply to memberships.',
'icon' => 'icon-exchange',
'class' => 'Responsiv\Subscribe\Models\Setting',
'category' => 'Pay',
'order' => 530,
],
];
}
public function registerNavigation()
{
return [
'subscribe' => [
'label' => 'Subscriptions',
'url' => Backend::url('responsiv/subscribe/memberships'),
'icon' => 'icon-newspaper-o',
'iconSvg' => 'plugins/responsiv/subscribe/assets/images/subscribe-icon.svg',
'permissions' => ['subscribe.*'],
'order' => 510,
'sideMenu' => [
'memberships' => [
'label' => 'Memberships',
'icon' => 'icon-users',
'url' => Backend::url('responsiv/subscribe/memberships'),
'permissions' => ['subscribe.*'],
],
'plans' => [
'label' => 'Plans',
'icon' => 'icon-clipboard',
'url' => Backend::url('responsiv/subscribe/plans'),
'permissions' => ['subscribe.*'],
],
'settings' => [
'label' => 'Settings',
'icon' => 'icon-cog',
'url' => Backend::url('system/settings/update/responsiv/subscribe/settings'),
'permissions' => ['subscribe.*'],
]
]
]
];
}
public function registerMailTemplates()
{
return [
'responsiv.subscribe::mail.billing_report',
'responsiv.subscribe::mail.invoice_report',
'responsiv.subscribe::mail.membership_thankyou',
'responsiv.subscribe::mail.new_membership_internal',
'responsiv.subscribe::mail.membership_status_update_internal'
];
}
/**
* Register events related to this plugin, needs to be public for unit testing.
*/
public function registerSubscriptionEvents()
{
$manager = SubscriptionEngine::instance();
Event::listen('responsiv.pay.invoicePaid', [$manager, 'invoiceAfterPayment']);
}
/**
* Extends the User model provided by the RainLab.User plugin.
*/
protected function extendUserModel()
{
UserModel::extend(function($model) {
$model->implement[] = \Responsiv\Subscribe\Behaviors\SubscriberModel::class;
});
}
}