_actions)) { // No Access return $this; } $tool = $this->getPdfExportTool(); $tribeIdParam = []; if (isset($query['tribeId']) && $query['tribeId']) { $tribeIdParam['tribeId'] = $query['tribeId']; $tool->setTargetDir($tool->getTargetDir() . '-' . $query['tribeId']); } $file = $tool->getExportFile(); if (($fileExists = file_exists($file))) { $links[$action] = [ 'title' => 'Download .' . pathinfo($file, PATHINFO_EXTENSION), 'options' => ['info' => 'created on ' . date('m/d/y g:i A', filemtime($file))], 'url' => $this->url(array_merge(['action' => 'downloadPdfExport', 'file' => basename($file)], $tribeIdParam)), ]; } if ($tool->isInProcess() || $this->isInProcess()) { $this->setInProcess(false); $this->_addItem([ 'refreshUrl' => $this->_getBackUrl(), 'tpl' => 'PdfExport/in-process.tpl', ]); } else { $links[$action] = [ 'title' => $fileExists ? 'Re-export to .pdf' : 'Export to .pdf', 'url' => $this->url(array_merge(['action' => 'exportToPdf'], $query)), ]; } return $this; } protected function isInProcess() { /** @noinspection PhpUndefinedFieldInspection */ return !empty($this->getSession()->inProcess); } protected function setInProcess($flag = true) { if (!$flag) { /** @noinspection PhpUndefinedFieldInspection */ unset($this->getSession()->inProcess); } else { /** @noinspection PhpUndefinedFieldInspection */ $this->getSession()->inProcess = $flag; } return $this; } protected function getSession() { return new Qs_Session_Namespace(__CLASS__); } protected function _doExportToPdf() { if (!($url = $this->getConfig('pdfExportJobUrl'))) { throw new Exception('pdfExportJobUrl is not defined'); } $query = Qs_Request::getGet(); unset($query['action']); if ($query) { $url .= '?' . http_build_query($query); } Qs_Job::run($url); $this->setInProcess(); $this->_doBack(); return $this; } protected function _doDownloadPdfExport() { try { $this->getPdfExportTool()->download(Qs_Request::getGetValue('file'), $this->getConfig('pdfExportDownloadFileName')); } catch (Exception $e) { $this->_setBackError($e->getMessage()); $this->_doBack(); } return $this; } }