/** * Returns an singleton instance of this class * * @param object $config * @param object $args * @return */ public static function getInstance($config, $args) { if (self::$instance == null) { self::$instance = new PriceSheetsManager($config, $args); } return self::$instance; }
public function getCompanyPriceSheetsNamesFromCache($companyId, $priceIndex) { $priceSheetsManager = PriceSheetsManager::getInstance($this->config, $this->args); $dtos = $priceSheetsManager->selectByField('company_id', $companyId); $sheetNames = array(); foreach ($dtos as $dto) { if (intval($dto->getPriceIndex()) == $priceIndex) { $sheetNames[] = $dto->getSheetTitle(); } } return $sheetNames; }
public function cachePriceInTables($companyId, $priceIndex) { $priceTextsManager = PriceTextsManager::getInstance($this->config, $this->args); $priceValuesManager = PriceValuesManager::getInstance($this->config, $this->args); $importPriceManager = ImportPriceManager::getInstance($this->config, $this->args); $priceSheetsManager = PriceSheetsManager::getInstance($this->config, $this->args); $companyLastPrices = $this->getCompanyLastPrices($companyId); if (empty($companyLastPrices) || !array_key_exists($priceIndex, $companyLastPrices)) { return false; } $companyLastPrice = $companyLastPrices[$priceIndex]; $file = DATA_DIR . "/companies_prices/" . $companyId . '/' . $companyLastPrice->getFileName() . '.' . $companyLastPrice->getFileExt(); if (!file_exists($file)) { return false; } $priceTextsManager->setCompanyPriceValuesReady($companyId, 0); $pHPExcelObject = ExcelUtils::getPHPExcelObject($file); $convertToText = ExcelUtils::convertToText($pHPExcelObject); if ($priceIndex == 0) { $priceTextsManager->setCompanyPriceText($companyId, $convertToText); } else { $priceTextsManager->appendCompanyPriceText($companyId, $convertToText); } $arrayValues = ExcelUtils::convertPriceToValuesArray($pHPExcelObject); if ($priceIndex == 0) { $priceValuesManager->setPriceValues($companyId, $priceIndex, $arrayValues); } else { $priceValuesManager->addPriceValues($companyId, $priceIndex, $arrayValues); } list($sheetNames, $sheetStates) = $importPriceManager->getCompanyPriceSheetsNames($pHPExcelObject); if ($priceIndex == 0) { $priceSheetsManager->deleteByField('company_id', $companyId); } foreach ($sheetNames as $sheetIndex => $sheetName) { $priceSheetsManager->addRow($companyId, $priceIndex, $sheetName, $sheetStates[$sheetIndex]); } $priceTextsManager->setCompanyPriceValuesReady($companyId, 1); }