<?php
 namespace App\Config; class ExportData_ActiveEntities extends SystemVars { protected $dbVarsPrefix = 'exportData_'; protected $dbVarsList = []; private function checkEntityType($var) { $CFG = \Engine\Loader_Cfg::getInstance()->getGlobal(); $issueDocsCfg = \App\Config\IssueDocuments::getInstance(); $varComponents = []; $varComponents = explode('|', $var); list ($category, $docType, $varName) = $varComponents; if (count($varComponents) == 1) { if (!in_array($category, ['currencyExchange', 'legalEntity', 'supplier', 'supplierInvoice', 'balance'])) { if (!$issueDocsCfg->exists($category) || $issueDocsCfg->getDocPivot($category)!='invoice') { throw new \Exception(sprintf('The var (%s) is not active or the pivot id not `invoice`', $var)); } } } if (count($varComponents) == 2) { if (!in_array($category, ['cashing', 'payment',])) { throw new \Exception(sprintf('The var name format should be `cashing|varName` or `payment|varName`. Current var name: %s', $var)); } if ($category == 'cashing' && !\App\Config\CashingDocuments::getInstance()->exists($docType)) { throw new \Exception(sprintf('The var name (%s) is incorrect or not active. Current var name: %s', $docType, $var)); } if ($category == 'payment' && !\App\Config\PaymentDocuments::getInstance()->exists($docType)) { throw new \Exception(sprintf('The var name (%s) is incorrect or not active. Current var name: %s', $docType, $var)); } } if (count($varComponents) == 3) { if (!in_array($category, ['cashbookDoc', 'importedDocument']) || !in_array($docType, ['cashing', 'payment',])) { throw new \Exception(sprintf('The var name format should be `cashbookDoc|cashing|varName` or `cashbookDoc|payment|varName` or `importedDocument|cashing|varName` or `importedDocument|payment|varName`. Current var name: %s', $var)); } if ($category=='cashbookDoc' && !$CFG['cashBook']['documentTypes'][$docType][$varName]['active']) { throw new \Exception(sprintf('The var name (%s) is incorrect or not active. Current var name: %s', $varName, $var)); } if ($category=='importedDocument' && $docType=='cashing' && !\App\Config\CashingDocuments::getInstance()->exists($varName)) { throw new \Exception(sprintf('The var name (%s) is incorrect or not active. Current var name: %s', $varName, $var)); } if ($category=='importedDocument' && $docType=='payment' && !\App\Config\PaymentDocuments::getInstance()->exists($varName)) { throw new \Exception(sprintf('The var name (%s) is incorrect or not active. Current var name: %s', $varName, $var)); } } } private function checkEntityValues($var, $value) { list($category, , ) = explode('|', $var); if (in_array($category, ['cashing','payment', 'cashbookDoc'])) { $valueList = unserialize($value); if (!is_array($valueList)) { throw new \Exception('Document options is not a valid array.'); } if (count($valueList) > 2) { throw new \Exception('Entity values is not a valid array.'); } if (!isset($valueList['block'])) { throw new \Exception('Entity value `block` key does not exist.'); } if (!isset($valueList['issue'])) { throw new \Exception('Entity value `issue` key does not exist.'); } } if (in_array($category, ['importedDocument'])) { $valueList = unserialize($value); if (!is_array($valueList)) { throw new \Exception('Document options is not a valid array.'); } if (count($valueList) != 1) { throw new \Exception('Entity values is not a valid array.'); } if (!isset($valueList['issue'])) { throw new \Exception('Entity value `issue` key does not exist.'); } } } protected function save_check() { parent::save_check(); if ($this->itemsList) { foreach($this->itemsList as $var => $value) { $this->checkEntityType($var); $this->checkEntityValues($var, $value); } } } public function get($var) { $this->checkEntityType($var); $docOptions = parent::get($var); list($category, , ) = explode('|', $var); if (in_array($category, ['cashing','payment', 'cashbookDoc', 'importedDocument'])) { $docOptionsList = unserialize((string)$docOptions); return $docOptionsList; } return $docOptions; } public function set($var, $docOptions) { list($category, , ) = explode('|', $var); if (in_array($category, ['cashing','payment', 'cashbookDoc', 'importedDocument'])) { return parent::set($var, serialize($docOptions)); } return parent::set($var, $docOptions); } }