<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
static protected $_template;
/**
- * class constructor
+ * Class constructor
*/
- function __construct() {
- if ( !isset( self::$_template ) ) {
+ public function __construct() {
+ if (!isset(self::$_template)) {
self::$_template = CRM_Core_Smarty::singleton();
}
}
// Override to assemble the appropriate subset of financial data for the specific export format
- function export($exportParams) {
+ /**
+ * @param array $exportParams
+ *
+ * @return mixed
+ */
+ public function export($exportParams) {
$this->_exportParams = $exportParams;
return $exportParams;
}
- function output($fileName = NULL) {
+ /**
+ * @param null $fileName
+ */
+ public function output($fileName = NULL) {
switch ($this->getFileExtension()) {
case 'csv':
self::createActivityExport($this->_batchIds, $fileName);
- break;
+ break;
case 'iif':
$tplFile = $this->getHookedTemplateFileName();
$out = self::getTemplate()->fetch($tplFile);
$fileName = $this->putFile($out);
self::createActivityExport($this->_batchIds, $fileName);
- break;
+ break;
}
}
- function getMimeType() {
+ /**
+ * @return string
+ */
+ public function getMimeType() {
return 'text/plain';
}
- function getFileExtension() {
+ /**
+ * @return string
+ */
+ public function getFileExtension() {
return 'txt';
}
// Override this if appropriate
- function getTemplateFileName() {
- return null;
+ /**
+ * @return null
+ */
+ public function getTemplateFileName() {
+ return NULL;
}
- static function &getTemplate() {
+ /**
+ * @return object
+ */
+ public static function &getTemplate() {
return self::$_template;
}
- function assign($var, $value = NULL) {
+ /**
+ * @param $var
+ * @param null $value
+ */
+ public function assign($var, $value = NULL) {
self::$_template->assign($var, $value);
}
* 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.
*/
- static function format($s, $type = 'string') {
+ /**
+ * @param $s
+ * @param string $type
+ *
+ * @return null
+ */
+ public static function format($s, $type = 'string') {
if (!empty($s)) {
return $s;
}
}
}
- function initiateDownload() {
+ public function initiateDownload() {
$config = CRM_Core_Config::singleton();
//zip files if more than one.
- if (count($this->_downloadFile)>1) {
+ if (count($this->_downloadFile) > 1) {
$zip = $config->customFileUploadDir . 'Financial_Transactions_' . date('YmdHis') . '.zip';
$result = $this->createZip($this->_downloadFile, $zip, TRUE);
if ($result) {
}
}
- static function createActivityExport($batchIds, $fileName) {
+ /**
+ * @param $batchIds
+ * @param string $fileName
+ *
+ * @throws CRM_Core_Exception
+ */
+ public static function createActivityExport($batchIds, $fileName) {
$session = CRM_Core_Session::singleton();
$values = array();
$params = array('id' => $batchIds);
$paymentInstrument = array_flip(CRM_Contribute_PseudoConstant::paymentInstrument('label'));
$values['payment_instrument_id'] = array_search($values['payment_instrument_id'], $paymentInstrument);
}
- $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>';
+ $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 (!empty($values['total'])) {
- $subject .= ts('Total') . '['. CRM_Utils_Money::format($values['total']) .'],';
+ $subject .= ts('Total') . '[' . CRM_Utils_Money::format($values['total']) . '],';
}
if (!empty($values['item_count'])) {
- $subject .= ' ' . ts('Count') . '['. $values['item_count'] .'],';
+ $subject .= ' ' . ts('Count') . '[' . $values['item_count'] . '],';
}
//create activity.
- $subject .= ' ' . ts('Batch') . '['. $values['title'] .']';
+ $subject .= ' ' . ts('Batch') . '[' . $values['title'] . ']';
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, FALSE, FALSE, 'name');
$activityParams = array(
'activity_type_id' => array_search('Export Accounting Batch', $activityTypes),
'source_record_id' => $values['id'],
'target_contact_id' => $session->get('userID'),
'details' => $details,
- 'attachFile_1' => array (
+ 'attachFile_1' => array(
'uri' => $fileName,
'type' => 'text/csv',
'location' => $fileName,
CRM_Activity_BAO_Activity::create($activityParams);
}
- function createZip($files = array(), $destination = NULL, $overwrite = FALSE) {
+ /**
+ * @param array $files
+ * @param null $destination
+ * @param bool $overwrite
+ *
+ * @return bool
+ */
+ public 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) {
return FALSE;
}
if (count($validFiles)) {
$zip = new ZipArchive();
- if ($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== TRUE) {
+ if ($zip->open($destination, $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== TRUE) {
return FALSE;
}
foreach ($validFiles as $file) {
return file_exists($destination);
}
else {
- return FALSE;
- }
+ return FALSE;
+ }
}
}