예제 #1
0
 /**
  * Prepare some main filters.
  *
  * @param JDatabaseQuery $query
  */
 protected function prepareFilters(&$query)
 {
     $db = JFactory::getDbo();
     // Filter by featured state.
     $featured = $this->getState($this->context . ".filter_featured");
     if (!is_null($featured)) {
         if (!$featured) {
             $query->where('a.featured = 0');
         } else {
             $query->where('a.featured = 1');
         }
     }
     // Filter by category ID
     $categoryId = $this->getState($this->context . ".category_id", 0);
     if (!empty($categoryId)) {
         $query->where('a.catid = ' . (int) $categoryId);
     }
     // Filter by project type
     $projectTypeId = $this->getState($this->context . ".filter_projecttype", 0);
     if (!empty($projectTypeId)) {
         $query->where('a.type_id = ' . (int) $projectTypeId);
     }
     // Filter by country
     $countryCode = $this->getState($this->context . ".filter_country");
     if (!empty($countryCode)) {
         $query->innerJoin($db->quoteName("#__crowdf_locations", "l") . " ON a.location_id = l.id");
         $query->where('l.country_code = ' . $db->quote($countryCode));
     }
     // Filter by location
     $locationId = $this->getState($this->context . ".filter_location");
     if (!empty($locationId)) {
         $query->where('a.location_id = ' . (int) $locationId);
     }
     // Filter by funding type
     $filterFundingType = Joomla\String\String::strtoupper(Joomla\String\String::trim($this->getState($this->context . ".filter_fundingtype")));
     if (!empty($filterFundingType)) {
         $allowedFundingTypes = array("FIXED", "FLEXIBLE");
         if (in_array($filterFundingType, $allowedFundingTypes)) {
             $query->where('a.funding_type = ' . $db->quote($filterFundingType));
         }
     }
     // Filter by phrase
     $phrase = $this->getState($this->context . ".filter_phrase");
     if (!empty($phrase)) {
         $escaped = $db->escape($phrase, true);
         $quoted = $db->quote("%" . $escaped . "%", false);
         $query->where('a.title LIKE ' . $quoted);
     }
 }
예제 #2
0
파일: payment.php 프로젝트: pashakiz/crowdf
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><?php 
echo JText::_("COM_CROWDFUNDING_INVESTMENT_SUMMARY");
?>
</h2>
                </div>
                <div class="panel-body">
                    <p><?php 
$amount = $this->amount->setValue($this->paymentAmount)->formatCurrency();
echo JText::sprintf("COM_CROWDFUNDING_INVESTMENT_AMOUNT", $amount);
?>
</p>

                    <p><?php 
echo JText::_("COM_CROWDFUNDING_FUNDING_TYPE_" . Joomla\String\String::strtoupper($this->item->funding_type));
?>
</p>

                    <p class="bg-info p-5">
                        <span class="glyphicon glyphicon-info-sign"></span>
                        <?php 
$endDate = JHtml::_('date', $this->item->funding_end, JText::_('DATE_FORMAT_LC3'));
if ($this->item->funding_type == "FIXED") {
    $goal = $this->amount->setValue($this->item->goal)->formatCurrency();
    echo JText::sprintf("COM_CROWDFUNDING_FUNDING_TYPE_INFO_FIXED", $goal, $endDate);
} else {
    echo JText::sprintf("COM_CROWDFUNDING_FUNDING_TYPE_INFO_FLEXIBLE", $endDate);
}
?>
</p>
예제 #3
0
 protected function getOrderString()
 {
     $params = $this->getState("params");
     $order = $params->get("items_order", "start_date");
     $orderDirn = $params->get("items_order_direction", "desc");
     $allowedDirns = array("asc", "desc");
     if (!in_array($orderDirn, $allowedDirns)) {
         $orderDirn = "ASC";
     } else {
         $orderDirn = Joomla\String\String::strtoupper($orderDirn);
     }
     switch ($order) {
         case "ordering":
             $orderCol = "a.ordering";
             break;
         case "added":
             $orderCol = "a.id";
             break;
         default:
             // Start date
             $orderCol = "a.funding_start";
             break;
     }
     $orderString = $orderCol . ' ' . $orderDirn;
     return $orderString;
 }
예제 #4
0
 protected function getOrderString()
 {
     $params = $this->getState("params");
     $order = $params->get("categories_order", "title");
     $orderDirn = $params->get("categories_dirn", "desc");
     $allowedDirns = array("asc", "desc");
     if (!in_array($orderDirn, $allowedDirns)) {
         $orderDirn = "ASC";
     } else {
         $orderDirn = Joomla\String\String::strtoupper($orderDirn);
     }
     switch ($order) {
         case "ordering":
             $orderCol = "a.rgt";
             break;
         case "created_time":
             $orderCol = "a.created_time";
             break;
         default:
             // Title
             $orderCol = "a.title";
             break;
     }
     $orderString = $orderCol . ' ' . $orderDirn;
     return $orderString;
 }
예제 #5
0
 /**
  * Display a progress bar
  *
  * @param int    $percent A percent of fund raising
  * @param int    $daysLeft
  * @param string $fundingType
  *
  * @return string
  */
 public static function progressBar($percent, $daysLeft, $fundingType)
 {
     $html = array();
     $class = 'progress-bar-success';
     if ($daysLeft > 0) {
         $html[1] = '<div class="progress-bar ' . $class . '" style="width: ' . $percent . '%"></div>';
     } else {
         // Check for the type of funding
         if ($fundingType == "FLEXIBLE") {
             if ($percent > 0) {
                 $html[1] = '<div class="progress-bar ' . $class . '" style="width: 100%">' . Joomla\String\String::strtoupper(JText::_("COM_CROWDFUNDING_SUCCESSFUL")) . '</div>';
             } else {
                 $class = 'progress-bar-danger';
                 $html[1] = '<div class="progress-bar ' . $class . '" style="width: 100%">' . Joomla\String\String::strtoupper(JText::_("COM_CROWDFUNDING_COMPLETED")) . '</div>';
             }
         } else {
             // Fixed
             if ($percent >= 100) {
                 $html[1] = '<div class="progress-bar ' . $class . '" style="width: 100%">' . Joomla\String\String::strtoupper(JText::_("COM_CROWDFUNDING_SUCCESSFUL")) . '</div>';
             } else {
                 $class = 'progress-bar-danger';
                 $html[1] = '<div class="progress-bar ' . $class . '" style="width: 100%">' . Joomla\String\String::strtoupper(JText::_("COM_CROWDFUNDING_COMPLETED")) . '</div>';
             }
         }
     }
     $html[0] = '<div class="progress">';
     $html[2] = '</div>';
     ksort($html);
     return implode("\n", $html);
 }
예제 #6
0
 /**
  * This method performs the transaction.
  *
  * @param string $context
  * @param Joomla\Registry\Registry $params
  *
  * @return null|array
  */
 public function onPaymentNotify($context, &$params)
 {
     if (strcmp("com_crowdfunding.notify.banktransfer", $context) != 0) {
         return null;
     }
     if ($this->app->isAdmin()) {
         return null;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("raw", $docType) != 0) {
         return null;
     }
     $projectId = $this->app->input->getInt("pid");
     $amount = $this->app->input->getFloat("amount");
     // Prepare the array that will be returned by this method
     $result = array("project" => null, "reward" => null, "transaction" => null, "payment_session" => null, "redirect_url" => null, "message" => null);
     // Get project
     $project = new Crowdfunding\Project(JFactory::getDbo());
     $project->load($projectId);
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PROJECT_OBJECT"), $this->debugType, $project->getProperties()) : null;
     // Check for valid project
     if (!$project->getId()) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"), $this->debugType, array("PROJECT OBJECT" => $project->getProperties(), "REQUEST METHOD" => $this->app->input->getMethod(), "_REQUEST" => $_REQUEST));
         return null;
     }
     $currencyId = $params->get("project_currency");
     $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $currencyId, $params);
     // Prepare return URL
     $result["redirect_url"] = Joomla\String\String::trim($this->params->get('return_url'));
     if (!$result["redirect_url"]) {
         $filter = JFilterInput::getInstance();
         $uri = JUri::getInstance();
         $domain = $filter->clean($uri->toString(array("scheme", "host")));
         $result["redirect_url"] = $domain . JRoute::_(CrowdfundingHelperRoute::getBackingRoute($project->getSlug(), $project->getCatslug(), "share"), false);
     }
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RETURN_URL"), $this->debugType, $result["redirect_url"]) : null;
     // Payment Session
     $userId = JFactory::getUser()->get("id");
     $aUserId = $this->app->getUserState("auser_id");
     // Reset anonymous user hash ID,
     // because the payment session based in it will be removed when transaction completes.
     if (!empty($aUserId)) {
         $this->app->setUserState("auser_id", "");
     }
     $paymentSessionContext = Crowdfunding\Constants::PAYMENT_SESSION_CONTEXT . $project->getId();
     $paymentSessionLocal = $this->app->getUserState($paymentSessionContext);
     $paymentSession = $this->getPaymentSession(array("session_id" => $paymentSessionLocal->session_id));
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_PAYMENT_SESSION_OBJECT"), $this->debugType, $paymentSession->getProperties()) : null;
     // Validate payment session record.
     if (!$paymentSession->getId()) {
         // Log data in the database
         $this->log->add(JText::_($this->textPrefix . "_ERROR_INVALID_PAYMENT_SESSION"), $this->debugType, $paymentSession->getProperties());
         // Send response to the browser
         $response = array("success" => false, "title" => JText::_($this->textPrefix . "_FAIL"), "text" => JText::_($this->textPrefix . "_ERROR_INVALID_PROJECT"));
         return $response;
     }
     // Validate a reward and update the number of distributed ones.
     // If the user is anonymous, the system will store 0 for reward ID.
     // The anonymous users can't select rewards.
     $rewardId = $paymentSession->isAnonymous() ? 0 : (int) $paymentSession->getRewardId();
     if (!empty($rewardId)) {
         $validData = array("reward_id" => $rewardId, "project_id" => $projectId, "txn_amount" => $amount);
         $reward = $this->updateReward($validData);
         // Validate the reward.
         if (!$reward) {
             $rewardId = 0;
         }
     }
     // Prepare transaction data
     $transactionId = new Prism\String();
     $transactionId->generateRandomString(12, "BT");
     $transactionId = Joomla\String\String::strtoupper($transactionId);
     $transactionData = array("txn_amount" => $amount, "txn_currency" => $currency->getCode(), "txn_status" => "pending", "txn_id" => $transactionId, "project_id" => $projectId, "reward_id" => $rewardId, "investor_id" => (int) $userId, "receiver_id" => (int) $project->getUserId(), "service_provider" => "Bank Transfer");
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_TRANSACTION_DATA"), $this->debugType, $transactionData) : null;
     // Auto complete transaction
     if ($this->params->get("auto_complete", 0)) {
         $transactionData["txn_status"] = "completed";
         $project->addFunds($amount);
         $project->storeFunds();
     }
     // Store transaction data
     $transaction = new Crowdfunding\Transaction(JFactory::getDbo());
     $transaction->bind($transactionData);
     $transaction->store();
     // Generate object of data, based on the transaction properties.
     $properties = $transaction->getProperties();
     $result["transaction"] = Joomla\Utilities\ArrayHelper::toObject($properties);
     // Generate object of data, based on the project properties.
     $properties = $project->getProperties();
     $result["project"] = Joomla\Utilities\ArrayHelper::toObject($properties);
     // Generate object of data, based on the reward properties.
     if (!empty($reward)) {
         $properties = $reward->getProperties();
         $result["reward"] = Joomla\Utilities\ArrayHelper::toObject($properties);
     }
     // Generate data object, based on the payment session properties.
     $properties = $paymentSession->getProperties();
     $result["payment_session"] = Joomla\Utilities\ArrayHelper::toObject($properties);
     // Set message to the user.
     $result["message"] = JText::sprintf($this->textPrefix . "_TRANSACTION_REGISTERED", $transaction->getTransactionId(), $transaction->getTransactionId());
     // DEBUG DATA
     JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_RESULT_DATA"), $this->debugType, $result) : null;
     // Close payment session and remove payment session record.
     $txnStatus = isset($result["transaction"]->txn_status) ? $result["transaction"]->txn_status : null;
     $this->closePaymentSession($paymentSession, $txnStatus);
     return $result;
 }