| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace ModulesGarden\Servers\KerioEmail\App\UI\Client\EmailAlias\Providers;
- use ModulesGarden\Servers\KerioEmail\App\Helpers\KerioManager;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\AccountAlias;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Repository;
- use ModulesGarden\Servers\KerioEmail\Core\Models\Whmcs\Hosting;
- use ModulesGarden\Servers\KerioEmail\Core\UI\ResponseTemplates\HtmlDataJsonResponse;
- use ModulesGarden\Servers\KerioEmail\Core\UI\Widget\Forms\DataProviders\BaseDataProvider;
- /**
- *
- * Created by PhpStorm.
- * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
- * Date: 18.09.19
- * Time: 11:50
- * Class AddEmailAliasDataProvider
- */
- class AddEmailAliasDataProvider extends BaseDataProvider
- {
- public function read()
- {
- /**
- * hosting id
- */
- $hid = $this->getRequestValue('id');
- /**
- * hosting model
- */
- $hosting = Hosting::where('id', $hid)->first();
- /**
- * hosting domain
- */
- $this->data['domain'] = $hosting->domain;
- /**
- * load api
- * load repo
- * load accounts from repo
- */
- $accounts =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->repository()
- ->accounts
- ->getByDomainName($hosting->domain);
- /**
- * available accounts
- */
- foreach($accounts as $account)
- {
- $this->availableValues['mailbox'][$account->getId()] = $account->getName();
- }
- }
- public function create()
- {
- /**
- * hosting id
- */
- $hid = $this->request->get('id');
- /**
- * product manager allow to check product settings
- */
- $productManager = new ProductManager();
- $productManager->loadByHostingId($hid);
- /**
- *
- * get soap create alias service
- * set service configuration
- */
- $service =(new KerioManager())
- ->getApiByHosting($hid)
- ->soap
- ->service()
- ->createAccountAlias()
- ->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('emailAliasHasBeenCreated')->setStatusSuccess();
- }
- public function update()
- {
- // TODO: Implement update() method.
- }
- }
|