Ejemplo n.º 1
0
 /**
  * Send emails to the administrator, project owner and the user who have made a donation.
  *
  * @param \stdClass   $project
  * @param \stdClass   $transaction
  * @param Registry    $params
  * @param \stdClass   $reward
  */
 protected function sendMails(&$project, &$transaction, &$params, &$reward)
 {
     $app = \JFactory::getApplication();
     /** @var $app \JApplicationSite */
     // Get website
     $uri = \JUri::getInstance();
     $website = $uri->toString(array('scheme', 'host'));
     $emailMode = $this->params->get('email_mode', 'plain');
     $componentParams = \JComponentHelper::getParams('com_crowdfunding');
     $currency = Crowdfunding\Currency::getInstance(\JFactory::getDbo(), $componentParams->get('project_currency'));
     $amount = new Crowdfunding\Amount($componentParams);
     $amount->setCurrency($currency);
     // Prepare data for parsing.
     $data = array('site_name' => $app->get('sitename'), 'site_url' => \JUri::root(), 'item_title' => $project->title, 'item_url' => $website . \JRoute::_(\CrowdfundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)), 'amount' => $amount->setValue($transaction->txn_amount)->formatCurrency(), 'transaction_id' => $transaction->txn_id, 'reward_title' => '', 'delivery_date' => '', 'payer_name' => '', 'payer_email' => '');
     // Set reward data.
     if (is_object($reward)) {
         $data['reward_title'] = $reward->title;
         if ($reward->delivery !== '0000-00-00') {
             $date = new \JDate($reward->delivery);
             $data['delivery_date'] = $date->format('d F Y');
         }
     }
     // Prepare data about payer if he is NOT anonymous ( is registered user with profile ).
     if ((int) $transaction->investor_id > 0) {
         $investor = \JFactory::getUser($transaction->investor_id);
         $data['payer_email'] = $investor->get('email');
         $data['payer_name'] = $investor->get('name');
     }
     // Send mail to the administrator
     $emailId = (int) $this->params->get('admin_mail_id', 0);
     if ($emailId > 0) {
         $email = new EmailTemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get('fromname'));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get('mailfrom'));
         }
         // Prepare recipient data.
         $componentParams = \JComponentHelper::getParams('com_crowdfunding');
         /** @var  $componentParams Registry */
         $recipientId = (int) $componentParams->get('administrator_id', 0);
         if ($recipientId > 0) {
             $recipient = \JFactory::getUser($recipientId);
             $recipientName = $recipient->get('name');
             $recipientMail = $recipient->get('email');
         } else {
             $recipientName = $app->get('fromname');
             $recipientMail = $app->get('mailfrom');
         }
         // Prepare data for parsing
         $data['sender_name'] = $email->getSenderName();
         $data['sender_email'] = $email->getSenderEmail();
         $data['recipient_name'] = $recipientName;
         $data['recipient_email'] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp('html', $emailMode) === 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . '_ERROR_MAIL_SENDING_ADMIN'), $this->debugType, $mailer->ErrorInfo);
         }
     }
     // Send mail to project owner.
     $emailId = (int) $this->params->get('creator_mail_id', 0);
     if ($emailId > 0) {
         $email = new EmailTemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get('fromname'));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get('mailfrom'));
         }
         $user = \JFactory::getUser($transaction->receiver_id);
         $recipientName = $user->get('name');
         $recipientMail = $user->get('email');
         // Prepare data for parsing
         $data['sender_name'] = $email->getSenderName();
         $data['sender_email'] = $email->getSenderEmail();
         $data['recipient_name'] = $recipientName;
         $data['recipient_email'] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp('html', $emailMode) === 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . '_ERROR_MAIL_SENDING_PROJECT_OWNER'), $this->debugType, $mailer->ErrorInfo);
         }
     }
     // Send mail to backer.
     $emailId = (int) $this->params->get('user_mail_id', 0);
     if ($emailId > 0 and (int) $transaction->investor_id > 0) {
         $email = new EmailTemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get('fromname'));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get('mailfrom'));
         }
         $user = \JFactory::getUser($transaction->investor_id);
         $recipientName = $user->get('name');
         $recipientMail = $user->get('email');
         // Prepare data for parsing
         $data['sender_name'] = $email->getSenderName();
         $data['sender_email'] = $email->getSenderEmail();
         $data['recipient_name'] = $recipientName;
         $data['recipient_email'] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp('html', $emailMode) === 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . '_ERROR_MAIL_SENDING_PROJECT_OWNER'), $this->debugType, $mailer->ErrorInfo);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Send emails to the administrator, project owner and the user who have made a donation.
  *
  * @param object                   $project
  * @param object                   $transaction
  * @param Registry $params
  */
 protected function sendMails($project, $transaction, $params)
 {
     $app = \JFactory::getApplication();
     /** @var $app \JApplicationSite */
     // Get website
     $uri = \JUri::getInstance();
     $website = $uri->toString(array("scheme", "host"));
     $emailMode = $this->params->get("email_mode", "plain");
     $componentParams = \JComponentHelper::getParams("com_crowdfunding");
     $currency = Crowdfunding\Currency::getInstance(\JFactory::getDbo(), $componentParams->get("project_currency"));
     $amount = new Crowdfunding\Amount($componentParams);
     $amount->setCurrency($currency);
     // Prepare data for parsing.
     $data = array("site_name" => $app->get("sitename"), "site_url" => \JUri::root(), "item_title" => $project->title, "item_url" => $website . \JRoute::_(\CrowdfundingHelperRoute::getDetailsRoute($project->slug, $project->catslug)), "amount" => $amount->setValue($transaction->txn_amount)->formatCurrency(), "transaction_id" => $transaction->txn_id);
     // Prepare data about payer if he is NOT anonymous ( is registered user with profile ).
     if (!empty($transaction->investor_id)) {
         $investor = \JFactory::getUser($transaction->investor_id);
         $data["payer_email"] = $investor->get("email");
         $data["payer_name"] = $investor->get("name");
     }
     // Send mail to the administrator
     $emailId = $this->params->get("admin_mail_id", 0);
     if (!empty($emailId)) {
         $email = new EmailTemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get("fromname"));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get("mailfrom"));
         }
         // Prepare recipient data.
         $componentParams = \JComponentHelper::getParams("com_crowdfunding");
         /** @var  $componentParams Registry */
         $recipientId = $componentParams->get("administrator_id");
         if (!empty($recipientId)) {
             $recipient = \JFactory::getUser($recipientId);
             $recipientName = $recipient->get("name");
             $recipientMail = $recipient->get("email");
         } else {
             $recipientName = $app->get("fromname");
             $recipientMail = $app->get("mailfrom");
         }
         // Prepare data for parsing
         $data["sender_name"] = $email->getSenderName();
         $data["sender_email"] = $email->getSenderEmail();
         $data["recipient_name"] = $recipientName;
         $data["recipient_email"] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp("html", $emailMode) == 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_ADMIN"), $this->debugType, $mailer->ErrorInfo);
         }
     }
     // Send mail to project owner.
     $emailId = $this->params->get("creator_mail_id", 0);
     if (!empty($emailId)) {
         $email = new EmailTemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get("fromname"));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get("mailfrom"));
         }
         $user = \JFactory::getUser($transaction->receiver_id);
         $recipientName = $user->get("name");
         $recipientMail = $user->get("email");
         // Prepare data for parsing
         $data["sender_name"] = $email->getSenderName();
         $data["sender_email"] = $email->getSenderEmail();
         $data["recipient_name"] = $recipientName;
         $data["recipient_email"] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp("html", $emailMode) == 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_PROJECT_OWNER"), $this->debugType, $mailer->ErrorInfo);
         }
     }
     // Send mail to backer.
     $emailId = $this->params->get("user_mail_id", 0);
     if (!empty($emailId) and !empty($transaction->investor_id)) {
         $email = new EmailTemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($app->get("fromname"));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($app->get("mailfrom"));
         }
         $user = \JFactory::getUser($transaction->investor_id);
         $recipientName = $user->get("name");
         $recipientMail = $user->get("email");
         // Prepare data for parsing
         $data["sender_name"] = $email->getSenderName();
         $data["sender_email"] = $email->getSenderEmail();
         $data["recipient_name"] = $recipientName;
         $data["recipient_email"] = $recipientMail;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp("html", $emailMode) == 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . "_ERROR_MAIL_SENDING_PROJECT_OWNER"), $this->debugType, $mailer->ErrorInfo);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Send emails to the administrator, project owner and the user who have made a donation.
  *
  * @param \stdClass   $paymentResult
  * @param Registry    $params
  *
  * @throws \InvalidArgumentException
  * @return void
  */
 protected function sendMails($paymentResult, $params)
 {
     if (!\JComponentHelper::isInstalled('com_emailtemplates')) {
         \JLog::add(\JText::_('LIB_CROWDFUNDING_EMAIL_TEMPLATES_INSTALLATION'), \JLog::WARNING, 'com_crowdfunding');
         return;
     }
     $transaction = $paymentResult->transaction;
     /** @var Crowdfunding\Transaction\Transaction $transaction */
     $project = $paymentResult->project;
     /** @var Crowdfunding\Project $project */
     $reward = $paymentResult->reward;
     /** @var Crowdfunding\Reward $reward */
     // Get website
     $uri = \JUri::getInstance();
     $website = $uri->toString(array('scheme', 'host'));
     $emailMode = $this->params->get('email_mode', 'plain');
     $moneyHash = Prism\Utilities\StringHelper::generateMd5Hash(Crowdfunding\Constants::CONTAINER_FORMATTER_MONEY, $params->get('project_currency'));
     $money = $this->container->get($moneyHash);
     /** @var Prism\Money\Money $money */
     // Prepare data for parsing.
     $data = array('site_name' => $this->app->get('sitename'), 'site_url' => \JUri::root(), 'item_title' => $project->getTitle(), 'item_url' => $website . \JRoute::_(\CrowdfundingHelperRoute::getDetailsRoute($project->getSlug(), $project->getCatSlug())), 'amount' => $money->setAmount($transaction->getAmount())->formatCurrency(), 'transaction_id' => $transaction->getTransactionId(), 'reward_title' => '', 'delivery_date' => '', 'payer_name' => '', 'payer_email' => '');
     // Prepare data about payer if he is NOT anonymous ( is registered user with profile ).
     if ((int) $transaction->getInvestorId() > 0) {
         $investor = \JFactory::getUser($transaction->getInvestorId());
         $data['payer_email'] = $investor->get('email');
         $data['payer_name'] = $investor->get('name');
     }
     // Set reward data.
     if (is_object($reward)) {
         $data['reward_title'] = $reward->getTitle();
         $dateValidator = new Prism\Validator\Date($reward->getDeliveryDate());
         if ($dateValidator->isValid()) {
             $date = new \JDate($reward->getDeliveryDate());
             $data['delivery_date'] = $date->format($this->params->get('date_format_views', \JText::_('DATE_FORMAT_LC3')));
         }
     }
     // Send mail to the administrator
     $emailId = (int) $this->params->get('admin_mail_id', 0);
     if ($emailId > 0) {
         $email = new Emailtemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($this->app->get('fromname'));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($this->app->get('mailfrom'));
         }
         $recipientId = (int) $params->get('administrator_id', 0);
         if ($recipientId > 0) {
             $recipient = \JFactory::getUser($recipientId);
             $recipientName = $recipient->get('name');
             $recipientMail = $recipient->get('email');
         } else {
             $recipientName = $this->app->get('fromname');
             $recipientMail = $this->app->get('mailfrom');
         }
         // Prepare data for parsing
         $data['sender_name'] = $email->getSenderName();
         $data['sender_email'] = $email->getSenderEmail();
         $data['recipient_name'] = $recipientName;
         $data['recipient_email'] = $recipientMail;
         // DEBUG
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_SEND_MAIL_ADMINISTRATOR'), $this->debugType, $data) : null;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp('html', $emailMode) === 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . '_ERROR_MAIL_SENDING_ADMIN'), $this->errorType, $mailer->ErrorInfo);
         }
     }
     // Send mail to project owner.
     $emailId = (int) $this->params->get('creator_mail_id', 0);
     if ($emailId > 0) {
         $email = new Emailtemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($this->app->get('fromname'));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($this->app->get('mailfrom'));
         }
         $user = \JFactory::getUser($transaction->getReceiverId());
         $recipientName = $user->get('name');
         $recipientMail = $user->get('email');
         // Prepare data for parsing
         $data['sender_name'] = $email->getSenderName();
         $data['sender_email'] = $email->getSenderEmail();
         $data['recipient_name'] = $recipientName;
         $data['recipient_email'] = $recipientMail;
         // DEBUG
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_SEND_MAIL_PROJECT_OWNER'), $this->debugType, $data) : null;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp('html', $emailMode) === 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . '_ERROR_MAIL_SENDING_PROJECT_OWNER'), $this->errorType, $mailer->ErrorInfo);
         }
     }
     // Send mail to backer.
     $emailId = (int) $this->params->get('user_mail_id', 0);
     if ($emailId > 0 and (int) $transaction->getInvestorId() > 0) {
         $email = new Emailtemplates\Email();
         $email->setDb(\JFactory::getDbo());
         $email->load($emailId);
         if (!$email->getSenderName()) {
             $email->setSenderName($this->app->get('fromname'));
         }
         if (!$email->getSenderEmail()) {
             $email->setSenderEmail($this->app->get('mailfrom'));
         }
         $user = \JFactory::getUser($transaction->getInvestorId());
         $recipientName = $user->get('name');
         $recipientMail = $user->get('email');
         // Prepare data for parsing
         $data['sender_name'] = $email->getSenderName();
         $data['sender_email'] = $email->getSenderEmail();
         $data['recipient_name'] = $recipientName;
         $data['recipient_email'] = $recipientMail;
         // DEBUG
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_SEND_MAIL_BACKER'), $this->debugType, $data) : null;
         $email->parse($data);
         $subject = $email->getSubject();
         $body = $email->getBody($emailMode);
         $mailer = \JFactory::getMailer();
         if (strcmp('html', $emailMode) === 0) {
             // Send as HTML message
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_HTML);
         } else {
             // Send as plain text.
             $return = $mailer->sendMail($email->getSenderEmail(), $email->getSenderName(), $recipientMail, $subject, $body, Prism\Constants::MAIL_MODE_PLAIN);
         }
         // Check for an error.
         if ($return !== true) {
             $this->log->add(\JText::_($this->textPrefix . '_ERROR_MAIL_SENDING_PROJECT_OWNER'), $this->errorType, $mailer->ErrorInfo);
         }
     }
 }