X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FFinancial%2FBAO%2FExportFormat.php;h=d6105f9dde414f1c27c76cc996afdd069591044a;hb=e0ef6999bd13664d0f36fe9adb861b133494144d;hp=033e8c3e5ea116fb58f391a5ccc802f30853e802;hpb=dae00956493ff85036f5f6acc038f0a043eccbec;p=civicrm-core.git diff --git a/CRM/Financial/BAO/ExportFormat.php b/CRM/Financial/BAO/ExportFormat.php index 033e8c3e5e..d6105f9dde 100644 --- a/CRM/Financial/BAO/ExportFormat.php +++ b/CRM/Financial/BAO/ExportFormat.php @@ -1,9 +1,9 @@ _exportParams = $exportParams; return $exportParams; } + /** + * @param null $fileName + */ function output($fileName = NULL) { switch ($this->getFileExtension()) { case 'csv': @@ -73,31 +81,47 @@ class CRM_Financial_BAO_ExportFormat { break; case 'iif': - $tplFile = $this->getTemplateFileName(); - $out = self::getTemplate()->fetch( $tplFile ); + $tplFile = $this->getHookedTemplateFileName(); + $out = self::getTemplate()->fetch($tplFile); $fileName = $this->putFile($out); self::createActivityExport($this->_batchIds, $fileName); break; } } + /** + * @return string + */ function getMimeType() { return 'text/plain'; } + /** + * @return string + */ function getFileExtension() { return 'txt'; } // Override this if appropriate + /** + * @return null + */ function getTemplateFileName() { return null; } + /** + * @return object + */ static function &getTemplate() { return self::$_template; } + /** + * @param $var + * @param null $value + */ function assign($var, $value = NULL) { self::$_template->assign($var, $value); } @@ -108,6 +132,12 @@ class CRM_Financial_BAO_ExportFormat { * Depending on the output format might want to override this, e.g. for IIF tabs need to be escaped etc, * but for CSV it doesn't make sense because php has built in csv output functions. */ + /** + * @param $s + * @param string $type + * + * @return null + */ static function format($s, $type = 'string') { if (!empty($s)) { return $s; @@ -121,30 +151,36 @@ class CRM_Financial_BAO_ExportFormat { $config = CRM_Core_Config::singleton(); //zip files if more than one. if (count($this->_downloadFile)>1) { - $zip = $config->customFileUploadDir.'Financial_Transactions_'.date('YmdHis').'.zip'; + $zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip'; $result = $this->createZip($this->_downloadFile, $zip, TRUE); if ($result) { header('Content-Type: application/zip'); - header('Content-Disposition: attachment; filename='.CRM_Utils_File::cleanFileName(basename($zip))); + header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($zip))); header('Content-Length: ' . filesize($zip)); ob_clean(); flush(); - readfile($config->customFileUploadDir.CRM_Utils_File::cleanFileName(basename($zip))); + readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($zip))); unlink($zip); //delete the zip to avoid clutter. CRM_Utils_System::civiExit(); } } else { - header('Content-Type: '.mime_content_type($this->_downloadFile[0])); - header('Content-Disposition: attachment; filename='.CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); + header('Content-Type: text/plain'); + header('Content-Disposition: attachment; filename=' . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); header('Content-Length: ' . filesize($this->_downloadFile[0])); ob_clean(); flush(); - readfile($config->customFileUploadDir.CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); + readfile($config->customFileUploadDir . CRM_Utils_File::cleanFileName(basename($this->_downloadFile[0]))); CRM_Utils_System::civiExit(); } } + /** + * @param $batchIds + * @param $fileName + * + * @throws CRM_Core_Exception + */ static function createActivityExport($batchIds, $fileName) { $session = CRM_Core_Session::singleton(); $values = array(); @@ -160,10 +196,10 @@ class CRM_Financial_BAO_ExportFormat { } $details = '

' . ts('Record: ') . $values['title'] . '

' . ts('Description: ') . '

' . ts('Created By: ') . $createdBy . '

' . ts('Created Date: ') . $values['created_date'] . '

' . ts('Last Modified By: ') . $modifiedBy . '

' . ts('Payment Instrument: ') . $values['payment_instrument_id'] . '

'; $subject = ''; - if (CRM_Utils_Array::value('total', $values)) { + if (!empty($values['total'])) { $subject .= ts('Total') . '['. CRM_Utils_Money::format($values['total']) .'],'; } - if (CRM_Utils_Array::value('item_count', $values)) { + if (!empty($values['item_count'])) { $subject .= ' ' . ts('Count') . '['. $values['item_count'] .'],'; } @@ -190,6 +226,13 @@ class CRM_Financial_BAO_ExportFormat { CRM_Activity_BAO_Activity::create($activityParams); } + /** + * @param array $files + * @param null $destination + * @param bool $overwrite + * + * @return bool + */ function createZip($files = array(), $destination = NULL, $overwrite = FALSE) { //if the zip file already exists and overwrite is false, return false if (file_exists($destination) && !$overwrite) { @@ -219,4 +262,4 @@ class CRM_Financial_BAO_ExportFormat { return FALSE; } } -} \ No newline at end of file +}