-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBillTech.php
executable file
·132 lines (123 loc) · 3.58 KB
/
BillTech.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
<?php
/*********************
* @author BillTech Group sp. z o.o.
* Copyright 2022
*
* All rights reserved.
* Distribution of the software in any financial form is only allowed with
* explicit, prior permission from the owner.
*
*/
class BillTech extends LMSPlugin
{
const PLUGIN_DB_VERSION = '2023091200';
const PLUGIN_DBVERSION = BillTech::PLUGIN_DB_VERSION; /* Legacy for old LMS versions */
const PLUGIN_SOFTWARE_VERSION = '2022012000';
const PLUGIN_DIRECTORY_NAME = 'BillTech';
const PLUGIN_NAME = 'BillTech';
const PLUGIN_DESCRIPTION = 'BillTech - wersja: 20220120';
const PLUGIN_AUTHOR = 'Michał Kaciuba <[email protected]>';
const PLUGIN_DOC_URL = 'https://github.com/BillTechPL/lms-billtech-plugin/blob/master/README.md';
const PLUGIN_REPO_URL = 'https://github.com/BillTechPL/lms-billtech-plugin';
const CASH_COMMENT = 'Wpłata online';
public function registerHandlers()
{
$this->handlers = array(
'menu_initialized' => array(
'class' => 'BillTechInitHandler',
'method' => 'menuBillTech'
),
'modules_dir_initialized' => array(
'class' => 'BillTechInitHandler',
'method' => 'modulesBillTech'
),
'smarty_initialized' => array(
'class' => 'BillTechInitHandler',
'method' => 'smartyBillTech'
),
'userpanel_smarty_initialized' => array(
'class' => 'BillTechInitHandler',
'method' => 'smartyBillTech'
),
'invoice_email_before_send' => array(
'class' => 'BillTechLinkInsertHandler',
'method' => 'addButtonToInvoiceEmail'
),
'notify_parse_customer_data' => array(
'class' => 'BillTechLinkInsertHandler',
'method' => 'notifyCustomerDataParse'
),
'customer_before_display' => array(
'class' => 'BillTechLinkInsertHandler',
'method' => 'addButtonToCustomerView'
),
'customer_otherip_before_display' => array(
'class' => 'BillTechLinkInsertHandler',
'method' => 'addButtonToCustomerOtherIPView'
),
'userpanel_finances_main_before_module_display' => array(
'class' => 'BillTechLinkInsertHandler',
'method' => 'addButtonsToFinancesView'
),
'cashimport_after_commit' => array(
'class' => 'BillTechPaymentCashImportHandler',
'method' => 'processCashImport'
),
'messageadd_variable_parser' => array(
'class' => 'BillTechLinkInsertHandler',
'method' => 'messageaddCustomerDataParse'
),
);
}
public static function toMap($callback, array $array)
{
$map = array();
foreach ($array as $item) {
$map[$callback($item)] = $item;
}
return $map;
}
/**
* @param string $str
* @param $separator
* @param int $repeatCount
* @return string
*/
public static function repeatWithSeparator($str, $separator, $repeatCount)
{
return implode($separator, array_fill(0, $repeatCount, $str));
}
/**
* @param int $rowCount
* @param int $valuesCount
* @return string
*/
public static function prepareMultiInsertPlaceholders($rowCount, $valuesCount)
{
return BillTech::repeatWithSeparator("(" . BillTech::repeatWithSeparator("?", ",", $valuesCount) . ")", ',', $rowCount);
}
public static function measureTime($callback, $verbose)
{
$start = microtime(true);
$callback();
$time_elapsed_secs = microtime(true) - $start;
if ($verbose) {
echo "Update took " . $time_elapsed_secs . " s\n";
}
}
public static function lock($lockName, $callback)
{
$fp = fopen('/tmp/billtech-lock-' . $lockName, 'w+');
try {
if (flock($fp, LOCK_EX | LOCK_NB)) {
echo "Lock acquired\n";
$callback();
flock($fp, LOCK_UN);
} else {
exit("Could not acquire lock. Another process is running.\n");
}
} finally {
fclose($fp);
}
}
}