|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Vvveb |
| 5 | + * |
| 6 | + * Copyright (C) 2022 Ziadin Givan |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Affero General Public License as |
| 10 | + * published by the Free Software Foundation, either version 3 of the |
| 11 | + * License, or (at your option) any later version. |
| 12 | + * |
| 13 | + * This program is distributed in the hope that it will be useful, |
| 14 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Affero General Public License for more details. |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU Affero General Public License |
| 19 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 20 | + * |
| 21 | + */ |
| 22 | + |
| 23 | +namespace Vvveb\Controller\Field; |
| 24 | + |
| 25 | +use function Vvveb\__; |
| 26 | +use Vvveb\Controller\Crud; |
| 27 | +use Vvveb\Sql\CountrySQL; |
| 28 | +use Vvveb\Sql\Field_GroupSQL; |
| 29 | +use Vvveb\Sql\FieldSQL; |
| 30 | + |
| 31 | +class FieldGroup extends Crud { |
| 32 | + protected $type = 'field_group'; |
| 33 | + |
| 34 | + protected $controller = 'field-group'; |
| 35 | + |
| 36 | + protected $module = 'field'; |
| 37 | + |
| 38 | + function save() {/* |
| 39 | + $field = $this->request->post['field'] ?? []; |
| 40 | + $field_group_id = $this->request->get['field_group_id'] ?? false; |
| 41 | +
|
| 42 | + if ($field_group_id) { |
| 43 | + $fieldGroup = new Field_GroupSQL(); |
| 44 | + $result = $fieldGroup->addFields(['field_group_id' => $field_group_id, 'field_to_field_group' => $field]); |
| 45 | +
|
| 46 | + if ($result && isset($result['field_to_field_group'])) { |
| 47 | + $successMessage = __('Field saved!'); |
| 48 | + $this->view->success[] = $successMessage; |
| 49 | + $this->view->errors = []; |
| 50 | + } else { |
| 51 | + $this->view->errors[] = __('Error saving!'); |
| 52 | + } |
| 53 | + }*/ |
| 54 | + |
| 55 | + $this->request->post[$this->type]['status'] = 1; |
| 56 | + |
| 57 | + parent::save(); |
| 58 | + } |
| 59 | + |
| 60 | + function fields() { |
| 61 | + $country_id = $this->request->get['country_id'] ?? false; |
| 62 | + $fields = []; |
| 63 | + |
| 64 | + if ($country_id) { |
| 65 | + $field = new FieldSQL(); |
| 66 | + $options = $this->global; |
| 67 | + $options['status'] = 1; |
| 68 | + $options['country_id'] = $country_id; |
| 69 | + unset($options['limit']); |
| 70 | + $fields = $field->getAll($options)['field'] ?? []; |
| 71 | + } |
| 72 | + |
| 73 | + $this->response->setType('json'); |
| 74 | + $this->response->output($fields); |
| 75 | + //return []; |
| 76 | + } |
| 77 | + |
| 78 | + function index() { |
| 79 | + $field_group_id = $this->request->get['field_group_id'] ?? false; |
| 80 | + $this->view->field_group_id = $field_group_id; |
| 81 | + |
| 82 | + parent::index(); |
| 83 | + |
| 84 | + return; |
| 85 | + $field_group_id = $this->request->get['field_group_id'] ?? false; |
| 86 | + |
| 87 | + $fields = []; |
| 88 | + |
| 89 | + if ($field_group_id) { |
| 90 | + $fieldGroup = new Field_GroupSQL(); |
| 91 | + $fields = $fieldGroup->getFields(['field_group_id' => $field_group_id])['fields'] ?? []; |
| 92 | + } |
| 93 | + $this->view->fields = $fields; |
| 94 | + $this->view->field_group_id = $field_group_id; |
| 95 | + |
| 96 | + $countryModel = new CountrySQL(); |
| 97 | + $options = $this->global; |
| 98 | + $options['status'] = 1; |
| 99 | + unset($options['limit']); |
| 100 | + $country = $countryModel->getAll($options); |
| 101 | + |
| 102 | + $this->view->countries = $country['country'] ?? []; |
| 103 | + |
| 104 | + $admin_path = \Vvveb\adminPath(); |
| 105 | + $controllerPath = $admin_path . 'index.php?module=localization/field-group'; |
| 106 | + $this->view->fieldsUrl = "$controllerPath&action=fields"; |
| 107 | + } |
| 108 | +} |
0 commit comments