Explorar o código

cleanup pages

andre %!s(int64=2) %!d(string=hai) anos
pai
achega
160c739901
Modificáronse 1 ficheiros con 10 adicións e 33 borrados
  1. 10 33
      app/UI/Client/DistributionList/Providers/AddListDataProvider.php

+ 10 - 33
app/UI/Client/DistributionList/Providers/AddListDataProvider.php

@@ -1,13 +1,7 @@
 <?php
 namespace ThurData\Servers\KerioEmail\App\UI\Client\DistributionList\Providers;
 use ThurData\Servers\KerioEmail\App\Enums\Kerio;
-use ThurData\Servers\KerioEmail\App\Helpers\KerioManager;
-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\Repository;
-use ThurData\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create\CreateDistributionList;
 use function ThurData\Servers\KerioEmail\Core\Helper\di;
-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;
 use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
@@ -25,13 +19,13 @@ class AddListDataProvider extends BaseDataProvider
 
     public function read()
     {
-        $hosting = Hosting::where('id', $this->getRequestValue('id'))->first();
-        $this->data['domain'] = $hosting->domain;
+        $domain = $this->getWhmcsParamByKey('domain');
+        $this->data['domain'] = $domain;
 
         $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
         try {
             $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
-            $domains = $api->getDomains(['id','name']);
+            $domainID = $api->getDomainId($domain);
         } catch (KerioApiException $error) {
             logModuleCall(
                 'kerioEmail',
@@ -42,19 +36,11 @@ class AddListDataProvider extends BaseDataProvider
             );
             return ['error' => $error->getMessage()];
         }
-        foreach($domains as $maildomain) {
-            if(($maildomain['name']) === $this->getWhmcsParamByKey('domain')){ 
-                $this->maildomainID = $maildomain['id'];
-                $this->maildomain = $maildomain['name'];
-            }
-        }
-        $productManager = new ProductManager();
-        $productManager->loadByHostingId($hosting->id);
         $fields = array(
             "id",
             "loginName");
         try {
-            $accounts = $api->getUsers($fields,$this->maildomainID);
+            $accounts = $api->getUsers($fields,$domainID);
         } catch (KerioApiException $error) {
             logModuleCall(
                 'kerioEmail',
@@ -67,17 +53,13 @@ class AddListDataProvider extends BaseDataProvider
         }
         $api->logout();
 
-        /**
-         *
-         * load lang
-         */
         $lang = di('lang');
 
         $this->availableValues['moderator']['none'] = $lang->absoluteT('none');
         foreach($accounts as $account)
         {
-            $this->availableValues['memberList'][$account['loginName']] = $account['loginName'] . '@' . $this->maildomain;
-            $this->availableValues['moderator'][$account['loginName']] = $account['loginName'] . '@' . $this->maildomain;
+            $this->availableValues['memberList'][$account['loginName']] = $account['loginName'] . '@' . $domain;
+            $this->availableValues['moderator'][$account['loginName']] = $account['loginName'] . '@' . $domain;
         }
 
         /**
@@ -136,9 +118,10 @@ class AddListDataProvider extends BaseDataProvider
     public function create()
     {
         
+        $domain = $this->getWhmcsParamByKey('domain');
         // add domain to members
         foreach($this->formData['memberList'] as $member) {
-            $memberList[] = $member . '@' . $this->getWhmcsParamByKey('domain');
+            $memberList[] = $member . '@' . $domain;
         }
 
         /**
@@ -167,7 +150,7 @@ class AddListDataProvider extends BaseDataProvider
         if($this->formData['moderator'] != 'none') {
             $moderator = array(
                 "hasId" => true,
-                "emailAddress" => $this->formData['moderator'] . '@' . $this->getWhmcsParamByKey('domain'),
+                "emailAddress" => $this->formData['moderator'] . '@' . $domain,
                 "fullName" => '',
                 "kind" => "Moderator"
             );
@@ -194,15 +177,10 @@ class AddListDataProvider extends BaseDataProvider
             array_push($paramsAddMembers, $extMember);
         }
 
-        /**
-         * hosting id
-         */
-        $hid = $this->request->get('id');
-
         $api = new KerioWhmcs('whmcsKerioEmail', 'Thurdata', '1.0');
         try {
             $api->login($this->getWhmcsParamByKey('serverhostname'), $this->getWhmcsParamByKey('serverusername'), $this->getWhmcsParamByKey('serverpassword'));
-            $domainID = $api->getDomainId($this->getWhmcsParamByKey('domain'));
+            $domainID = $api->getDomainId($domain);
         } catch (KerioApiException $error) {
             logModuleCall(
                 'kerioEmail',
@@ -246,7 +224,6 @@ class AddListDataProvider extends BaseDataProvider
 
         $api->logout();
 
-
         return (new HtmlDataJsonResponse())->setMessageAndTranslate('distributionListHasBeenAdded')->setStatusSuccess();
 
     }