1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\assets; |
4
|
|
|
|
5
|
|
|
use DomainException; |
6
|
|
|
use EE_Currency_Config; |
7
|
|
|
use EventEspresso\core\domain\DomainInterface; |
8
|
|
|
use EventEspresso\core\exceptions\InvalidDataTypeException; |
9
|
|
|
use EventEspresso\core\exceptions\InvalidEntityException; |
10
|
|
|
use EventEspresso\core\services\assets\AssetCollection; |
11
|
|
|
use EventEspresso\core\services\assets\AssetManager; |
12
|
|
|
use EventEspresso\core\services\assets\Registry; |
13
|
|
|
use EventEspresso\core\services\collections\DuplicateCollectionIdentifierException; |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* LegacyEditorAssetManager |
18
|
|
|
* assets for the EE legacy event editor |
19
|
|
|
* |
20
|
|
|
* @package EventEspresso\core\domain\services\assets |
21
|
|
|
* @author Brent Christensen |
22
|
|
|
* @since $VID:$ |
23
|
|
|
*/ |
24
|
|
|
class LegacyAccountingAssetManager extends AssetManager |
25
|
|
|
{ |
26
|
|
|
|
27
|
|
|
const JS_HANDLE_UNDERSCORE = 'underscore'; |
28
|
|
|
|
29
|
|
|
const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
30
|
|
|
|
31
|
|
|
const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var EE_Currency_Config $currency_config |
36
|
|
|
*/ |
37
|
|
|
protected $currency_config; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* CoreAssetRegister constructor. |
41
|
|
|
* |
42
|
|
|
* @param AssetCollection $assets |
43
|
|
|
* @param DomainInterface $domain |
44
|
|
|
* @param Registry $registry |
45
|
|
|
* @param EE_Currency_Config $currency_config |
46
|
|
|
*/ |
47
|
|
|
public function __construct( |
48
|
|
|
AssetCollection $assets, |
49
|
|
|
DomainInterface $domain, |
50
|
|
|
Registry $registry, |
51
|
|
|
EE_Currency_Config $currency_config |
52
|
|
|
) { |
53
|
|
|
$this->currency_config = $currency_config; |
54
|
|
|
parent::__construct($domain, $assets, $registry); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @throws InvalidDataTypeException |
61
|
|
|
* @throws InvalidEntityException |
62
|
|
|
* @throws DuplicateCollectionIdentifierException |
63
|
|
|
* @throws DomainException |
64
|
|
|
*/ |
65
|
|
|
public function addAssets() |
66
|
|
|
{ |
67
|
|
|
$this->loadAccountingJs(); |
68
|
|
|
add_action('admin_enqueue_scripts', [$this, 'enqueueLegacyAccountingAssets'], 100); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* accounting.js for performing client-side calculations |
74
|
|
|
* |
75
|
|
|
* @throws DomainException |
76
|
|
|
* @throws DuplicateCollectionIdentifierException |
77
|
|
|
* @throws InvalidDataTypeException |
78
|
|
|
* @throws InvalidEntityException |
79
|
|
|
* @since $VID:$ |
80
|
|
|
*/ |
81
|
|
|
private function loadAccountingJs() |
82
|
|
|
{ |
83
|
|
|
//accounting.js library |
84
|
|
|
// @link http://josscrowcroft.github.io/accounting.js/ |
85
|
|
|
$this->addJavascript( |
86
|
|
|
LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
87
|
|
|
EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
88
|
|
|
[LegacyAccountingAssetManager::JS_HANDLE_UNDERSCORE], |
89
|
|
|
true, |
90
|
|
|
'0.3.2' |
91
|
|
|
); |
92
|
|
|
|
93
|
|
|
$this->addJavascript( |
94
|
|
|
LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
95
|
|
|
EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
96
|
|
|
[LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING_CORE] |
97
|
|
|
) |
98
|
|
|
->setInlineDataCallback( |
99
|
|
|
function () { |
100
|
|
|
wp_localize_script( |
101
|
|
|
LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING, |
102
|
|
|
'EE_ACCOUNTING_CFG', |
103
|
|
|
$this->getAccountingSettings() |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Returns configuration data for the accounting-js library. |
112
|
|
|
* |
113
|
|
|
* @return array |
114
|
|
|
* @since $VID:$ |
115
|
|
|
*/ |
116
|
|
|
private function getAccountingSettings() |
117
|
|
|
{ |
118
|
|
|
return [ |
119
|
|
|
'currency' => [ |
120
|
|
|
'symbol' => $this->currency_config->sign, |
121
|
|
|
'format' => [ |
122
|
|
|
'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
123
|
|
|
'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
124
|
|
|
'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
125
|
|
|
], |
126
|
|
|
'decimal' => $this->currency_config->dec_mrk, |
127
|
|
|
'thousand' => $this->currency_config->thsnds, |
128
|
|
|
'precision' => $this->currency_config->dec_plc, |
129
|
|
|
], |
130
|
|
|
'number' => [ |
131
|
|
|
'precision' => $this->currency_config->dec_plc, |
132
|
|
|
'thousand' => $this->currency_config->thsnds, |
133
|
|
|
'decimal' => $this->currency_config->dec_mrk, |
134
|
|
|
], |
135
|
|
|
]; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* enqueue_scripts - Load the scripts and css |
141
|
|
|
* |
142
|
|
|
* @return void |
143
|
|
|
*/ |
144
|
|
|
public function enqueueLegacyAccountingAssets() |
145
|
|
|
{ |
146
|
|
|
$this->enqueueAsset(LegacyAccountingAssetManager::JS_HANDLE_ACCOUNTING); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|