Get export model based on given identifier

@param integer $exportId          An export identifier
@param boolean $dispatchException Dispatch exception if model doesn't exist

@throws \ErrorException

@return null|\Thelia\Model\Export
16794
public function getExport($exportId, $dispatchException = false)
    {
        $export = (new ExportQuery)->findPk($exportId);

        if ($export === null && $dispatchException) {
            throw new \ErrorException(
                Translator::getInstance()->trans(
                    'There is no id "%id" in the exports',
                    [
                        '%id' => $exportId
                    ]
                )
            );
        }

        return $export;
    }
436577
protected function handleExceptionsDuringExport()
    {
        if (count($this->exceptionsDuringExport) > 0) {
            $exceptionMessages = '';
            foreach ($this->exceptionsDuringExport as $i => $exception) {
                $exceptionMessages .= "\n" . $i . ': ' . get_class($exception) . "\n" . $exception->getMessage() . "\n";
            }

            throw new ExportException(sprintf('%s exceptions occurred during export. Please see the log for the full exceptions (including stack traces). The exception messages follow below: %s', count($this->exceptionsDuringExport), $exceptionMessages), 1409057360);
        }
    }
963552
public function executeExportCSVCommand(ExportCommand $exportCommand)
    {
        $translations = $this->getTranslations($exportCommand);
        /** @var CSVFileExporter $exporter */
        $exporter = $this->exporter->getExporterByExtension($exportCommand->getFormat());
        $exporter->setLocales($this->determineLocalesToImport($exportCommand));

        return $exporter->export($translations);
    }
797335
protected function getModelFromSerializedId($serializedId)
    {
        $modelId      = ModelId::fromSerialized($serializedId);
        $dataProvider = $this->getEnvironment()->getDataProvider($modelId->getDataProviderName());
        $model        = $dataProvider->fetch($dataProvider->getEmptyConfig()->setId($modelId->getId()));

        if (null === $model) {
            $event = new LogEvent(
                'A record with the ID "' . $serializedId . '" does not exist in "' .
                $this->getEnvironment()->getDataDefinition()->getName() . '"',
                'Ajax executePostActions()',
                TL_ERROR
            );
            $this->getEnvironment()->getEventDispatcher()->dispatch(ContaoEvents::SYSTEM_LOG, $event);

            throw new ResponseException(new Response(Response::$statusTexts[400], 400));
        }

        return $model;
    }
559911
public function getExporter($type, $dest = null)
    {
        if ( ! isset(self::$_exporterDrivers[$type])) {
            throw ExportException::invalidExporterDriverType($type);
        }

        $class = self::$_exporterDrivers[$type];

        return new $class($dest);
    }
85805
public function export()
    {
        // Disable any access to use of WorkflowExport if user has no SecurityAdmin access
        if (!Permission::check('CMS_ACCESS_SecurityAdmin')) {
            throw new Exception(_t('SilverStripe\\ErrorPage\\ErrorPage.CODE_403', '403 - Forbidden'), 403);
        }
        $def = $this->getDefinition();
        $templateData = new ArrayData(array(
            'ExportMetaData' => $this->ExportMetaData(),
            'ExportActions' => $def->Actions(),
            'ExportUsers' => $def->Users(),
            'ExportGroups' => $def->Groups()
        ));
        return $this->format($templateData);
    }
667166
public function exportAction($id)
    {
        /** @var \Thelia\Handler\Exporthandler $exportHandler */
        $exportHandler = $this->container->get('thelia.export.handler');

        $export = $exportHandler->getExport($id);
        if ($export === null) {
            return $this->pageNotFound();
        }

        $form = $this->createForm(AdminForm::EXPORT);

        try {
            $validatedForm = $this->validateForm($form);

            set_time_limit(0);

            $lang = (new LangQuery)->findPk($validatedForm->get('language')->getData());

            /** @var \Thelia\Core\Serializer\SerializerManager $serializerManager */
            $serializerManager = $this->container->get(RegisterSerializerPass::MANAGER_SERVICE_ID);
            $serializer = $serializerManager->get($validatedForm->get('serializer')->getData());

            $archiver = null;
            if ($validatedForm->get('do_compress')->getData()) {
                /** @var \Thelia\Core\Archiver\ArchiverManager $archiverManager */
                $archiverManager = $this->container->get(RegisterArchiverPass::MANAGER_SERVICE_ID);
                $archiver = $archiverManager->get($validatedForm->get('archiver')->getData());
            }

            $rangeDate = null;
            if ($validatedForm->get('range_date_start')->getData()
                && $validatedForm->get('range_date_end')->getData()
            ) {
                $rangeDate = [
                    'start' => $validatedForm->get('range_date_start')->getData(),
                    'end' =>$validatedForm->get('range_date_end')->getData()
                ];
            }

            $exportEvent = $exportHandler->export(
                $export,
                $serializer,
                $archiver,
                $lang,
                $validatedForm->get('images')->getData(),
                $validatedForm->get('documents')->getData(),
                $rangeDate
            );

            $contentType = $exportEvent->getSerializer()->getMimeType();
            $fileExt = $exportEvent->getSerializer()->getExtension();

            if ($exportEvent->getArchiver() !== null) {
                $contentType = $exportEvent->getArchiver()->getMimeType();
                $fileExt = $exportEvent->getArchiver()->getExtension();
            }

            $header = [
                'Content-Type' => $contentType,
                'Content-Disposition' => sprintf(
                    '%s; filename="%s.%s"',
                    ResponseHeaderBag::DISPOSITION_ATTACHMENT,
                    $exportEvent->getExport()->getFileName(),
                    $fileExt
                )
            ];

            return new BinaryFileResponse($exportEvent->getFilePath(), 200, $header, false);
        } catch (FormValidationException $e) {
            $form->setErrorMessage($this->createStandardFormValidationErrorMessage($e));
        } catch (\Exception $e) {
            $this->getParserContext()->setGeneralError($e->getMessage());
        }

        $this->getParserContext()
            ->addForm($form)
        ;

        return $this->configureAction($id);
    }
1235393
public function exportById($id): string
    {
        $fieldGroup = Craft::$app->fields->getGroupById((int) $id);

        return $this->export($fieldGroup);
    }
107816
function export_class_instance($exportclass = null) {
        if (!is_null($exportclass)) {
            $this->started_output = true;
            $this->exportclass = $exportclass;
            $this->exportclass->table = $this;
        } else if (is_null($this->exportclass) && !empty($this->download)) {
            $this->exportclass = new table_dataformat_export_format($this, $this->download);
            if (!$this->exportclass->document_started()) {
                $this->exportclass->start_document($this->filename, $this->sheettitle);
            }
        }
        return $this->exportclass;
    }
1107987
public static function get_submission($submissionid) {
        global $USER, $DB, $PAGE;

        $params = self::validate_parameters(self::get_submission_parameters(), array('submissionid' => $submissionid));
        $warnings = array();

        // Get and validate the submission and workshop.
        $submission = $DB->get_record('workshop_submissions', array('id' => $params['submissionid']), '*', MUST_EXIST);
        list($workshop, $course, $cm, $context) = self::validate_workshop($submission->workshopid);

        self::validate_submission($submission, $workshop);

        $submission = self::prepare_submission_for_external($submission, $workshop);

        $related = array('context' => $context);
        $exporter = new submission_exporter($submission, $related);
        return array(
            'submission' => $exporter->export($PAGE->get_renderer('core')),
            'warnings' => $warnings
        );
    }
907756
public static function get_export_xml($roleid) {
        global $DB;

        $role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST);

        $dom = new DOMDocument('1.0', 'UTF-8');
        $top = $dom->createElement('role');
        $dom->appendChild($top);

        $top->appendChild($dom->createElement('shortname', $role->shortname));
        $top->appendChild($dom->createElement('name', htmlspecialchars($role->name, ENT_COMPAT | ENT_HTML401, 'UTF-8')));
        $top->appendChild($dom->createElement('description', htmlspecialchars($role->description, ENT_COMPAT | ENT_HTML401,
                'UTF-8')));
        $top->appendChild($dom->createElement('archetype', $role->archetype));

        $contextlevels = $dom->createElement('contextlevels');
        $top->appendChild($contextlevels);
        foreach (get_role_contextlevels($roleid) as $level) {
            $name = context_helper::get_class_for_level($level);
            $name = preg_replace('/^context_/', '', $name);
            $contextlevels->appendChild($dom->createElement('level', $name));
        }

        foreach (array('assign', 'override', 'switch', 'view') as $type) {
            $allows = $dom->createElement('allow'.$type);
            $top->appendChild($allows);
            $records = $DB->get_records('role_allow_'.$type, array('roleid'=>$roleid), "allow$type ASC");
            foreach ($records as $record) {
                if (!$ar = $DB->get_record('role', array('id'=>$record->{'allow'.$type}))) {
                    continue;
                }
                $allows->appendChild($dom->createElement('shortname', $ar->shortname));
            }
        }

        $permissions = $dom->createElement('permissions');
        $top->appendChild($permissions);

        $capabilities = $DB->get_records_sql_menu(
            "SELECT capability, permission
               FROM {role_capabilities}
              WHERE contextid = :syscontext AND roleid = :roleid
           ORDER BY capability ASC",
            array('syscontext'=>context_system::instance()->id, 'roleid'=>$roleid));

        $allcapabilities = $DB->get_records('capabilities', array(), 'name ASC');
        foreach ($allcapabilities as $cap) {
            if (!isset($capabilities[$cap->name])) {
                $permissions->appendChild($dom->createElement('inherit', $cap->name));
            }
        }

        foreach ($capabilities as $capability => $permission) {
            if ($permission == CAP_ALLOW) {
                $permissions->appendChild($dom->createElement('allow', $capability));
            }
        }
        foreach ($capabilities as $capability => $permission) {
            if ($permission == CAP_PREVENT) {
                $permissions->appendChild($dom->createElement('prevent', $capability));
            }
        }
        foreach ($capabilities as $capability => $permission) {
            if ($permission == CAP_PROHIBIT) {
                $permissions->appendChild($dom->createElement('prohibit', $capability));
            }
        }

        return $dom->saveXML();
    }
1014448
public function getForWithId(string $paramName, string $errorId)
    {
        if (isset($this->errors[$paramName]) && isset($this->errors[$paramName][$errorId])) {
            return $this->errors[$paramName][$errorId];
        }

        return null;
    }
418825
public function getDataTable($export = 'JqGrid', $source = null)
	{
		if(is_null($source))
		{
			$source = new Lib_Grid_Source_Model($this);
		}

		$config = $this->getGridConfig();

		$id = Lib_Grid::buildId(
			  $export,
			  $source,
			  isset($config->bvbParams->id_prefix) ? $config->bvbParams->id_prefix : null
		);

		$requestParams = Zend_Controller_Front::getInstance()->getRequest()->getParams();
		if(isset($requestParams['q']) && $requestParams['q'] == $id && isset($requestParams['_exportTo']))
		{
			$requestParams['_exportTo'.$id] = $requestParams['_exportTo'];
		}

		/**
		 * @var Bvb_Grid $grid
		 */
		$grid = Bvb_Grid::factory($export, $config, $id, array(), $requestParams);
		if($export == 'JqGrid')
		{
			Lib_Grid::prepareDeploy($grid, $config, $source);
		}
		elseif($export == 'Pdf')
		{
			$config->export->pdf   = 'Pdf';
			$config->disableExport = false;
			Lib_Grid::prepareDeploy($grid, $config, $source);
		}

		return $grid;
	}
598363
public function getExportDoc($shipmentNumbers) {
		switch($this->getMayor()) {
			case 1:
				$data = $this->getExportDocClass_v1($shipmentNumbers);
				break;
			case 2:
			default:
				$data = $this->getExportDocClass_v2($shipmentNumbers);
		}

		try {
			$response = $this->sendGetExportDocRequest($data);
		} catch(Exception $e) {
			$this->addError($e->getMessage());

			return false;
		}

		if(is_soap_fault($response)) {
			$this->addError($response->faultstring);

			return false;
		} else
			return new Response($this->getVersion(), $response);
	}
585112
protected function getInvoiceForEvent(int $iInvoiceId): Resource
    {
        $oInvoice = $this->getById($iInvoiceId, ['expand' => ['customer', 'items']]);
        if (empty($oInvoice)) {
            throw new ModelException('Invalid invoice ID');
        }
        return $oInvoice;
    }
412297
public function getId($iId = null)
    {
        $oInput = Factory::service('Input');
        $iId    = (int) $iId ?: (int) $oInput->get('id');

        if (empty($iId)) {
            throw new ApiException('Invalid Invoice ID', 404);
        }

        $oInvoiceModel = Factory::model('Invoice', 'nails/module-invoice');
        $oInvoice      = $oInvoiceModel->getById($iId, ['expand' => ['customer']]);

        if (empty($oInvoice)) {
            throw new ApiException('Invalid Invoice ID', 404);
        }

        return Factory::factory('ApiResponse', 'nails/module-api')
                      ->setData($this->formatInvoice($oInvoice));
    }
1156526
public function getExport($alias)
    {
        if (!array_key_exists($alias, $this->exports)) {
            throw new \RuntimeException("The export with alias $alias is not known.");
        }
        
        return $this->exports[$alias];
    }