Skip to content

Commit 011cb34

Browse files
committed
added admin controller and moved BulkSMS to marketing tab
1 parent b68bd13 commit 011cb34

25 files changed

+415
-429
lines changed

.gitignore

100755100644
File mode changed.

LICENSE

100755100644
File mode changed.

README.md

100755100644
-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ Available message placeholders:
2424

2525
#### TODO:
2626
- Add tests
27-
- Add more translations
2827
- Add more events
2928
- Add more placeholders to message contents

TableWrapper.php

-47
This file was deleted.

Util.php

-142
This file was deleted.

Constants.php renamed to classes/Constants.php

-16
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,9 @@ abstract class Constants
3131
const SIGNATURE = 'SMS77_SIGNATURE';
3232
const SIGNATURE_POSITION = 'SMS77_SIGNATURE_POSITION';
3333

34-
static function persistedKeys() {
35-
$keys = [];
36-
37-
foreach (self::CONFIGURATION as $k => $v) {
38-
if (!in_array($k, self::NON_PERSISTED_KEYS)) {
39-
$keys[] = $k;
40-
}
41-
}
42-
43-
return $keys;
44-
}
45-
4634
const CONFIGURATION = [
4735
self::API_KEY => '',
4836
self::BULK => '',
49-
self::BULK_COUNTRIES => [],
50-
self::BULK_GROUPS => [],
5137
self::FROM => '',
5238
self::MSG_ON_DELIVERY => false,
5339
self::MSG_ON_INVOICE => false,
@@ -65,6 +51,4 @@ static function persistedKeys() {
6551
];
6652

6753
const SIGNATURE_POSITIONS = ['append', 'prepend',];
68-
69-
const NON_PERSISTED_KEYS = [Constants::BULK_COUNTRIES, Constants::BULK_GROUPS,];
7054
}

Form.php renamed to classes/Form.php

+15-49
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
* @license LICENSE
1414
*/
1515

16+
require_once __DIR__ . "/../controllers/admin/Sms77AdminController.php";
17+
require_once __DIR__ . "./Constants.php";
18+
1619
class Form extends HelperForm
1720
{
18-
public function __construct($name)
19-
{
21+
public function __construct($name) {
2022
parent::__construct();
2123
$defaultLang = (int)Configuration::get('PS_LANG_DEFAULT');
2224
$this->allow_employee_form_lang = $defaultLang;
23-
$this->currentIndex = AdminController::$currentIndex . "&configure=$name";
25+
$this->currentIndex = Sms77AdminController::$currentIndex . "&configure=$name";
2426
$this->default_form_language = $defaultLang;
2527

26-
$setFieldsValue = function($k, $v) {
28+
$setFieldsValue = function ($k, $v) {
2729
$name = "config[$k]";
2830

2931
if (is_array($v)) {
@@ -33,15 +35,11 @@ public function __construct($name)
3335
$this->fields_value[$name] = $v;
3436
};
3537

36-
foreach (Configuration::getMultiple(Constants::persistedKeys()) as $k => $v) {
38+
foreach (Configuration::getMultiple(array_keys(Constants::CONFIGURATION)) as $k => $v) {
3739
$setFieldsValue($k, $v);
3840
}
3941

40-
foreach (Constants::NON_PERSISTED_KEYS as $k) {
41-
$setFieldsValue($k, Constants::CONFIGURATION[$k]);
42-
}
43-
44-
$toName = function($key) {
42+
$toName = function ($key) {
4543
return "config[$key]";
4644
};
4745

@@ -130,35 +128,6 @@ public function __construct($name)
130128
];
131129
}, Constants::SIGNATURE_POSITIONS),
132130
],
133-
[
134-
'label' => $this->l('Countries'),
135-
'multiple' => true,
136-
'name' => $toName(Constants::BULK_COUNTRIES),
137-
'options' => [
138-
'query' => Country::getCountries($this->context->language->id),
139-
'id' => 'id_country',
140-
'name' => 'name'
141-
],
142-
'tab' => 'bulk',
143-
'type' => 'select',
144-
],
145-
[
146-
'label' => $this->l('Groups'),
147-
'multiple' => true,
148-
'name' => $toName(Constants::BULK_GROUPS),
149-
'options' => [
150-
'query' => Group::getGroups($this->context->language->id),
151-
'id' => 'id_group',
152-
'name' => 'name'
153-
],
154-
'tab' => 'bulk',
155-
'type' => 'select',
156-
],
157-
$this->makeTextarea(
158-
'BULK',
159-
'Send out any message to all of your customers.',
160-
'bulk'
161-
),
162131
],
163132
'submit' => [
164133
'title' => $this->l('Save'),
@@ -179,19 +148,18 @@ public function __construct($name)
179148
'save' =>
180149
[
181150
'desc' => $this->l('Save'),
182-
'href' => AdminController::$currentIndex . "&configure=$name&save$name&token="
151+
'href' => Sms77AdminController::$currentIndex . "&configure=$name&save$name&token="
183152
. Tools::getAdminTokenLite('AdminModules'),
184153
],
185154
'back' => [
186-
'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
155+
'href' => Sms77AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
187156
'desc' => $this->l('Back to list'),
188157
],
189158
];
190159
$this->toolbar_scroll = true;
191160
}
192161

193-
private function makeTextarea($action, $trans, $tab = 'settings')
194-
{
162+
private function makeTextarea($action, $trans, $tab = 'settings') {
195163
$trans = $this->l($trans);
196164

197165
return [
@@ -204,8 +172,7 @@ private function makeTextarea($action, $trans, $tab = 'settings')
204172
];
205173
}
206174

207-
private function makeSwitch($action, $label, $desc, $values, $isBool)
208-
{
175+
private function makeSwitch($action, $label, $desc, $values, $isBool) {
209176
$descHit = $this->l($desc);
210177

211178
return [
@@ -220,18 +187,17 @@ private function makeSwitch($action, $label, $desc, $values, $isBool)
220187
];
221188
}
222189

223-
private function makeBool($action, $label, $desc)
224-
{
190+
private function makeBool($action, $label, $desc) {
225191
$sAction = Tools::strtolower($action);
226192

227193
return $this->makeSwitch("MSG_ON_$action", $label, $desc, [
228194
[
229195
'id' => 'on_' . $sAction . '_on',
230-
'value' => 1
196+
'value' => 1,
231197
],
232198
[
233199
'id' => 'on_' . $sAction . '_off',
234-
'value' => 0
200+
'value' => 0,
235201
],
236202
], true);
237203
}

Personalizer.php renamed to classes/Personalizer.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
* @property bool $hasFirstName
2020
* @property bool $hasLastName
2121
* @property bool $hasOrderId
22-
*
2322
*/
2423
class Personalizer
2524
{
26-
public function __construct($msg, $address)
27-
{
25+
public function __construct($msg, $address) {
2826
$this->msg = $msg;
2927
$this->address = $address;
3028

@@ -33,8 +31,7 @@ public function __construct($msg, $address)
3331
$this->hasOrderId = false !== strpos($this->msg, '{2}');
3432
}
3533

36-
function toString($orderId = null)
37-
{
34+
function toString($orderId = null) {
3835
$msg = $this->msg;
3936

4037
if ($this->hasFirstName) {

0 commit comments

Comments
 (0)