* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ class RetailcrmSettingsItems { /** * @var RetailcrmSettingsItem[] */ private $settings; public function __construct() { $this->settings = [ 'url' => new RetailcrmSettingsItemUrl('url', RetailCRM::API_URL), 'apiKey' => new RetailcrmSettingsItem('apiKey', RetailCRM::API_KEY), 'delivery' => new RetailcrmSettingsItemJson('delivery', RetailCRM::DELIVERY), 'payment' => new RetailcrmSettingsItemJson('payment', RetailCRM::PAYMENT), 'status' => new RetailcrmSettingsItemJson('status', RetailCRM::STATUS), 'outOfStockStatus' => new RetailcrmSettingsItemJson('outOfStockStatus', RetailCRM::OUT_OF_STOCK_STATUS), 'enableHistoryUploads' => new RetailcrmSettingsItemBool('enableHistoryUploads', RetailCRM::ENABLE_HISTORY_UPLOADS), 'enableBalancesReceiving' => new RetailcrmSettingsItemBool('enableBalancesReceiving', RetailCRM::ENABLE_BALANCES_RECEIVING), 'collectorActive' => new RetailcrmSettingsItemBool('collectorActive', RetailCRM::COLLECTOR_ACTIVE), 'synchronizeCartsActive' => new RetailcrmSettingsItemBool('synchronizeCartsActive', RetailCRM::SYNC_CARTS_ACTIVE), 'enableIcmlServices' => new RetailcrmSettingsItemBool('enableIcmlServices', RetailCRM::ENABLE_ICML_SERVICES), 'enableCorporate' => new RetailcrmSettingsItemBool('enableCorporate', RetailCRM::ENABLE_CORPORATE_CLIENTS), 'enableOrderNumberSending' => new RetailcrmSettingsItemBool('enableOrderNumberSending', RetailCRM::ENABLE_ORDER_NUMBER_SENDING), 'enableOrderNumberReceiving' => new RetailcrmSettingsItemBool('enableOrderNumberReceiving', RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING), 'enableCompanyAndVatNumberSend' => new RetailcrmSettingsItemBool('enableCompanyAndVatNumberSend', RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND), 'webJobs' => new RetailcrmSettingsItemBool('webJobs', RetailCRM::ENABLE_WEB_JOBS, '1'), 'debugMode' => new RetailcrmSettingsItemBool('debugMode', RetailCRM::ENABLE_DEBUG_MODE), 'deliveryDefault' => new RetailcrmSettingsItem('deliveryDefault', RetailCRM::DELIVERY_DEFAULT), 'paymentDefault' => new RetailcrmSettingsItem('paymentDefault', RetailCRM::PAYMENT_DEFAULT), 'synchronizedCartStatus' => new RetailcrmSettingsItem('synchronizedCartStatus', RetailCRM::SYNC_CARTS_STATUS), 'synchronizedCartDelay' => new RetailcrmSettingsItem('synchronizedCartDelay', RetailCRM::SYNC_CARTS_DELAY), 'collectorKey' => new RetailcrmSettingsItem('collectorKey', RetailCRM::COLLECTOR_KEY), ]; } public function getValue($key) { $this->checkKey($key); return $this->settings[$key]->getValue(); } public function issetValue($key) { $this->checkKey($key); return $this->settings[$key]->issetValue(); } public function updateValue($key) { $this->checkKey($key); $this->settings[$key]->updateValue(); } public function updateValueAll() { foreach ($this->settings as $key => $item) { $item->updateValue(); } } public function deleteValue($key) { $this->checkKey($key); $this->settings[$key]->deleteValue(); } public function deleteValueAll() { foreach ($this->settings as $item) { $item->deleteValue(); } } /** * @throws Exception */ private function checkKey($key) { if (!array_key_exists($key, $this->settings)) { throw new Exception("Invalid key `$key`!"); } } public function getValueStored($key) { $this->checkKey($key); return $this->settings[$key]->getValueStored(); } public function getValueStoredAll() { $result = []; foreach ($this->settings as $key => $item) { $result[$key] = $item->getValueStored(); } return $result; } public function getValueWithStored($key) { $this->checkKey($key); return $this->settings[$key]->getValueWithStored(); } public function getChanged() { $changed = []; foreach ($this->settings as $key => $setting) { if ($setting->issetValue()) { $changed[$key] = $setting->getValueStored(); } } return $changed; } }