| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?php
- namespace ModulesGarden\Servers\ProxmoxCloudVps\Packages\WhmcsService;
- use ModulesGarden\Servers\ProxmoxCloudVps\App\UI\Admin\ProductConfig\Pages\ConfigurableOptions;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\HandlerError\Exceptions\Exception;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\HandlerError\ErrorCodes\ErrorCodesLib;
- use ModulesGarden\Servers\ProxmoxCloudVps\Core\Models\Whmcs\CustomFieldValue;
- use WHMCS\Database\Capsule;
- class Service
- {
- protected $serviceId = null;
- protected $service = null;
- public function __construct($serviceId = null)
- {
- $this->setServiceId($serviceId);
- $this->loadWhmcsService();
- }
- /**
- * @return null
- */
- public function getServiceId()
- {
- return $this->serviceId;
- }
- public function getProductId()
- {
- return $this->service->packageid;
- }
- public function getServiceInstanceId()
- {
- $customFields = $this->getCustomFieldsValues();
- return $customFields['InstanceId']['value'];
- }
- public function getCustomFieldsValues()
- {
- $model = new CustomFieldValue();
- $fields = $model->select('tblcustomfields.fieldname as name', 'value')
- ->join('tblcustomfields', 'tblcustomfields.id', '=', 'fieldid')
- ->where('type', 'product')
- ->where('tblcustomfields.relid', $this->getProductId())
- ->where('tblcustomfieldsvalues.relid', $this->serviceId)->get();
- $fields = $fields ? $fields->toArray() : [];
- $parsedFields = [];
- foreach($fields as $field)
- {
- $nameParts = explode('|', $field['name']);
- $parsedFields[$nameParts[0]] = [
- 'rawName' => $nameParts[0],
- 'name' => $field['name'],
- 'value' => $field['value'],
- 'displayName' => $nameParts[1] ? $nameParts[1] : $nameParts[0]
- ];
- }
- return $parsedFields;
- }
- protected function setServiceId($serviceId = null)
- {
- $relationId = (int)$serviceId;
- if ($relationId <= 0)
- {
- throw new Exception(ErrorCodesLib::CORE_WS_000001);
- }
- $this->serviceId = $relationId;
- }
- protected function loadWhmcsService()
- {
- $this->service = \WHMCS\Service\Service::find($this->serviceId);
- }
- public function getConfigurableOptionsValues()
- {
- $options = Capsule::table('tblhostingconfigoptions')->select(['*', 'tblproductconfigoptionssub.optionname as subname'])
- ->join('tblproductconfigoptionssub', 'tblproductconfigoptionssub.id', '=', 'tblhostingconfigoptions.optionid')
- ->join('tblproductconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
- ->where('tblhostingconfigoptions.relid', $this->serviceId)->get();
- if (!($options))
- {
- return [];
- }
- $optionsData = [];
- foreach ($options as $option)
- {
- $rawOptionName = $this->configOptionNameToRaw($option->optionname) ? : $option->optionname;
- $optionsData[$rawOptionName] = [
- 'optionNameRaw' => $rawOptionName,
- 'optionName' => $option->optionname,
- 'subOptionName' => $option->subname,
- 'subOptionNameRaw' => $this->configOptionNameToRaw($option->subname) ? : $option->subname,
- 'value' => $option->optiontype == 4 ? $option->qty : $this->configOptionNameToRaw($option->subname) ? : $option->subname
- ];
- }
- return $optionsData;
- }
- public function configOptionNameToRaw($optionName)
- {
- if (!is_string($optionName) || trim($optionName) === '' || substr($optionName, 0, 1) === '|')
- {
- return false;
- }
- if (strpos($optionName, '|') > 0)
- {
- $parts = explode('|', $optionName);
- return $parts[0];
- }
- return $optionName;
- }
- }
|