Exemple #1
0
 /**
  * This method is invoked when the administrator changes transaction status from the backend.
  *
  * @param string  $context  This string gives information about that where it has been executed the trigger.
  * @param object  $item  A transaction data.
  * @param string  $oldStatus  Old status
  * @param string  $newStatus  New status
  *
  * @return void
  */
 public function onTransactionChangeState($context, &$item, $oldStatus, $newStatus)
 {
     $allowedContexts = array("com_crowdfunding.transaction", "com_crowdfundingfinance.transaction");
     if (!in_array($context, $allowedContexts)) {
         return;
     }
     $app = JFactory::getApplication();
     /** @var $app JApplicationSite */
     if ($app->isSite()) {
         return;
     }
     $doc = JFactory::getDocument();
     /**  @var $doc JDocumentHtml * */
     // Check document type
     $docType = $doc->getType();
     if (strcmp("html", $docType) != 0) {
         return;
     }
     // Verify the service provider.
     $paymentService = str_replace(" ", "", JString::strtolower(JString::trim($item->service_provider)));
     if (strcmp($this->paymentService, $paymentService) != 0) {
         return;
     }
     if (strcmp($oldStatus, "completed") == 0) {
         // Remove funds if someone change the status from completed to other one.
         jimport("crowdfunding.project");
         $project = new CrowdFundingProject(JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_BCSNC"), $this->debugType, $project->getProperties()) : null;
         $project->removeFunds($item->txn_amount);
         $project->updateFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_ACSNC"), $this->debugType, $project->getProperties()) : null;
     } elseif (strcmp($newStatus, "completed") == 0) {
         // Add funds if someone change the status to completed.
         jimport("crowdfunding.project");
         $project = new CrowdFundingProject(JFactory::getDbo());
         $project->load($item->project_id);
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_BCSTC"), $this->debugType, $project->getProperties()) : null;
         $project->addFunds($item->txn_amount);
         $project->updateFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(JText::_($this->textPrefix . "_DEBUG_ACSTC"), $this->debugType, $project->getProperties()) : null;
     }
 }