-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathps_quality_checklist_opquast.php
121 lines (99 loc) · 3.59 KB
/
ps_quality_checklist_opquast.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
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
require_once(_PS_MODULE_DIR_ . 'ps_quality_checklist_opquast/classes/ChecklistUtility.php');
/**
* @author Constantin Boulanger <[email protected]>
*/
class Ps_Quality_Checklist_Opquast extends Module
{
/**
* {@inheritDoc}
*/
public function __construct()
{
$this->name = 'ps_quality_checklist_opquast';
$this->tab = 'front_office_features';
$this->version = '1.0.3';
$this->author = '<a href="https://constantin-boulanger.fr" target="_blank">Constantin Boulanger</a>';
$this->need_instance = 0;
$this->bootstrap = true;
parent::__construct();
$this->displayName = $this->l('Prestashop Quality Checklist Opquast');
$this->description = $this->l('Checklist qualité web Opquast pour Prestashop');
}
/**
* {@inheritDoc}
*/
public function install()
{
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
throw new PrestaShopException($this->l('This module requires PHP 5.4 or higher.'));
}
if (!Configuration::hasKey('PSOPQUASTCURRENT')) {
Configuration::updateValue('PSOPQUASTCURRENT', serialize([]));
}
return parent::install();
}
/**
* {@inheritDoc}
*/
public function postProcess()
{
$values = null;
if (method_exists('Tools', 'getAllValues')) {
$values = Tools::getAllValues();
} else {
$values = $_GET + $_POST;
}
$opquastResponses = array_filter($values, function ($value) {
return false !== strpos($value, 'opquast-checklist-');
}, ARRAY_FILTER_USE_KEY);
if (empty($opquastResponses)) {
return false;
}
$toSave = [];
foreach ($opquastResponses as $index => $response) {
$id = explode('-', $index)[2];
$toSave[$id] = $response;
}
return Configuration::updateValue('PSOPQUASTCURRENT', serialize($toSave));
}
/**
* {@inheritDoc}
*/
public function getContent()
{
$html = '';
if (Tools::isSubmit('submitOpquastChecklist')) {
if ($this->postProcess()) {
$html .= $this->displayConfirmation($this->l('Settings saved'));
} else {
$html .= $this->displayError($this->l('An error has occurred. Please try again'));
}
}
$this->context->controller->addJS($this->_path . 'views/js/admin.js');
$this->context->controller->addCSS($this->_path . 'views/css/admin.css');
$iso_code = 'fr';
if ($this->context->language->iso_code !== 'fr') {
$iso_code = 'en';
}
$checklist = ChecklistUtility::getOPQuastChecklist();
$themes = ChecklistUtility::getThemesFromJSON();
$currentCriterias = ChecklistUtility::getCurrentCriterias();
$stats = ChecklistUtility::getStats();
$this->context->smarty->assign(
[
'iso_code' => $iso_code,
'themes' => $themes,
'checklist' => $checklist,
'currentCriterias' => $currentCriterias,
'path' => $this->_path,
'stats' => $stats,
'actionUrl' => $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->name . '&tab_module=' . $this->tab . '&module_name=' . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'),
]
);
return $html . $this->display(__FILE__, 'views/templates/admin/index.tpl');
}
}