/** * @param $postData array everything from the form post. The Generator is used in 3 different * contexts: for in-page generation, new tab/window or for prompting download of the data. */ public function __construct($postData) { $this->exportTarget = $postData["gdExportTarget"]; // inPage, newTab or promptDownload if ($this->exportTarget == "inPage") { $this->batchSize = $postData["gdBatchSize"]; $this->batchNum = $postData["gdCurrentBatchNum"]; } else { $this->batchSize = $postData["gdNumRowsToGenerate"]; $this->batchNum = 1; } $this->numResults = $postData["gdNumRowsToGenerate"]; if (Core::checkDemoMode() && !Core::checkIsLoggedIn()) { $maxDemoModeRows = Core::getMaxDemoModeRows(); if ($this->numResults > $maxDemoModeRows) { $this->numResults = $maxDemoModeRows; } } // always apply the max generated rows limitation. Technically this value could be lower than // the $maxDemoModeRows value above, but it's extremely unlikely & an acceptable restriction $maxGeneratedRows = Core::getMaxGeneratedRows(); if ($this->numResults > $maxGeneratedRows) { $this->numResults = $maxGeneratedRows; } $this->countries = isset($postData["gdCountries"]) ? $postData["gdCountries"] : array(); $this->dataTypes = DataTypePluginHelper::getDataTypeHash(Core::$dataTypePlugins); $this->postData = $postData; if (isset($postData["configurationID"])) { $this->configurationID = $postData["configurationID"]; } // make a note of whether this batch is the first / last. This is useful information for the // Export Types to know whether to output special content at the top or bottom $this->isFirstBatch = $this->batchNum == 1; $this->isLastBatch = $this->batchNum * $this->batchSize >= $this->numResults; $this->currentBatchFirstRow = ($this->batchNum - 1) * $this->batchSize + 1; $this->currentBatchLastRow = $this->currentBatchFirstRow + $this->batchSize > $this->numResults ? $this->numResults : $this->currentBatchFirstRow + $this->batchSize - 1; // figure out what we're going to need to generate $this->createDataSetTemplate($postData); // now we farm out the work of data generation to the selected Export Type $exportTypes = Core::$exportTypePlugins; $selectedExportType = null; foreach ($exportTypes as $currExportType) { if ($currExportType->getFolder() != $postData["gdExportType"]) { continue; } $this->exportType = $currExportType; break; } // set the value of isCompressionRequired if ($postData["gdExportTarget"] == "promptDownload" && $postData["gdExportTarget_promptDownload_zip"] == "doZip") { $this->isCompressionRequired = true; } }
/** * Helper to see if we're in demo mode, and limit the number of rows that can be generated. */ private function applyRowsGeneratedLimit() { if (Core::checkDemoMode() && !Core::checkIsLoggedIn()) { $maxDemoModeRows = Core::getMaxDemoModeRows(); if ($this->numResults > $maxDemoModeRows) { $this->numResults = $maxDemoModeRows; } } // always apply the max generated rows limitation. Technically this value could be lower than // the $maxDemoModeRows value above, but it's extremely unlikely & an acceptable restriction $maxGeneratedRows = Core::getMaxGeneratedRows(); if ($this->numResults > $maxGeneratedRows) { $this->numResults = $maxGeneratedRows; } }