Beispiel #1
0
 /**
  * Function to export donor list to CSV.
  *
  * @return  void
  *
  * @since   1.0.0
  */
 public function export_donors()
 {
     $app = JFactory::getApplication();
     $params = JComponentHelper::getParams('com_cmdonation');
     $campaignId = $app->input->get('campaign', 0, 'integer');
     // Make sure campaign exists.
     $campaign = JModelAdmin::getInstance('Campaign', 'CMDonationModel')->getItem($campaignId);
     if (empty($campaign)) {
         $app->enqueueMessage(JText::_('COM_CMDONATION_CAMPAIGN_NOT_FOUND'), 'error');
         $app->redirect(JRoute::_('index.php?option=com_cmdonation'));
     }
     // Get campaign's donations.
     $donations = JModelAdmin::getInstance('Donations', 'CMDonationModel')->getDonationsForCSV($campaignId);
     $data = array(array(JText::_('COM_CMDONATION_DONATION_FIRST_NAME_LABEL'), JText::_('COM_CMDONATION_DONATION_LAST_NAME_LABEL'), JText::_('COM_CMDONATION_DONATION_EMAIL_LABEL'), JText::_('COM_CMDONATION_DONATION_COUNTRY_LABEL'), JText::_('COM_CMDONATION_DONATION_AMOUNT_LABEL'), JText::_('COM_CMDONATION_DONATION_COMPLETED_LABEL'), JText::_('COM_CMDONATION_DONATION_PAYMENT_METHOD_LABEL')));
     if (!empty($donations)) {
         include JPATH_ROOT . '/administrator/components/com_cmdonation/helpers/countries.php';
         $currencySign = $params->get('currency_sign');
         $currencySignPosition = $params->get('currency_sign_position');
         $decimals = $params->get('decimals');
         $decimalPoint = $params->get('decimal_point');
         $thousandSeparator = $params->get('thousand_separator');
         foreach ($donations as $donation) {
             if (array_key_exists($donation->country_code, $countryList)) {
                 $countryName = JText::_($countryList[$donation->country_code]);
             } else {
                 $countryName = '';
             }
             $amount = CMDonationHelper::showDonationAmount($donation->amount, $currencySign, $currencySignPosition, $decimals, $decimalPoint, $thousandSeparator, false);
             $paymentMethod = CMDonationHelper::displayPaymentMethodName($donation->payment_method_id);
             $data[] = array($donation->first_name, $donation->last_name, $donation->email, $countryName, $amount, $donation->completed, $paymentMethod);
         }
     }
     $delimiter = $params->get('csv_delimiter_character', ',');
     $enclosure = $params->get('csv_enclosure_character', 'double');
     if ($enclosure == 'double') {
         $enclosure = '"';
     } else {
         $enclosure = "'";
     }
     $filename = JApplication::stringURLSafe($campaign->name);
     if ($filename == '') {
         $filename = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     $filename .= '.csv';
     header("Content-type: text/csv");
     header("Content-Disposition: attachment; filename={$filename}");
     header("Pragma: no-cache");
     header("Expires: 0");
     $output = fopen("php://output", "w");
     foreach ($data as $row) {
         fputcsv($output, $row, $delimiter, $enclosure);
     }
     fclose($output);
     JFactory::getApplication()->close();
 }
 /**
  * Search for CM Donation's tags and replace them with actual content.
  *
  * @param   string   $context  The context of the content being passed to the plugin.
  * @param   mixed    &$row     An object with a "text" property
  * @param   mixed    $params   Additional parameters. See {@see PlgContentContent()}.
  * @param   integer  $page     Optional page number. Unused. Defaults to zero.
  *
  * @return  boolean	True on success.
  *
  * @since   1.0.0
  */
 public function onContentPrepare($context, &$row, $params, $page = 0)
 {
     require_once JPATH_ROOT . '/administrator/components/com_cmdonation/helpers/cmdonation.php';
     $lang = JFactory::getLanguage();
     $lang->load('com_cmdonation', JPATH_SITE, null, false, true);
     $lang->load('com_cmdonation', JPATH_SITE . '/components/com_cmdonation/', null, false, true);
     $enableDonations = $this->params->get('enable_donations', '1');
     $enableAmount = $this->params->get('enable_amount', '1');
     $enableDonationForm = $this->params->get('enable_donation_form', '1');
     $enableLatestDonations = $this->params->get('enable_latest_donations', '1');
     $enableTopDonors = $this->params->get('enable_top_donors', '1');
     $enableTopCountries = $this->params->get('enable_top_countries', '1');
     // Should I run?
     if (!$enableDonations && !$enableAmount && !$enableDonationForm && !$enableLatestDonations && !$enableTopDonors && !$enableTopCountries) {
         return;
     } else {
         // Load CSS.
         JFactory::getDocument()->addStyleSheet('components/com_cmdonation/assets/css/pure-min.css');
     }
     // Number of donations.
     if ($enableDonations) {
         $pattern = '/{donations:([0-9]*)}/';
         preg_match_all($pattern, $row->text, $matches, PREG_SET_ORDER);
         if (!empty($matches)) {
             foreach ($matches as $match) {
                 $campaignId = $match[1];
                 $existence = CMDonationHelper::doesCampaignExist($campaignId);
                 if (!$existence) {
                     $replace = '';
                 } else {
                     $replace = $this->countDonations($campaignId);
                 }
                 $row->text = preg_replace($pattern, $replace, $row->text, 1);
             }
         }
     }
     // Total amount donated.
     if ($enableAmount) {
         $pattern = '/{amount:([0-9]*)}/';
         preg_match_all($pattern, $row->text, $matches, PREG_SET_ORDER);
         if (!empty($matches)) {
             foreach ($matches as $match) {
                 $campaignId = $match[1];
                 $existence = CMDonationHelper::doesCampaignExist($campaignId);
                 if (!$existence) {
                     $replace = '';
                 } else {
                     // Component settings.
                     $params = JComponentHelper::getParams('com_cmdonation');
                     $currencySign = $params->get('currency_sign');
                     $currencySignPosition = $params->get('currency_sign_position');
                     $decimals = $params->get('decimals');
                     $decimalPoint = $params->get('decimal_point');
                     $thousandSeparator = $params->get('thousand_separator');
                     $replace = $this->countAmount($campaignId);
                     $replace = CMDonationHelper::showDonationAmount($replace, $currencySign, $currencySignPosition, $decimals, $decimalPoint, $thousandSeparator);
                 }
                 $row->text = preg_replace($pattern, $replace, $row->text, 1);
             }
         }
     }
     // Donation form.
     if ($enableDonationForm) {
         $pattern = '/{donation-form:([0-9]*)}/';
         preg_match_all($pattern, $row->text, $matches, PREG_SET_ORDER);
         if (!empty($matches)) {
             foreach ($matches as $match) {
                 $campaignId = $match[1];
                 $existence = CMDonationHelper::doesCampaignExist($campaignId);
                 if (!$existence) {
                     $replace = '';
                 } else {
                     $replace = $this->buildDonationForm($campaignId);
                 }
                 $row->text = preg_replace($pattern, $replace, $row->text, 1);
             }
         }
     }
     // Latest donations.
     if ($enableLatestDonations) {
         $pattern = '/{latest-donations:([0-9]*):([0-9]*)}/';
         preg_match_all($pattern, $row->text, $matches, PREG_SET_ORDER);
         if (!empty($matches)) {
             foreach ($matches as $match) {
                 $campaignId = $match[1];
                 $existence = CMDonationHelper::doesCampaignExist($campaignId);
                 if (!$existence) {
                     $replace = '';
                 } else {
                     $limit = $match[2];
                     $replace = $this->buildLatestDonationsTable($campaignId, $limit);
                 }
                 $row->text = preg_replace($pattern, $replace, $row->text, 1);
             }
         }
     }
     // Top donors.
     if ($enableTopDonors) {
         $pattern = '/{top-donors:([0-9]*):([0-9]*)}/';
         preg_match_all($pattern, $row->text, $matches, PREG_SET_ORDER);
         if (!empty($matches)) {
             foreach ($matches as $match) {
                 $campaignId = $match[1];
                 $existence = CMDonationHelper::doesCampaignExist($campaignId);
                 if (!$existence) {
                     $replace = '';
                 } else {
                     $limit = $match[2];
                     $replace = $this->buildTopDonorsTable($campaignId, $limit);
                 }
                 $row->text = preg_replace($pattern, $replace, $row->text, 1);
             }
         }
     }
     // Top countries.
     if ($enableTopCountries) {
         $pattern = '/{top-countries:([0-9]*):([0-9]*)}/';
         preg_match_all($pattern, $row->text, $matches, PREG_SET_ORDER);
         if (!empty($matches)) {
             foreach ($matches as $match) {
                 $campaignId = $match[1];
                 $existence = CMDonationHelper::doesCampaignExist($campaignId);
                 if (!$existence) {
                     $replace = '';
                 } else {
                     $limit = $match[2];
                     $replace = $this->buildTopCountryTable($campaignId, $limit);
                 }
                 $row->text = preg_replace($pattern, $replace, $row->text, 1);
             }
         }
     }
 }
				<td class="pure-text-center"><?php 
            echo CMDonationHelper::showCountryName($donor->country_code);
            ?>
				<td class="pure-text-center"><?php 
            echo CMDonationHelper::showCountryFlag($donor->country_code);
            ?>
				<?php 
        }
        ?>
				<td class="pure-text-center"><?php 
        echo $donor->donation_quantity;
        ?>
</td>
				<td class="pure-text-center">
					<?php 
        echo CMDonationHelper::showDonationAmount($donor->amount, $currencySign, $currencySignPosition, $decimals, $decimalPoint, $thousandSeparator);
        ?>
				</td>
			</tr>
			<?php 
    }
    ?>
		</tbody>
	</table>
<?php 
} else {
    ?>
	<div class="text-error"><?php 
    echo JText::_('COM_CMDONATION_NO_DONATIONS');
    ?>
</div>