Example #1
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);
         }
     }
 }
Example #2
0
 /**
  * Calculate three types of project amount - goal, funded amount and remaining amount.
  *
  * <code>
  * $projectId    = 1;
  *
  * $statistics   = new CrowdfundingStatisticsProject(\JFactory::getDbo(), $projectId);
  * $data = $statistics->getFundedAmount();
  * </code>
  *
  * @return array
  *
  * # Example result:
  * array(
  *    "goal" = array("label" => "Goal", "amount" => 1000),
  *    "funded" = array("label" => "Funded", "amount" => 100),
  *    "remaining" = array("label" => "Remaining", "amount" => 900)
  * )
  */
 public function getFundedAmount()
 {
     $data = array();
     $query = $this->db->getQuery(true);
     $query->select("a.funded, a.goal")->from($this->db->quoteName("#__crowdf_projects", "a"))->where("a.id = " . (int) $this->id);
     $this->db->setQuery($query);
     $result = $this->db->loadObject();
     /** @var $result object */
     if (empty($result->funded) or empty($result->goal)) {
         return $data;
     }
     // Get currency
     $params = \JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Registry */
     $currencyId = $params->get("project_currency");
     $currency = Currency::getInstance(\JFactory::getDbo(), $currencyId, $params);
     $amount = new Amount();
     $amount->setCurrency($currency);
     $data["goal"] = array("label" => \JText::sprintf("COM_CROWDFUNDINGFINANCE_GOAL_S", $amount->setValue($result->goal)->formatCurrency()), "amount" => (double) $result->goal);
     $data["funded"] = array("label" => \JText::sprintf("COM_CROWDFUNDINGFINANCE_FUNDED_S", $amount->setValue($result->funded)->formatCurrency()), "amount" => (double) $result->funded);
     $remaining = (double) ($result->goal - $result->funded);
     if ($remaining < 0) {
         $remaining = 0;
     }
     $data["remaining"] = array("label" => \JText::sprintf("COM_CROWDFUNDINGFINANCE_REMAINING_S", $amount->setValue($remaining)->formatCurrency()), "amount" => $remaining);
     return $data;
 }
Example #3
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);
         }
     }
 }
Example #4
0
 /**
  * Calculate three types of project amount - goal, funded amount and remaining amount.
  *
  * <code>
  * $projectId    = 1;
  *
  * $statistics   = new Crowdfunding\Statistics\Project(\JFactory::getDbo(), $projectId);
  * $data = $statistics->getFundedAmount();
  * </code>
  *
  * @return array
  *
  * # Example result:
  * array(
  *    "goal" = array("label" => "Goal", "amount" => 1000),
  *    "funded" = array("label" => "Funded", "amount" => 100),
  *    "remaining" = array("label" => "Remaining", "amount" => 900)
  * )
  */
 public function getFundedAmount()
 {
     $data = array();
     $query = $this->db->getQuery(true);
     $query->select('a.funded, a.goal')->from($this->db->quoteName('#__crowdf_projects', 'a'))->where('a.id = ' . (int) $this->id);
     $this->db->setQuery($query);
     $result = $this->db->loadObject();
     /** @var $result \stdClass */
     if ($result->funded === null or $result->goal === null) {
         return $data;
     }
     // Get currency
     $params = \JComponentHelper::getParams('com_crowdfunding');
     /** @var  $params Registry */
     $currencyId = $params->get('project_currency');
     $currency = Currency::getInstance(\JFactory::getDbo(), $currencyId, $params);
     $amount = new Amount();
     $amount->setCurrency($currency);
     $data['goal'] = array('label' => \JText::sprintf('COM_CROWDFUNDINGFINANCE_GOAL_S', $amount->setValue($result->goal)->formatCurrency()), 'amount' => (double) $result->goal);
     $data['funded'] = array('label' => \JText::sprintf('COM_CROWDFUNDINGFINANCE_FUNDED_S', $amount->setValue($result->funded)->formatCurrency()), 'amount' => (double) $result->funded);
     $remaining = (double) ($result->goal - $result->funded);
     if ($remaining < 0) {
         $remaining = 0;
     }
     $data['remaining'] = array('label' => \JText::sprintf('COM_CROWDFUNDINGFINANCE_REMAINING_S', $amount->setValue($remaining)->formatCurrency()), 'amount' => $remaining);
     return $data;
 }