| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307 |
- <?php
- namespace ThurData\Servers\KerioEmail\App\UI\Client\EmailAccount\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\Http\Admin\ProductConfiguration;
- use ThurData\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Helpers\ServiceFactory;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Account;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\ClassOfService;
- use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository\ClassOfServices;
- use ThurData\Servers\KerioEmail\App\Services\ConfigurableOptions\Strategy\Types\ClassOfServicesOptions;
- use function ThurData\Servers\KerioEmail\Core\Helper\di;
- use ThurData\Servers\KerioEmail\Core\Http\JsonResponse;
- use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
- use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- /**
- *
- * Created by PhpStorm.
- * User: Tomasz Bielecki ( tomasz.bi@thurdata.com )
- * Date: 10.09.19
- * Time: 13:06
- * Class AccountDataProvider
- */
- class AccountDataProvider extends BaseDataProvider
- {
- public function read()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- $hosting = Hosting::where('id', $hid)->first();
- //todo refactor
- $this->data['domain'] = $hosting->domain;
- $lang = di('lang');
- $this->availableValues['status'] = [
- Kerio::ACC_STATUS_ACTIVE => $lang->absoluteT('kerio','account','status','active'),
- Kerio::ACC_STATUS_LOCKED => $lang->absoluteT('kerio','account','status','locked'),
- Kerio::ACC_STATUS_MAINTENANCE => $lang->absoluteT('kerio','account','status','maintenance'),
- Kerio::ACC_STATUS_CLOSED => $lang->absoluteT('kerio','account','status','closed'),
- Kerio::ACC_STATUS_LOCKOUT => $lang->absoluteT('kerio','account','status','lockout'),
- Kerio::ACC_STATUS_PENDING => $lang->absoluteT('kerio','account','status','pending')
- ];
- /**
- * product manager allow to check product settings
- */
- $this->readCosParams();
- }
- public function create()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- $fieldToProtection = ['firstname', 'lastname', 'display_name', 'company', 'title', 'country', 'state', 'city', 'street', 'post_code' ];
- foreach ($this->formData as $field => &$value)
- {
- $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $value;
- }
- /**
- * product manager allow to check product settings
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * get soap create domain service
- */
- $service =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->createAccount($productManager->get('cos_name'));
- /**
- *
- * set product manager & form data to service
- */
- $service
- ->setProductManager($productManager)
- ->setFormData($this->formData);
- /**
- *
- * run service
- */
- $result = $service->run();
- /**
- *
- * return success or error response
- */
- if(!$result)
- {
- return (new HtmlDataJsonResponse())->setMessageAndTranslate($service->getError())->setStatusError();
- }
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('emailAccountHasBeenAdded')->setStatusSuccess();
- }
- public function updateStatus()
- {
- }
- public function update()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- /**
- * product manager allow to check product settings
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * get soap create domain service
- */
- $service =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->updateAccountStatus()
- ->setProductManager($productManager)
- ;
- /**
- *
- * set product manager & form data to service
- */
- /**
- * run service for each id
- */
- foreach($this->request->get('massActions') as $id)
- {
- $service->setFormData(['status' => $this->formData['status'], 'id' => $id]);
- $result = $service->run();
- }
- /**
- * return success
- */
- return (new HtmlDataJsonResponse())->setMessageAndTranslate('massEmailAccountStatusHasBeenUpdated')->setStatusSuccess();
- }
- /**
- *
- * read data per cos_name
- */
- protected function readCosParams()
- {
- $hid = $this->request->get('id');
- /**
- *
- * load product manager
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * check if class of services should be selectable
- */
- if($productManager->get('cos_name') === ClassOfServices::CLASS_OF_SERVICE_QUOTA)
- {
- /**
- *
- * get soap create domain service
- */
- $api =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap;
- /**
- *
- * get cos from API
- */
- $classOfServices = $api->repository()->cos->all();
- /**
- *
- * load configurable options coses
- */
- $supportedCos = $productManager->getSettingCos();
- /**
- *
- * add COS to array
- */
- $configoptions = $this->getFilteredCosConfigurableOptions();
- foreach($classOfServices as $cos)
- {
- /**
- *
- *
- * skip COS which is not used in configurable options
- */
- if(!($supportedCos && array_key_exists($cos->getId(), $supportedCos)))
- {
- continue;
- }
- /**
- * 1. check if config opts are available
- * 2. skip if class of services doesnt exists in config option list
- */
- if($configoptions && !array_key_exists('cosQuota_'.$cos->getId(), $configoptions))
- {
- continue;
- }
- /**
- * 1. check if config opts are available
- * 2. skip not purchased as CO
- */
- if ($configoptions && $configoptions['cosQuota_'.$cos->getId()] == 0)
- {
- continue;
- }
- /**
- * 1. check if config opts are not available
- * 2. skip if quantity === 0
- */
- if(!$configoptions && $supportedCos[$cos->getId()] == 0)
- {
- continue;
- }
- /* @var $cos ClassOfService*/
- $this->availableValues['cosId'][$cos->getId()] = $cos->getMbMailQuote().' MB';
- }
- return $this;
- }
- /**
- *
- * check if class of service is choosen by config opt
- */
- if($productManager->get('cos_name') === ClassOfServices::ZIMBRA_CONFIG_OPTIONS)
- {
- $this->data['cosId'] = key($productManager->getSettingCos());
- return $this;
- }
- /**
- *
- * if cos_name is dedicated (loaded from API)
- */
- if($productManager->get('cos_name') !== ClassOfServices::CUSTOM_ZIMBRA)
- {
- /**
- * if dedicated class of service has been selected
- */
- $this->data['cosId'] = $productManager->get('cos_name');
- return $this;
- }
- return $this;
- }
- /**
- * @return bool|mixed
- */
- protected function getFilteredCosConfigurableOptions()
- {
- $configoptions = $this->getWhmcsParamByKey('configoptions');
- foreach($configoptions as $key => $value)
- {
- if(strpos($key, ClassOfServicesOptions::COS_CONFIG_OPT_PREFIX) === false)
- {
- unset($configoptions[$key]);
- }
- }
- return $configoptions;
- }
- }
|