-
Notifications
You must be signed in to change notification settings - Fork 2
/
client_statements_plugin.php
119 lines (96 loc) · 2.97 KB
/
client_statements_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
<?php
class ClientStatementsPlugin extends Plugin {
public function __construct() {
$this->loadConfig( dirname( __FILE__ ) . DS . "config.json" );
}
public function getActions() {
return array(
/*
array(
'action' => "widget_client_home",
'uri' => "plugin/client_statements/client_widget/index/",
'name' => "Account Statement",
),
*/
/*
array(
'action' => "nav_secondary_staff", // The action to tie into
'uri' => "plugin/client_statements/admin_main/index/", // The URI to fetch when the action is needed
'name' => "Client Statements", // The name used by Blesta to display for the action (e.g. The name of the link),
'options' => array(
'parent' => "billing/",
),
),
*/
array(
'action' => 'action_staff_client',
'uri' => "plugin/client_statements/admin/index/",
'name' => 'Send Account Statement',
'options' => array(
'class' => 'statements',
),
),
array(
'action' => "nav_primary_client", // The action to tie into
'uri' => "plugin/client_statements/client/index/", // The URI to fetch when the action is needed
'name' => "Account Statements", // The name used by Blesta to display for the action (e.g. The name of the link),
#'options' => array(
# 'parent' => "billing/",
#),
),
);
}
public function install( $plugin_id ) {
Loader::loadModels( $this, array( "EmailGroups", "Emails" ) );
$group = array(
'action' => "ClientStatements.send_statement",
'type' => "staff",
'plugin_dir' => "client_statements",
'tags' => "first_name,last_name",
);
// Add the custom group
$group_id = $this->EmailGroups->add( $group );
$email = array(
'email_group_id' => $group_id,
'company_id' => Configure::get( "Blesta.company_id" ),
'lang' => "en_us",
'from' => "[email protected]",
'from_name' => "My Company",
'subject' => "Subject of the email",
'text' => "Hi {first_name},
This is the text version of your email",
'html' => "<p>Hi {first_name},</p>
<p>This is the HTML version of your email</p>"
);
// Add an email to the group
$this->Emails->add( $email );
}
public function uninstall( $plugin_id, $last_instance ) {
Loader::loadModels( $this, array( "EmailGroups", "Emails" ) );
// Fetch the email template created by this plugin
$group = $this->EmailGroups->getByAction( "ClientStatements.send_statement" );
// Delete all emails templates belonging to this plugin's email group and company
if ( $group ) {
$this->Emails->deleteAll( $group->id, Configure::get( "Blesta.company_id" ) );
}
if ( $last_instance ) {
try {
// Remove the email template created by this plugin
if ( $group ) {
$this->EmailGroups->delete( $group->id );
}
}
catch ( Exception $e ) {
// Error dropping... no permission?
$this->Input->setErrors(
array(
'db' => array(
'create' => $e->getMessage()
)
)
);
return;
}
}
}
}