andre пре 2 година
родитељ
комит
e07ab5c9a5
1 измењених фајлова са 59 додато и 107 уклоњено
  1. 59 107
      app/UI/Client/Ressource/Providers/EditRessourceDataProvider.php

+ 59 - 107
app/UI/Client/Ressource/Providers/EditRessourceDataProvider.php

@@ -17,6 +17,7 @@ use function ThurData\Servers\KerioEmail\Core\Helper\di;
 use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
 use ThurData\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
 use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
 use ThurData\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
 use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
 use ThurData\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
+use ThurData\Servers\KerioEmail\Api\KerioWhmcs;
 
 
 /**
 /**
  *
  *
@@ -34,62 +35,60 @@ class EditRessourceDataProvider extends BaseDataProvider
      */
      */
     public function read()
     public function read()
     {
     {
-        /**
-         * hosting id
-         */
-        $hid = $this->getRequestValue('id');
-        /**
-         * load hosting
-         */
-        $hosting = Hosting::where('id', $hid)->first();
-
-        /**
-         * load api
-         */
-        $api = (new KerioManager())->getApiByServer($hosting->server);
-
-        $repository = new Repository($api->soap);
-
-        $result = $repository->ressources->getRessourceOptionsById($this->actionElementId);
-
-        if($result instanceof Response && $result->getLastError())
-        {
-            throw new \Exception($result->getLastError());
+        $fields = array(
+            "id",
+            "name",
+            "description",
+            "type",
+            "isEnabled",
+            "manager"
+        );
+        $cond = array(
+                "fieldName" => "id",
+                "comparator" => "Eq",
+                "value" => $this->actionElementId
+        );
+
+        $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'));
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
         }
         }
-
-        $mailBoxParams               = explode('@', $result->getName());
-        $this->data['id']            = $result->getId();
-        $this->data['username']      = $mailBoxParams[0];
-        $this->data['domain']        = $mailBoxParams[1];
-        $this->data['status']        = $result->getDataResourceA(Ressource::ATTR_STATUS);
-        $this->data['type']          = $result->getDataResourceA(Ressource::ATTR_TYPE);
-        $this->data['display_name']  = $result->getDataResourceA(Ressource::ATTR_DISPLAY_NAME);
-        $this->data['description']   = $result->getDataResourceA(Ressource::ATTR_DESC);
-        $this->data['capacity']      = $result->getDataResourceA(Ressource::ATTR_CAPACITY);
-        $this->data['notes']         = $result->getDataResourceA(Ressource::ATTR_NOTE);
-        $this->data['contact']       = $result->getDataResourceA(Ressource::ATTR_CONT);
-        $this->data['site']          = $result->getDataResourceA(Ressource::ATTR_SITE);
-        $this->data['contact_mail']  = $result->getDataResourceA(Ressource::ATTR_CONT_EMAIL);
-        $this->data['contact_phone'] = $result->getDataResourceA(Ressource::ATTR_CONT_PHONE);
-        $this->data['street']        = $result->getDataResourceA(Ressource::ATTR_STREET);
-        $this->data['building']      = $result->getDataResourceA(Ressource::ATTR_BUILDING);
-        $this->data['floor']         = $result->getDataResourceA(Ressource::ATTR_FLOOR);
-        $this->data['room']          = $result->getDataResourceA(Ressource::ATTR_ROOM);
-        $this->data['post_code']     = $result->getDataResourceA(Ressource::ATTR_POSTAL_CODE);
-        $this->data['town']          = $result->getDataResourceA(Ressource::ATTR_TOWN);
-        $this->data['state']         = $result->getDataResourceA(Ressource::ATTR_STATE);
-        $this->data['county']        = $result->getDataResourceA(Ressource::ATTR_COUNTY);
-        $this->data['auto_accept']   = $result->getDataResourceA(Ressource::ATTR_AUTO) == 'TRUE' ? 'on' : 'off';
-        $this->data['auto_busy']     = $result->getDataResourceA(Ressource::ATTR_BUSY) == 'TRUE' ? 'on' : 'off';
+        try {
+            $ressource = $api->getResources($fields,$domainID,$cond);
+        } catch (KerioApiException $error) {
+            logModuleCall(
+                'kerioEmail',
+                __FUNCTION__,
+                $error,
+                'Debug Error',
+                $error->getMessage()
+            );
+            return ['error' => $error->getMessage()];
+        }
+        $api->logout();
 
 
         $lang = di('lang');
         $lang = di('lang');
+        $this->data['id']            = $ressource[0]['id'];
+        $this->data['name']          = $ressource[0]['name'];
+        $this->data['domain']        = $this->getWhmcsParamByKey('domain');
+        $this->data['status']        = $ressource[0]['isEnabled'] == true ? Kerio::ACC_STATUS_ACTIVE : Kerio::ACC_STATUS_CLOSED;
+        $this->data['type']          = $ressource[0]['type'] === 'Room' ? di('lang')->absoluteT('kerio','ressource','type','location') : di('lang')->absoluteT('kerio','ressource','type','equipment');;
+        $this->data['description']   = $ressource[0]['description'];
+        $this->data['manager']       = $ressource[0]['magager'];
+
         $this->availableValues['status'] = [
         $this->availableValues['status'] = [
             Kerio::ACC_STATUS_ACTIVE        => $lang->absoluteT('kerio','account','status','active'),
             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_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')
         ];
         ];
 
 
         $this->availableValues['type'] = [
         $this->availableValues['type'] = [
@@ -104,74 +103,27 @@ class EditRessourceDataProvider extends BaseDataProvider
      */
      */
     public function update()
     public function update()
     {
     {
-        /**
-         * hosting id
-         */
-        $hid = $this->request->get('id');
-
         $fieldToProtection = [
         $fieldToProtection = [
-            'display_name',
+            'name',
             'status',
             'status',
             'type',
             'type',
-            'capacity',
             'description',
             'description',
-            'notes',
-            'contact',
-            'site',
-            'contact_mail',
-            'contact_phone',
-            'street',
-            'building',
-            'floor',
-            'room',
-            'post_code',
-            'town',
-            'state',
-            'county',
-            'auto_accept',
-            'auto_busy'
+            'managert'
         ];
         ];
 
 
+        logModuleCall(
+            'kerioEmail',
+            __FUNCTION__,
+            $this->formData,
+            'Debug Error',
+            $this->actionElementId
+        );
+
         foreach ($this->formData as $field => &$value)
         foreach ($this->formData as $field => &$value)
         {
         {
             $value = in_array($field, $fieldToProtection) ? htmlentities($value) : $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()
-            ->updateRessource();
-        /**
-         *
-         * 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('ressourceHasBeenUpdated')->setStatusSuccess();
         return (new HtmlDataJsonResponse())->setMessageAndTranslate('ressourceHasBeenUpdated')->setStatusSuccess();
     }
     }