-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPactioner.php
More file actions
207 lines (166 loc) · 6.05 KB
/
Pactioner.php
File metadata and controls
207 lines (166 loc) · 6.05 KB
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?
class Pactioner extends Actioner{
private $pluginName = 'group_property';
// Сортирует характеристики в группе
public function sortedProperty(){
$this->messageSucces = 'Операция выполнена';
$this->messageError = 'Ошибка выполнения операции';
$propertys = array();
if(!empty($_POST['propertys'])){
foreach($_POST['propertys'] as $item){
$propertys[$item] = $item;
}
}
$save = array(
'property' => serialize($propertys)
);
if(DB::query('UPDATE `'.PREFIX.$this->pluginName.'` SET '.DB::buildPartQuery($save).' WHERE id = '.$_POST['idGroup'].''))
return true;
return false;
}
// Сортирует группы характеристик
public function sortedGroup(){
$this->messageSucces = 'Операция выполнена';
$this->messageError = 'Ошибка выполнения операции';
$position = 1;
foreach($_POST['groups'] as $id){
DB::query("UPDATE `".PREFIX.$this->pluginName."` SET sort={$position} WHERE id={$id}");
$position++;
}
return true;
}
// Поиск характеристики по имени, которой еще нет в группе
public function searchProperty(){
$ids = GroupProperty::getGroupProperty();
$result = array();
$query = $_POST['query'];
if(!empty($query)){
if(!empty($ids)){
$ids = implode($ids, ', ');
$query = DB::query("SELECT id, name FROM `".PREFIX."property` WHERE id NOT IN({$ids}) AND name LIKE '{$query}%' LIMIT 10");
} else {
$query = DB::query("SELECT id, name FROM `".PREFIX."property` WHERE name LIKE '{$query}%' LIMIT 10");
}
if(DB::numRows($query) != 0){
while($row = DB::fetchAssoc($query)){
$result[] = $row;
}
}
} else {
// Если передан пустой запрос - отображаем все добавленные характеристики
$result = GroupProperty::getAllProperty();
}
echo json_encode($result);
}
// Добавляет характеристики в группу
public function addPropertyInGroup(){
$this->messageSucces = 'Операция выполнена';
$this->messageError = 'Ошибка выполнения операции';
if(!empty($_POST['data'])){
$query = DB::query("SELECT property FROM `".PREFIX.$this->pluginName."` WHERE id={$_POST['idGroup']}");
$row = DB::fetchAssoc($query);
$data = array();
if(!empty($row['property'])){
$data = unserialize($row['property']);
}
$data = array_merge($data, $_POST['data']);
$result = array();
foreach($data as $key => $val){
$result[$val] = $val;
}
$save = array(
'property' => serialize($result)
);
if(DB::query('UPDATE `'.PREFIX.$this->pluginName.'` SET '.DB::buildPartQuery($save).' WHERE id = '.$_POST['idGroup'].''))
return true;
return false;
}
}
public function saveOptions(){
$this->messageSucces = 'Настройки успешно сохранены';
$this->messageError = 'Ошибка выполнения операции';
if (!empty($_POST['data'])) {
MG::setOption(array('option' => 'group_property-option', 'value' => addslashes(serialize($_POST['data']))));
}
return true;
}
// Удаляет характеристику из группы
public function deletePropertyInGroup(){
$this->messageSucces = 'Характеристика удаленна';
$this->messageError = 'Ошибка выполнения операции';
$query = DB::query("SELECT property FROM `".PREFIX.$this->pluginName."` WHERE id={$_POST['idGroup']}");
$row = DB::fetchAssoc($query);
$data = unserialize($row['property']);
unset($data[$_POST['idEl']]);
$save = array(
'property' => serialize($data)
);
$options = GroupProperty::getPluginOptions();
if($options['delete_property'] == 'true'){
DB::query('
DELETE
FROM `'.PREFIX.'property`
WHERE id = '.DB::quote($_POST['idEl'], true)) &&
DB::query('
DELETE
FROM `'.PREFIX.'product_user_property`
WHERE property_id = '.DB::quote($_POST['idEl'], true)) &&
DB::query('
DELETE
FROM `'.PREFIX.'category_user_property`
WHERE property_id = '.DB::quote($_POST['idEl'], true));
}
if(DB::query('UPDATE `'.PREFIX.$this->pluginName.'` SET '.DB::buildPartQuery($save).' WHERE id = '.$_POST['idGroup'].''))
return true;
return false;
}
public function getGroup(){
$data = GroupProperty::getEntity($_POST['idGroup']);
if(!empty($data[0]['property'])){
$res = array();
foreach($data[0]['property'] as $item){
$res[] = $item;
}
echo json_encode($res);
} else {
echo json_encode($data[0]['property']);
}
}
public function createGroup(){
$this->messageSucces = 'Группа успешно создана';
$this->messageError = 'Ошибка выполнения операции';
$save = array(
'name' => $_POST['nameGroup']
);
if(DB::buildQuery('INSERT INTO `'.PREFIX.$this->pluginName.'` SET ', $save)){
$lastId = DB::insertId();
DB::query('UPDATE `'.PREFIX.$this->pluginName.'` SET sort='.$lastId.' WHERE id='.$lastId.'');
$this->data['nameGroup'] = $_POST['nameGroup'];
$this->data['idGroup'] = $lastId;
return true;
}
return false;
}
public function deleteGroup(){
$this->messageSucces = 'Группа удаленна';
$this->messageError = 'Ошибка выполнения операции';
if (DB::query('DELETE FROM `'.PREFIX.$this->pluginName.'` WHERE `id`= '.$_POST['idGroup']))
return true;
return false;
}
public function editGroup(){
$this->messageSucces = 'Группа отредактированна';
$this->messageError = 'Ошибка выполнения операции';
$save = array(
'name' => $_POST['nameGroup']
);
if(DB::query('UPDATE `'.PREFIX.$this->pluginName.'` SET '.DB::buildPartQuery($save).' WHERE id='.$_POST['idGroup'].'')){
return true;
}
return false;
}
public function getAllProperty(){
$data = GroupProperty::getAllProperty();
echo json_encode($data);
}
}