Exemple #1
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     // Get model state.
     $this->state = $this->get('State');
     $this->item = $this->get("Item");
     // Get params
     /** @var  $params Joomla\Registry\Registry */
     $params = $this->state->get("params");
     $this->params = $params;
     $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding");
     if (!$this->item) {
         $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"), "notice");
         $app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false));
         return;
     }
     // Get currency
     // Get currency
     $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency"));
     $this->amount = new Crowdfunding\Amount($this->params);
     $this->amount->setCurrency($currency);
     // Integrate with social profile.
     $this->displayCreator = $this->params->get("integration_display_creator", true);
     // Prepare integration. Load avatars and profiles.
     if ($this->displayCreator and !empty($this->item->user_id)) {
         $socialProfilesBuilder = new Prism\Integration\Profile\Builder(array("social_platform" => $this->params->get("integration_social_platform"), "user_id" => $this->item->user_id));
         $socialProfilesBuilder->build();
         $socialProfile = $socialProfilesBuilder->getProfile();
         $this->socialProfileLink = !$socialProfile ? null : $socialProfile->getLink();
     }
     // Set a link to project page
     $uri = JUri::getInstance();
     $host = $uri->toString(array("scheme", "host"));
     $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false);
     // Set a link to image
     $this->item->link_image = $host . "/" . $this->imageFolder . "/" . $this->item->image;
     $layout = $this->getLayout();
     switch ($layout) {
         case "email":
             if (!$this->params->get("security_display_friend_form", 0)) {
                 $app->enqueueMessage(JText::_("COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL"), "notice");
                 $app->redirect(JRoute::_($this->item->link, false));
                 return;
             }
             $this->prepareEmailForm($this->item);
             break;
         default:
             // Embed HTML code
             $this->embedCode = $this->prepareEmbedCode($this->item, $host);
             break;
     }
     $this->prepareDocument();
     parent::display($tpl);
 }
Exemple #2
0
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     $this->option = JFactory::getApplication()->input->get('option');
     $this->state = $this->get('State');
     $this->item = $this->get('Item');
     // Get params
     $this->params = $this->state->get('params');
     /** @var  $this->params Joomla\Registry\Registry */
     $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding');
     if (!$this->item) {
         $app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_INVALID_PROJECT'), 'notice');
         $app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute(), false));
         return;
     }
     // Get currency
     // Get currency
     $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency'));
     $this->amount = new Crowdfunding\Amount($this->params);
     $this->amount->setCurrency($currency);
     // Integrate with social profile.
     $this->displayCreator = $this->params->get('integration_display_creator', true);
     // Prepare integration. Load avatars and profiles.
     if ($this->displayCreator and (is_object($this->item) and $this->item->user_id > 0)) {
         $socialProfilesBuilder = new Prism\Integration\Profile\Builder(array('social_platform' => $this->params->get('integration_social_platform'), 'user_id' => $this->item->user_id));
         $socialProfilesBuilder->build();
         $socialProfile = $socialProfilesBuilder->getProfile();
         $this->socialProfileLink = !$socialProfile ? null : $socialProfile->getLink();
     }
     // Set a link to project page
     $uri = JUri::getInstance();
     $host = $uri->toString(array('scheme', 'host'));
     $this->item->link = $host . JRoute::_(CrowdfundingHelperRoute::getDetailsRoute($this->item->slug, $this->item->catslug), false);
     // Set a link to image
     $this->item->link_image = $host . '/' . $this->imageFolder . '/' . $this->item->image;
     $layout = $this->getLayout();
     if ($this->getLayout() === 'email') {
         if (!$this->params->get('security_display_friend_form', 0)) {
             $app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_CANT_SEND_MAIL'), 'notice');
             $app->redirect(JRoute::_($this->item->link, false));
             return;
         }
         $this->prepareEmailForm($this->item);
     } else {
         $this->embedCode = $this->prepareEmbedCode($this->item, $host);
     }
     $this->prepareDocument();
     parent::display($tpl);
 }
 /**
  * Display the view
  */
 public function display($tpl = null)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationAdministrator */
     // Get user ID
     $userId = $app->input->getInt("id");
     $model = $this->getModel();
     $this->state = $model->getState();
     $this->item = $model->getItem($userId);
     $this->params = JComponentHelper::getParams($this->option);
     // Get currency
     $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency"));
     $this->amount = new Crowdfunding\Amount($this->params);
     $this->amount->setCurrency($currency);
     // Get number of rewards.
     $statistics = new Crowdfunding\Statistics\User(JFactory::getDbo(), $this->item->id);
     $this->projects = $statistics->getProjectsNumber();
     $amounts = $statistics->getAmounts();
     if (!empty($amounts["invested"])) {
         $this->investedAmount = (double) $amounts["invested"]['amount'];
         $this->investedTransactions = (int) $amounts["invested"]['number'];
     }
     if (!empty($amounts["received"])) {
         $this->receivedAmount = (double) $amounts["received"]['amount'];
         $this->receivedTransactions = (int) $amounts["received"]['number'];
     }
     // Get social profile
     $socialPlatform = $this->params->get("integration_social_platform");
     if (!empty($socialPlatform)) {
         $options = array("social_platform" => $socialPlatform, "user_id" => $this->item->id);
         $profileBuilder = new Prism\Integration\Profile\Builder($options);
         $profileBuilder->build();
         $this->socialProfile = $profileBuilder->getProfile();
         $this->profileLink = $this->socialProfile->getLink();
     }
     $this->rewards = new Crowdfunding\User\Rewards(JFactory::getDbo());
     $this->rewards->load(array("user_id" => $this->item->id));
     $this->returnUrl = base64_encode("index.php?option=com_crowdfunding&view=user&id=" . $this->item->id);
     // Prepare actions, behaviors, scripts and document
     $this->addToolbar();
     $this->setDocument();
     parent::display($tpl);
 }
    return;
}
// Get project
$project = Crowdfunding\Project::getInstance(JFactory::getDbo(), $projectId);
if (!$project->getId()) {
    return;
}
// Get component params
$componentParams = JComponentHelper::getParams('com_crowdfunding');
/** @var  $componentParams Joomla\Registry\Registry */
$socialPlatform = $componentParams->get('integration_social_platform');
$imageFolder = $componentParams->get('images_directory', 'images/crowdfunding');
$imageWidth = $componentParams->get('image_width', 200);
$imageHeight = $componentParams->get('image_height', 200);
// Get currency
$currencyId = $componentParams->get('project_currency');
$currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $componentParams->get('project_currency'));
$amount = new Crowdfunding\Amount($componentParams);
$amount->setCurrency($currency);
// Get social platform and a link to the profile
$socialBuilder = new Prism\Integration\Profile\Builder(array('social_platform' => $socialPlatform, 'user_id' => $project->getUserId()));
$socialBuilder->build();
$socialProfile = $socialBuilder->getProfile();
$socialProfileLink = !$socialProfile ? null : $socialProfile->getLink();
// Get amounts
$fundedAmount = $amount->setValue($project->getGoal())->formatCurrency();
$raised = $amount->setValue($project->getFunded())->formatCurrency();
// Prepare the value that I am going to display
$fundedPercents = JHtml::_('crowdfunding.funded', $project->getFundedPercent());
$user = JFactory::getUser($project->getUserId());
require JModuleHelper::getLayoutPath('mod_crowdfundingdetails', $params->get('layout', 'default'));
Exemple #5
0
 protected function prepareDefaultLayout()
 {
     $this->rewards = new Crowdfunding\User\Rewards(JFactory::getDbo());
     $this->rewards->load(array("reward_id" => $this->item->id));
     $this->rewardOwnerId = CrowdfundingHelper::getUserIdByRewardId($this->item->id);
     $dateValidator = new Prism\Validator\Date($this->item->delivery);
     $this->deliveryDate = $dateValidator->isValid() ? JHtml::_('date', $this->item->delivery, JText::_('DATE_FORMAT_LC3')) : "--";
     $this->imagesFolder = CrowdfundingHelper::getImagesFolderUri($this->rewardOwnerId);
     // Get social profile
     $socialPlatform = $this->params->get("integration_social_platform");
     if (!empty($socialPlatform)) {
         $options = array("social_platform" => $socialPlatform, "user_id" => $this->rewardOwnerId);
         $profileBuilder = new Prism\Integration\Profile\Builder($options);
         $profileBuilder->build();
         $this->socialProfile = $profileBuilder->getProfile();
         $this->profileLink = $this->socialProfile->getLink();
     }
     $this->returnUrl = base64_encode("index.php?option=com_crowdfunding&view=reward&id=" . $this->item->id);
 }
Exemple #6
0
 public function addPartner()
 {
     $response = new Prism\Response\Json();
     $user = JFactory::getUser();
     // Check for registered user.
     $userId = $user->get("id");
     if (!$userId) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_NOT_LOG_IN'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     $projectId = $this->input->post->get("project_id");
     $username = $this->input->post->getString("username");
     // Get image size.
     $imageSize = $this->input->post->getString("image_size");
     if (!in_array($imageSize, $this->allowedAvatarSizes)) {
         $imageSize = "small";
     }
     $itemId = 0;
     $avatar = "media/com_crowdfunding/images/no-profile.png";
     // Validate user.
     if (!$username) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_INVALID_USERNAME'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Validate project owner.
     $validator = new Crowdfunding\Validator\Project\Owner(JFactory::getDbo(), $projectId, $userId);
     if (!$projectId or !$validator->isValid()) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_INVALID_PROJECT'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get the model
     $model = $this->getModel();
     /** @var $model CrowdfundingPartnersModelPartners */
     // Get user ID by username or email
     $partnerId = $model->getUserId($username);
     // Get user data for the partner.
     $partner = JFactory::getUser($partnerId);
     // Validate partner.
     if (!$partner->id) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_USERNAME_DOES_NOT_EXISTS'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Validate for owner and partner to be different users.
     // Check partner about that he has not been assigned.
     if ($userId == $partner->id or $model->hasAssigned($partnerId, $projectId)) {
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_CANNOT_ASSIGN'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     try {
         $itemId = $model->addPartner($partner, $projectId);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_FAIL'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_ERROR_SYSTEM'))->failure();
         echo $response;
         JFactory::getApplication()->close();
     }
     // Get component parameters
     $params = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $params Joomla\Registry\Registry */
     // Get a social platform for integration
     $socialPlatform = $params->get("integration_social_platform");
     // Get social profile
     if (!empty($socialPlatform)) {
         $socialProfileBuilder = new Prism\Integration\Profile\Builder(array("social_platform" => $socialPlatform, "user_id" => $partnerId));
         $socialProfileBuilder->build();
         $socialProfile = $socialProfileBuilder->getProfile();
         // Get avatar from social profile.
         if (!is_null($socialProfile)) {
             $avatar = $socialProfile->getAvatar($imageSize);
         }
     }
     $partnerData = array("id" => $itemId, "name" => $partner->name, "avatar" => $avatar);
     $response->setTitle(JText::_('COM_CROWDFUNDINGPARTNERS_SUCCESS'))->setText(JText::_('COM_CROWDFUNDINGPARTNERS_PARTNER_ADDED'))->setData($partnerData)->success();
     echo $response;
     JFactory::getApplication()->close();
 }
Exemple #7
0
 /**
  * @param string    $context
  * @param object    $item
  * @param Joomla\Registry\Registry    $params
  * @param int $page
  *
  * @return null|string
  */
 public function onContentAfterDisplay($context, &$item, &$params, $page = 0)
 {
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return null;
     }
     if (strcmp("com_crowdfunding.details", $context) != 0) {
         return null;
     }
     $user = JFactory::getUser($item->user_id);
     // Load language
     $this->loadLanguage();
     if ($this->params->get("display_location", 0) or $this->params->get("display_map", 0)) {
         $location = $this->getLocation($item->location_id);
     }
     // Social Profile Integration
     $componentParams = JComponentHelper::getParams("com_crowdfunding");
     /** @var  $componentParams Joomla\Registry\Registry */
     // Check for verified user account.
     $proofVerified = false;
     if ($this->params->get("display_account_state", 0) and JComponentHelper::isEnabled("com_identityproof")) {
         jimport("IdentityProof.init");
         $proof = new IdentityProof\User(JFactory::getDbo());
         $proof->load(array("user_id" => $user->get("id")));
         if ($proof->isVerified()) {
             $proofVerified = true;
         }
     }
     // Get profile
     $socialPlatform = $componentParams->get("integration_social_platform");
     if (!empty($socialPlatform)) {
         // Get social profile
         $config = array("social_platform" => $socialPlatform, "user_id" => $user->get("id"));
         $profileBuilder = new Prism\Integration\Profile\Builder($config);
         $profileBuilder->build();
         $socialProfile = $profileBuilder->getProfile();
         $profileLink = $socialProfile->getLink();
         // Prepare the avatar
         $socialAvatar = $socialProfile->getAvatar($this->params->get("image_size", "small"));
         $socialLocation = $socialProfile->getLocation();
         if ($socialProfile->getCountryCode()) {
             $socialLocation .= ", " . $socialProfile->getCountryCode();
         }
     } else {
         // Set default values
         $profileLink = "";
         $socialAvatar = $params->get("integration_avatars_default", "/media/com_crowdfunding/images/no-profile.png");
         $socialLocation = "";
     }
     // END Social Profile Integration
     // Preparing HTML output
     // Prepare map
     $mapCode = "";
     if ($this->params->get("display_map", 0) and !empty($location)) {
         $mapCode = $this->getMapCode($doc, $location);
     }
     // Prepare output
     // Get the path for the layout file
     $path = JPluginHelper::getLayoutPath('content', 'crowdfundinginfo', 'default');
     // Render the login form.
     ob_start();
     include $path;
     $html = ob_get_clean();
     return $html;
 }