| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /**
- * Class CreateRessource
- * User: Nessandro
- * Date: 2019-10-07
- * Time: 10:41
- * @package ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create
- */
- namespace ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Services\Create;
- use ModulesGarden\Servers\KerioEmail\App\Enums\ProductParams;
- use ModulesGarden\Servers\KerioEmail\App\Enums\Size;
- use ModulesGarden\Servers\KerioEmail\App\Enums\Kerio;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Product\ProductManager;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Interfaces\ApiService;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Models\Ressource;
- use ModulesGarden\Servers\KerioEmail\App\Libs\Kerio\Components\Api\Soap\Traits\ProductManagerHandler;
- use ModulesGarden\Servers\KerioEmail\Core\Helper\ConfigOptionsHelper;
- class CreateRessource extends ApiService
- {
- use ProductManagerHandler;
- use \ModulesGarden\Servers\KerioEmail\Core\UI\Traits\RequestObjectHandler;
- /**
- * added more conditions
- * @return bool
- */
- protected function isValid()
- {
- /**
- * check if product manager is set
- */
- if(!$this->productManager)
- {
- $this->setError('Product Manager Not Found');
- return false;
- }
- /**
- * domain name
- */
- if(!$this->formData['domain'])
- {
- $this->setError('Domain name can not be found.');
- return false;
- }
- /**
- *
- */
- return parent::isValid();
- }
- /**
- * @return mixed
- */
- protected function getRessources()
- {
- $ressources = $this->api->repository()->ressources->getRessources($this->formData['domain']);
- return $ressources;
- }
- /**
- * @return Ressource
- */
- protected function getModel()
- {
- /**
- * create new ressource in kerio
- */
- $ressource = new Ressource();
- $ressource->setName($this->formData['username'].'@'.$this->formData['domain']);
- $ressource->setPassword(html_entity_decode($this->formData['password']), ENT_QUOTES);
- /**
- * set ressource attributes
- */
- $ressource->setAttr(Ressource::ATTR_STATUS, $this->formData['status']);
- $ressource->setAttr(Ressource::ATTR_TYPE, $this->formData['type']);
- $ressource->setAttr(Ressource::ATTR_DISPLAY_NAME, $this->formData['display_name']);
- $ressource->setAttr(Ressource::ATTR_DESC, $this->formData['description']);
- $ressource->setAttr(Ressource::ATTR_NOTE, $this->formData['notes']);
- $ressource->setAttr(Ressource::ATTR_CONT, $this->formData['contact']);
- $ressource->setAttr(Ressource::ATTR_CONT_EMAIL, $this->formData['contact_mail']);
- $ressource->setAttr(Ressource::ATTR_CONT_PHONE, $this->formData['contact_phone']);
- $ressource->setAttr(Ressource::ATTR_SITE, $this->formData['site']);
- $ressource->setAttr(Ressource::ATTR_BUILDING, $this->formData['building']);
- $ressource->setAttr(Ressource::ATTR_FLOOR, $this->formData['floor']);
- $ressource->setAttr(Ressource::ATTR_ROOM, $this->formData['room']);
- $ressource->setAttr(Ressource::ATTR_CAPACITY, $this->formData['capacity']);
- $ressource->setAttr(Ressource::ATTR_STREET, $this->formData['street']);
- $ressource->setAttr(Ressource::ATTR_TOWN, $this->formData['town']);
- $ressource->setAttr(Ressource::ATTR_POSTAL_CODE, $this->formData['post_code']);
- $ressource->setAttr(Ressource::ATTR_COUNTY, $this->formData['county']);
- $ressource->setAttr(Ressource::ATTR_STATE, $this->formData['state']);
- $ressource->setAttr(Ressource::ATTR_AUTO, $this->formData['auto_accept'] == 'on' ? 'TRUE' : 'FALSE' );
- $ressource->setAttr(Ressource::ATTR_BUSY, $this->formData['auto_busy'] == 'on' ? 'TRUE' : 'FALSE' );
- foreach($this->productManager->getKerioConfiguration() as $key => $value)
- {
- $value = $value === ProductParams::SWITCHER_ENABLED ? Kerio::ATTR_ENABLED : Kerio::ATTR_DISABLED;
- $ressource->setAttr($key, $value);
- }
- return $ressource;
- }
- /**
- * @return bool|mixed|Ressource|void
- */
- protected function process()
- {
- /**
- *
- */
- $model = $this->getModel();
- /**
- * create ressource in ZIMBRA
- */
- $result = $this->api->ressource->create($model);
- /**
- * problem with create ressource
- */
- if(!$result)
- {
- $this->setError($this->api->ressource->getLastResult()->getLastErrorCode());
- return false;
- }
- return $result;
- }
- }
|