| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Admin\ProductConfiguration\Providers;
- use ThurData\Servers\KerioEmail\App\Enums\ProductParams;
- use ThurData\Servers\KerioEmail\App\Enums\Size;
- use ThurData\Servers\KerioEmail\App\Enums\Kerio;
- use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
- use ThurData\Servers\KerioEmail\App\Traits\LangHandler;
- use ThurData\Servers\KerioEmail\App\Traits\ServerParams;
- use ThurData\Servers\KerioEmail\App\Traits\KerioApiHandler;
- use ThurData\Servers\KerioEmail\Core\App\Controllers\Interfaces\AdminArea;
- use ThurData\Servers\KerioEmail\Core\Traits\Lang;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- use \ThurData\Servers\KerioEmail\App\Models\ProductConfiguration;
- use ThurData\Servers\KerioEmail\App\Libs\Migrations\Drivers\Version1To2;
- use \Illuminate\Database\Capsule\Manager as DB;
- /**
- *
- * Created by PhpStorm.
- * User: ThurData
- * Date: 29.08.19
- * Time: 10:27
- * Class ProductConfigurationDataProvider
- */
- class ProductConfigurationDataProvider extends BaseDataProvider implements AdminArea
- {
- const FORM_DATA = [
- 'acc_limit',
- 'acc_base',
- 'alias_limit',
- 'cos_name',
- 'login_link',
- 'filterAccountsByCOS',
- 'acc_size',
- 'domain_alias_limit',
- 'dist_list_limit',
- 'domainMaxSize',
- 'domainBaseSize',
- 'cos',
- 'ca_emailAccountPage',
- 'ca_ressourcePage',
- 'ca_distributionListPage',
- 'ca_goToWebmailPage',
- 'ca_emailAliasesPage',
- 'ca_domainAliasesPage',
- 'ca_logInToMailboxButton',
- ];
- const FILED_NOT_UPDATED = [
- 'login_link'
- ];
- use LangHandler;
- /**
- *
- */
- public function read()
- {
- /**
- * load params from previous version
- */
- $this->checkConfigOrLoadFromPrevious($this->getRequestValue('id'));
- $this->loadDefaultData();
- $this->overrideDefaultDataByProductConfig();
- }
- /**
- *
- */
- public function update()
- {
- $this->catchFormData();
- $cos = $this->formData['cos'];
- unset($this->formData['cos']);
- $productId = $this->request->get('id');
- foreach ($this->formData as $key => $value)
- {
- ProductConfiguration::updateOrCreate(['product_id' => $productId, 'setting' => $key], ['value' => $value]);
- }
- /**
- * save serialized cos
- */
- ProductConfiguration::updateOrCreate(['product_id' => $productId, 'setting' => 'cos'], ['value' => json_encode($cos)]);
- }
- /**
- *
- */
- protected function loadDefaultData()
- {
- /* default data */
- $this->data['acc_limit'] = Size::DEFAULT_ACC_LIMIT;
- $this->data['acc_base'] = Size::DEFAULT_ACC_BASE;
- $this->data['acc_size'] = Size::DEFAULT_ACC_SIZE;
- $this->data['alias_limit'] = Size::DEFAULT_ALIAS_LIMIT;
- $this->data['domain_alias_limit'] = Size::DEFAULT_DOMAIN_ALIAS_LIMIT;
- $this->data['cos_name'] = ClassOfServices::CUSTOM_ZIMBRA;
- $this->data['dist_list_limit'] = Size::DEFAULT_DIST_ALIAS_LIMIT;
- $this->data['login_link'] = Kerio::DEFAULT_LOGIN_LINK;
- $this->data['domainMaxSize'] = Size::UNLIMITED;
- $this->data['domainBaseSize'] = Size::UNLIMITED;
- /* available class of services*/
- $this->availableValues['cos_name'] = [
- ClassOfServices::CUSTOM_ZIMBRA => $this->getLang()->absoluteT('addonAA', 'configuration', 'product', 'kerio', 'cos', 'Use Custom Settings'),
- ClassOfServices::ZIMBRA_CONFIG_OPTIONS => $this->getLang()->absoluteT('addonAA', 'configuration', 'product', 'kerio', 'cos', 'Allow clients to choose Class Of Service'),
- ClassOfServices::CLASS_OF_SERVICE_QUOTA => $this->getLang()->absoluteT('addonAA', 'configuration', 'product', 'kerio', 'cos', 'Allow clients to choose Class Of Service Quota Per Account'),
- ];
- $manager = new KerioManager();
- $repository = $manager->getApiByProduct($this->getRequestValue('id'))->soap->repository();
- $cosList = $repository->cos->all();
- /**
- * class of services from API
- */
- foreach ($cosList as $cos)
- {
- /**
- * @var $cos \ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService
- */
- $this->availableValues['cos_name'][$cos->getId()] = $this->getLang()->absoluteT($cos->getName());
- }
- }
- /**
- * @description load data from database
- */
- protected function overrideDefaultDataByProductConfig()
- {
- $settings = ProductConfiguration::where('product_id', $this->request->get('id'))->get();
- foreach ($settings as $setting)
- {
- if('cos' === $setting->setting)
- {
- $this->data[$setting->setting] = json_decode($setting->value, true);
- continue;
- }
- $this->data[$setting->setting] = $setting->value;
- }
- }
- /**
- * @description catch params from request
- */
- protected function catchFormData()
- {
- /**
- * catch from request
- */
- $params = array_merge(Kerio::BASE_ACCOUNT_CONFIG,self::FORM_DATA);
- foreach ($params as $name)
- {
- if ($value = $this->request->get($name))
- {
- $this->formData[$name] = $value;
- }elseif(!in_array($name,self::FILED_NOT_UPDATED)){
- $this->formData[$name] = ProductParams::SWITCHER_DISABLED;
- }else{
- $this->formData[$name] = '';
- }
- }
- }
- private function checkConfigOrLoadFromPrevious($id)
- {
- if(ProductConfiguration::where('product_id', $id)->first())
- {
- return;
- }
- $migration = new Version1To2\Settings();
- $exists = DB::schema()->hasTable($migration->getFromTable());
- if(!$exists)
- {
- return;
- }
- $previous = DB::table($migration->getFromTable())->where('product_id', $id)->get();
- /**
- *
- */
- $prodManager = new ProductConfiguration();
- /**
- *
- * storage all params per product id
- */
- foreach($previous as $setting)
- {
- $settings[$setting->product_id][$setting->setting] = $setting->value;
- $products[] = $setting->product_id;
- }
- /**
- *
- * update setting data & save
- */
- foreach($settings as $prodId => $settingsArray)
- {
- $attrs = $migration->updateValues($settingsArray, $prodId);
- foreach($attrs as $key => $value)
- {
- $prodManager->updateOrCreate(['product_id' => $prodId, 'setting' => $key],['value' => $value]);
- }
- }
- /**
- *
- * new options
- */
- foreach($migration->getNewFields() as $key => $value)
- {
- $prodManager->updateOrCreate(['product_id' => $id, 'setting' => $key],['value' => $value]);
- }
- }
- }
|