-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofflinerecurring.php
137 lines (119 loc) · 4.45 KB
/
offlinerecurring.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
<?php
/**
* CiviCRM Offline Recurring Payment Extension for CiviCRM - Circle Interactive 2013
* Original author: rajesh
* http://sourceforge.net/projects/civicrmoffline/
*
* Ported to CiviCRM extension by andyw@circle, 2013
* Rewritten for CiviCRM 4.5 - andyw@circle, Jan 2015
*/
/**
* Get CRM version as floating point number - eg: 4.5
* so we can do less than / greater than comparison
* @return float
*/
function _offlinerecurring_getCRMVersion() {
$crmversion = explode('.', ereg_replace('[^0-9\.]','', CRM_Utils_System::version()));
return floatval($crmversion[0] . '.' . $crmversion[1]);
}
/**
* Implementation of hook_civicrm_config
*/
function offlinerecurring_civicrm_config(&$config) {
$template = &CRM_Core_Smarty::singleton();
$ddRoot = dirname(__FILE__);
$subDir = _offlinerecurring_getCRMVersion() >= 4.5 ? 'new' : 'legacy';
$ddDir = "$ddRoot/$subDir/templates";
if (is_array($template->template_dir)) {
array_unshift($template->template_dir, $ddDir);
} else {
$template->template_dir = array($ddDir, $template->template_dir);
}
# also fix php include path
set_include_path("$ddRoot/$subDir/php" . PATH_SEPARATOR . get_include_path());
}
/**
* Implementation of hook_civicrm_disable
*/
function offlinerecurring_civicrm_disable() {
CRM_Core_DAO::executeQuery("
DELETE FROM civicrm_job WHERE api_action = 'process_offline_recurring_payments'
");
}
/**
* Implementation of hook_civicrm_enable
*/
function offlinerecurring_civicrm_enable() {
// Create entry in civicrm_job table for cron call
$version = _offlinerecurring_getCRMVersion();
if ($version >= 4.3) {
// looks like someone finally wrote an api ..
civicrm_api('job', 'create', array(
'version' => 3,
'name' => ts('Process Offline Recurring Payments'),
'description' => ts('Processes any offline recurring payments that are due'),
'run_frequency' => 'Hourly',
'api_entity' => 'job',
'api_action' => 'process_offline_recurring_payments',
'is_active' => 0
));
} else {
// otherwise, this ..
CRM_Core_DAO::executeQuery("
INSERT INTO civicrm_job (
id, domain_id, run_frequency, last_run, name, description,
api_prefix, api_entity, api_action, parameters, is_active
) VALUES (
NULL, %1, 'Hourly', NULL, 'Process Offline Recurring Payments',
'Processes any offline recurring payments that are due',
'civicrm_api3', 'job', 'process_offline_recurring_payments', '', 0
)
", array(
1 => array(CIVICRM_DOMAIN_ID, 'Integer')
)
);
}
// We need some way of keeping track of which contribution_recurs were created by us.
// I'm creating a second table for that for now, maybe not the best way, but we
// can revisit this later perhaps
CRM_Core_DAO::executeQuery("
CREATE TABLE IF NOT EXISTS `civicrm_contribution_recur_offline` (
`recur_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`recur_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
");
}
/**
* Implementation of hook_civicrm_uninstall
*/
function offlinerecurring_civicrm_uninstall() {
CRM_Core_DAO::executeQuery("DROP TABLE civicrm_contribution_recur_offline");
}
/**
* Implementation of hook_civicrm_xmlMenu
*/
function offlinerecurring_civicrm_xmlMenu(&$files) {
$subDir = _offlinerecurring_getCRMVersion() >= 4.5 ? 'new' : 'legacy';
$files[] = dirname(__FILE__) . "/$subDir/php/Recurring/xml/Menu/RecurringPayment.xml";
}
/**
* @param array $permissions
*/
function offlinerecurring_civicrm_permission( &$permissions ) {
$prefix = 'CiviCRM Offlinerecurring: ';
$permissions['add offline recurring payments'] = [
'label' => $prefix . 'add offline recurring payments',
'description' => E::ts('Add offline recurring payments.'),
];
$permissions['edit offline recurring payments'] = [
'label' => $prefix . 'edit offline recurring payments',
'description' => E::ts('Edit offline recurring payments.'),
];
}
# conditionally include other hooks / functions, depending
# on which version of CiviCRM we're running on
require_once dirname(__FILE__) . (
_offlinerecurring_getCRMVersion() >= 4.5 ?
'/offlinerecurring_new.php' :
'/offlinerecurring_legacy.php'
);