CRM add remaining missing comment blocks (autogenerated)
[civicrm-core.git] / CRM / Financial / BAO / ExportFormat.php
index 033e8c3e5ea116fb58f391a5ccc802f30853e802..d6105f9dde414f1c27c76cc996afdd069591044a 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                             |
+ | CiviCRM version 4.5                                             |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -61,11 +61,19 @@ class CRM_Financial_BAO_ExportFormat {
   }
 
   // Override to assemble the appropriate subset of financial data for the specific export format
+  /**
+   * @param $exportParams
+   *
+   * @return mixed
+   */
   function export($exportParams) {
     $this->_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 = '<p>' . ts('Record: ') . $values['title'] . '</p><p>' . ts('Description: ') . '</p><p>' . ts('Created By: ') . $createdBy . '</p><p>' . ts('Created Date: ') . $values['created_date'] . '</p><p>' . ts('Last Modified By: ') . $modifiedBy . '</p><p>' . ts('Payment Instrument: ') . $values['payment_instrument_id'] . '</p>';
     $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
+}