/**
  * Return profile object from Proof of Identity.
  *
  * <code>
  * $userId = 1;
  *
  * $this->prepareProfile($container, $userId);
  * $profile = $this->getProfile($container, $userId);
  * </code>
  *
  * @param Container $container
  * @param int $userId
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return User
  */
 protected function getProofProfile($container, $userId)
 {
     $userId = (int) abs($userId);
     $hash = StringHelper::generateMd5Hash(Constants::CONTAINER_PROOF_PROFILE, $userId);
     if (!$container->exists($hash) and $userId > 0) {
         $this->prepareProofProfile($container, $userId);
     }
     return $container->get($hash);
 }
 /**
  * Return reward object.
  *
  * <code>
  * $rewardId = 1;
  * $projectId = 2;
  *
  * $this->prepareReward($container, $rewardId, $projectId);
  * $reward = $this->getReward($container, $rewardId, $projectId);
  * </code>
  *
  * @param Container $container
  * @param int $rewardId
  * @param int $projectId
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return Reward
  */
 protected function getReward($container, $rewardId, $projectId)
 {
     $rewardId = (int) abs($rewardId);
     $hash = StringHelper::generateMd5Hash(Constants::CONTAINER_REWARD, array($rewardId, $projectId));
     if (!$container->exists($hash) and $rewardId > 0) {
         $this->prepareReward($container, $rewardId, $projectId);
     }
     return $container->get($hash);
 }
 /**
  * Return project.
  *
  * <code>
  * $projectId = 1;
  *
  * $this->prepareProject($container, $projectId);
  * $project = $this->getProject($container, $projectId);
  * </code>
  *
  * @param Container $container
  * @param int $projectId
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return Project
  */
 protected function getProject($container, $projectId)
 {
     $projectId = (int) abs($projectId);
     $hash = StringHelper::generateMd5Hash(Constants::CONTAINER_PROJECT, $projectId);
     if (!$container->exists($hash) and $projectId > 0) {
         $this->prepareProject($container, $projectId);
     }
     return $container->get($hash);
 }
 /**
  * Return user profile.
  *
  * <code>
  * $userId = 1;
  *
  * $this->prepareProfile($container, $params, $userId);
  * $profile = $this->getProfile($container, $params, $userId);
  * </code>
  *
  * @param Container $container
  * @param Registry $params
  * @param int $userId
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return Project
  */
 protected function getProfile($container, $params, $userId)
 {
     $userId = (int) abs($userId);
     $options = array('platform' => $params->get('integration_social_platform'), 'user_id' => $userId);
     $hash = StringHelper::generateMd5Hash(Constants::CONTAINER_PROFILE, $options);
     if (!$container->exists($hash) and $userId > 0) {
         $this->prepareProfile($container, $params, $userId);
     }
     return $container->get($hash);
 }
 /**
  * Return number formatter.
  *
  * <code>
  * $fractionDigits = 2;
  *
  * $this->prepareNumberFormatter($container, $fractionDigits);
  * $numberFormatter = $this->getNumberFormatter($container, $fractionDigits);
  * </code>
  *
  * @param Container $container
  * @param int $fractionDigits
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \OutOfBoundsException
  *
  * @return \NumberFormatter
  */
 protected function getNumberFormatter($container, $fractionDigits = 2)
 {
     $fractionDigits = (int) abs($fractionDigits);
     $numberHash = StringHelper::generateMd5Hash(Constants::CONTAINER_FORMATTER_NUMBER, $fractionDigits);
     if (!$container->exists($numberHash)) {
         $this->prepareNumberFormatter($container, $fractionDigits);
         $numberFormatter = $container->get($numberHash);
     } else {
         $numberFormatter = $container->get($numberHash);
     }
     return $numberFormatter;
 }
 /**
  * Prepare safe profile alias.
  *
  * @param string $alias
  * @param int $userId
  *
  * @return string
  */
 public static function safeAlias($alias, $userId = 0)
 {
     $filter = new \JFilterInput();
     $alias = \JString::strtolower($filter->clean($alias, 'ALNUM'));
     // Check for valid alias.
     $aliasValidator = new Validator\Profile\Alias(\JFactory::getDbo(), $alias, $userId);
     if (!$aliasValidator->isValid()) {
         if (!$alias) {
             $alias = StringHelper::generateRandomString(16);
         } else {
             $alias .= mt_rand(10, 1000);
         }
     }
     return $alias;
 }
 protected function preparePointsObject($pointsId)
 {
     if ($pointsId > 0) {
         $key = StringHelper::generateMd5Hash(BasicPoints::class, $pointsId);
         if ($this->container !== null) {
             if ($this->container->exists($key)) {
                 $this->points = $this->container->get($key);
             } else {
                 $this->points = new BasicPoints($this->db);
                 $this->points->load($pointsId);
                 $this->container->set($key, $this->points);
             }
         } else {
             $this->points = new BasicPoints($this->db);
             $this->points->load($pointsId);
         }
     }
 }
 /**
  * Set Points object.
  *
  * <code>
  * $pointsId   = 1;
  * $points     = new Gamification\Points\Points(\JFactory::getDbo());
  * $points->load($pointsId);
  *
  * $level      = new Gamification\Level\Level(\JFactory::getDbo());
  * $level->setPoints($points);
  * </code>
  *
  * @param Points $points
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return self
  */
 public function setPoints(Points $points)
 {
     $this->points = $points;
     if ($this->points_id > 0 and $this->points_id !== $points->getId()) {
         throw new \UnexpectedValueException('The points ID already exists and it does not much with new Points object.');
     }
     $this->points_id = $points->getId();
     // Add the points object in the container.
     $key = StringHelper::generateMd5Hash(Points::class, $this->points_id);
     if ($this->container !== null and !$this->container->exists($key)) {
         $this->container->set($key, $this->points);
     }
     return $this;
 }
 /**
  * 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);
         }
     }
 }
Example #10
0
 /**
  * Resize the temporary file to new one.
  *
  * <code>
  * $image = $this->input->files->get('media', array(), 'array');
  * $rootFolder = "/root/joomla/tmp";
  *
  * $resizeOptions = array(
  *    'width'  => $options['thumb_width'],
  *    'height' => $options['thumb_height'],
  *    'scale'  => $options['thumb_scale']
  * );
  *
  * $file = new Prism\File\Image($image, $rootFolder);
  *
  * $file->upload();
  * $fileData = $file->resize($resize);
  * </code>
  *
  * @param array $options
  * @param bool $replace Replace the original file with the new one.
  * @param string $prefix Filename prefix.
  *
  * @throws \RuntimeException
  *
  * @return array
  */
 public function resize(array $options, $replace = false, $prefix = '')
 {
     if (!$this->file) {
         throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND_S', $this->file));
     }
     // Resize image.
     $image = new \JImage();
     $image->loadFile($this->file);
     if (!$image->isLoaded()) {
         throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND_S', $this->file));
     }
     // Resize to general size.
     $width = ArrayHelper::getValue($options, 'width', 640);
     $width = $width < 50 ? 50 : $width;
     $height = ArrayHelper::getValue($options, 'height', 480);
     $height = $height < 50 ? 50 : $height;
     $scale = ArrayHelper::getValue($options, 'scale', \JImage::SCALE_INSIDE);
     $image->resize($width, $height, false, $scale);
     // Generate new name.
     $generatedName = StringHelper::generateRandomString($this->options->get('filename_length', 16)) . '.png';
     if (is_string($prefix) and $prefix !== '') {
         $generatedName = $prefix . $generatedName;
     }
     $file = \JPath::clean($this->rootFolder . '/' . $generatedName);
     // Store to file.
     $image->toFile($file, IMAGETYPE_PNG);
     if ($replace) {
         \JFile::delete($this->file);
         $this->file = $file;
     }
     // Prepare meta data about the file.
     $fileData = array('filename' => $generatedName, 'filepath' => $file, 'type' => 'image');
     $fileData = array_merge($fileData, $this->prepareImageProperties($this->file));
     return $fileData;
 }
 /**
  * Return money formatter.
  *
  * <code>
  * $this->prepareMoneyFormatter($container, $params);
  * $money = $this->getMoneyFormatter($container, $params);
  * </code>
  *
  * @param Container $container
  * @param Registry $params
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \OutOfBoundsException
  *
  * @return Money
  */
 protected function getMoneyFormatter($container, $params)
 {
     $currencyId = $params->get('project_currency');
     $moneyHash = StringHelper::generateMd5Hash(Constants::CONTAINER_FORMATTER_MONEY, $currencyId);
     if (!$container->exists($moneyHash)) {
         $this->prepareMoneyFormatter($container, $params);
         $money = $container->get($moneyHash);
     } else {
         $money = $container->get($moneyHash);
     }
     return $money;
 }
 /**
  * Set Badge object.
  * This method will reset badge ID, user ID the ID of the record.
  *
  * <code>
  * $userBadge  = new Gamification\User\Badge\Badge(JFactory::getDbo());
  *
  * $basicBadge = new Gamification\Points\Points(JFactory::getDbo());
  * $userBadge->setBadge($basicBadge);
  * </code>
  *
  * @param BasicBadge $badge
  *
  * @throws \OutOfBoundsException
  *
  * @return self
  */
 public function setBadge(BasicBadge $badge)
 {
     $this->badge = $badge;
     $this->id = null;
     $this->user_id = null;
     $this->badge_id = $badge->getId();
     // Add the badge object in the container.
     $key = StringHelper::generateMd5Hash(BasicBadge::class, $this->badge_id);
     if ($this->container !== null and !$this->container->exists($key)) {
         $this->container->set($key, $this->badge);
     }
     return $this;
 }