Parcourir la source

Bugfix: use attribute at forms

andre il y a 2 ans
Parent
commit
232a909d51

+ 43 - 134
app/UI/Client/Ressource/Providers/EditRessourceDataProvider.php

@@ -57,31 +57,28 @@ class EditRessourceDataProvider extends BaseDataProvider
             throw new \Exception($result->getLastError());
         }
 
-        logModuleCall(
-            'zimbraEmail',
-            __FUNCTION__,
-            $result,
-            'Debug Ressource',
-            $this->availableValues
-        );
-
-        $mailBoxParams              = explode('@', $result->getName());
-        $this->data['id']           = $result->getId();
-        $this->data['username']     = $mailBoxParams[0];
-        $this->data['domain']       = $mailBoxParams[1];
-        $this->data['display_name'] = $result->getDataResourceA(Ressource::ATTR_DISPLAY_NAME);
-        $this->data['status']       = $result->getDataResourceA(Ressource::ATTR_STATUS);
-        $this->data['title']        = $result->getDataResourceA(Ressource::ATTR_PROF_TITLE);
-        $this->data['phone']        = $result->getDataResourceA(Ressource::ATTR_PHONE);
-        $this->data['home_phone']   = $result->getDataResourceA(Ressource::ATTR_HOME_PHONE);
-        $this->data['mobile_phone'] = $result->getDataResourceA(Ressource::ATTR_MOBILE_PHONE);
-        $this->data['fax']          = $result->getDataResourceA(Ressource::ATTR_FAX);
-        $this->data['pager']        = $result->getDataResourceA(Ressource::ATTR_PAGER);
-        $this->data['country']      = $result->getDataResourceA(Ressource::ATTR_COUNTRY);
-        $this->data['city']         = $result->getDataResourceA(Ressource::ATTR_CITY);
-        $this->data['street']       = $result->getDataResourceA(Ressource::ATTR_STREET);
-        $this->data['post_code']    = $result->getDataResourceA(Ressource::ATTR_POSTAL_CODE);
-        $this->data['state']        = $result->getDataResourceA(Ressource::ATTR_STATE);
+        $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);
 
         $lang = di('lang');
         $this->availableValues['status'] = [
@@ -93,8 +90,6 @@ class EditRessourceDataProvider extends BaseDataProvider
             Zimbra::ACC_STATUS_PENDING       => $lang->absoluteT('zimbra','account','status','pending')
         ];
 
-        $this->readCosParams();
-
     }
 
     /**
@@ -107,8 +102,26 @@ class EditRessourceDataProvider extends BaseDataProvider
          */
         $hid = $this->request->get('id');
 
-
-        $fieldToProtection = ['firstname', 'lastname', 'display_name', 'company', 'title', 'country', 'state', 'city', 'street', 'post_code' ];
+        $fieldToProtection = [
+            'display_name',
+            'status',
+            'type',
+            'capacity',
+            'description',
+            'notes',
+            'contact',
+            'site',
+            'contact_mail',
+            'contact_phone',
+            'street',
+            'building',
+            'floor',
+            'room',
+            'post_code',
+            'town',
+            'state',
+            'county'
+        ];
 
         foreach ($this->formData as $field => &$value)
         {
@@ -129,7 +142,7 @@ class EditRessourceDataProvider extends BaseDataProvider
             ->getApiByHosting($hid)
             ->soap
             ->service()
-            ->updateRessource($productManager->get('cos_name'));
+            ->updateRessource();
         /**
          *
          * set product manager & form data to service
@@ -250,108 +263,4 @@ class EditRessourceDataProvider extends BaseDataProvider
 
         return (new HtmlDataJsonResponse())->setMessageAndTranslate('passwordChangedSuccessfully')->setStatusSuccess();
     }
-
-    /**
-     *
-     */
-    public function readCosParams()
-    {
-        $hid = $this->getRequestValue('id');
-        /**
-         * product manager allow to check product settings
-         */
-        $productManager = new ProductManager();
-        $productManager->loadByHostingId($hid);
-        if($productManager->get('cos_name') === ClassOfServices::CLASS_OF_SERVICE_QUOTA)
-        {
-            /**
-             *
-             * get soap create domain  service
-             */
-            $api =(new ZimbraManager())
-                ->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;
-                }
-
-                /**
-                 *
-                 * skip if class of services doesnt exists in config option list
-                 */
-                if($configoptions && !array_key_exists('cosQuota_'.$cos->getId(), $configoptions))
-                {
-                    continue;
-                }
-
-                /**
-                 * 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 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;
-    }
-
 }

+ 21 - 150
app/UI/Client/Ressource/Providers/RessourceDataProvider.php

@@ -54,11 +54,6 @@ class RessourceDataProvider extends BaseDataProvider
             Zimbra::RES_TYPE_EQUIPMENT       => $lang->absoluteT('zimbra','ressource','type','equipment')
         ];
 
-        /**
-         * product manager allow to check product settings
-         */
-
-        $this->readCosParams();
     }
 
     public function create()
@@ -68,8 +63,26 @@ class RessourceDataProvider extends BaseDataProvider
          */
         $hid = $this->request->get('id');
 
-
-        $fieldToProtection = ['firstname', 'lastname', 'display_name', 'company', 'title', 'country', 'state', 'city', 'street', 'post_code' ];
+        $fieldToProtection = [
+            'display_name',
+            'status',
+            'type',
+            'capacity',
+            'description',
+            'notes',
+            'contact',
+            'site',
+            'contact_mail',
+            'contact_phone',
+            'street',
+            'building',
+            'floor',
+            'room',
+            'post_code',
+            'town',
+            'state',
+            'county'
+        ];
 
         foreach ($this->formData as $field => &$value)
         {
@@ -90,7 +103,7 @@ class RessourceDataProvider extends BaseDataProvider
             ->getApiByHosting($hid)
             ->soap
             ->service()
-            ->createRessource($productManager->get('cos_name'));
+            ->createRessource();
         /**
          *
          * set product manager & form data to service
@@ -167,146 +180,4 @@ class RessourceDataProvider extends BaseDataProvider
          */
         return (new HtmlDataJsonResponse())->setMessageAndTranslate('massRessourceStatusHasBeenUpdated')->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 ZimbraManager())
-                ->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;
-    }
 }

+ 6 - 9
app/UI/Client/Ressource/Sections/EditAdditionalSection.php

@@ -24,21 +24,18 @@ class EditAdditionalSection extends FreeFieldsSection
 
     public function initContent()
     {
-        $this->generateDoubleSection([new Text('company'), new Text('title')]);
+        $this->generateDoubleSection([new Text('contact'), new Text('site')]);
 
-        $field = new Text('phone');
-        $this->addField($field);
+        $this->generateDoubleSection([new Text('contact_mail'), new Text('contact_phone')]);
 
-        $this->generateDoubleSection([new Text('home_phone'), new Text('mobile_phone')]);
+        $this->generateDoubleSection([new Text('street'), new Text('building')]);
 
-        $this->generateDoubleSection([new Text('fax'), new Text('pager')]);
+        $this->generateDoubleSection([new Text('floor'), new Text('room')]);
 
-        $this->generateDoubleSection([new Text('country'), new Text('state')]);
+        $this->generateDoubleSection([new Text('post_code'), new Text('town')]);
 
-        $this->generateDoubleSection([new Text('city'), new Text('street')]);
+        $this->generateDoubleSection([new Text('state'), new Text('county')]);
 
-        $field = new Text('post_code');
-        $this->addField($field);
     }
 
 }

+ 10 - 9
app/UI/Client/Ressource/Sections/EditGeneralSection.php

@@ -47,8 +47,6 @@ class EditGeneralSection extends FreeFieldsSection
         $field = new Hidden('id');
         $this->addField($field);
 
-        $this->generateDoubleSection([new Text('firstname'), new Text('lastname')]);
-
         $email =new InputGroup('usernameGroup');
 
         $email->addInputComponent((new InputGroupElements\Text('username'))->addHtmlAttribute('readonly','true'));
@@ -58,13 +56,16 @@ class EditGeneralSection extends FreeFieldsSection
 
         $this->generateDoubleSection([new Text('display_name'), new Select('status')]);
 
-        if($productManager->get('cos_name') === ClassOfServices::CLASS_OF_SERVICE_QUOTA)
-        {
-            $field = new Hidden('currentCosId');
-            $this->addField($field);
+        $type = new Select('type');
+        $capacity = new Text('capacity');
+
+        $this->generateDoubleSection([$type, $capacity]);
+
+        $field = new Text('description');
+        $this->addField($field);
+
+        $field = new Text('notes');
+        $this->addField($field);
 
-            $field = new Select('cosId');
-            $this->addField($field);
-        }
     }
 }