示例#1
0
 /**
  * Method to delete one or more records.
  *
  * @param   array &$pks An array of record primary keys.
  *
  * @return  boolean  True if successful, false if an error occurs.
  *
  * @since   12.2
  */
 public function delete(&$pks)
 {
     $params = JComponentHelper::getParams($this->option);
     /** @var  $params Joomla\Registry\Registry */
     $folderImages = $params->get("images_directory", "images/crowdfunding");
     jimport("joomla.filesystem.path");
     jimport("joomla.filesystem.file");
     jimport("crowdfunding.project");
     foreach ($pks as $id) {
         $project = new CrowdFundingProject(JFactory::getDbo());
         $project->load($id);
         $this->deleteProjectImages($project, $folderImages);
         $this->deleteAdditionalImages($project, $folderImages);
         $this->removeIntentions($project);
         $this->removeComments($project);
         $this->removeUpdates($project);
         $this->removeRewards($project);
         $this->removeTransactions($project);
     }
     return parent::delete($pks);
 }
示例#2
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;
     }
 }
示例#3
0
 /**
  * @param int $projectId
  * @param Joomla\Registry\Registry $params
  *
  * @return stdClass
  * @throws UnexpectedValueException
  */
 protected function prepareItem($projectId, $params)
 {
     jimport("crowdfunding.project");
     $project = new CrowdFundingProject(JFactory::getDbo());
     $project->load($projectId);
     if (!$project->getId()) {
         throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_INVALID_PROJECT"));
     }
     if ($project->isCompleted()) {
         throw new UnexpectedValueException(JText::_("COM_CROWDFUNDING_ERROR_COMPLETED_PROJECT"));
     }
     // Get currency
     jimport("crowdfunding.currency");
     $currencyId = $params->get("project_currency");
     $this->currency = CrowdFundingCurrency::getInstance(JFactory::getDbo(), $currencyId, $params);
     $item = new stdClass();
     $item->id = $project->getId();
     $item->title = $project->getTitle();
     $item->slug = $project->getSlug();
     $item->catslug = $project->getCatSlug();
     $item->rewardId = $this->paymentProcess->rewardId;
     $item->amount = $this->paymentProcess->amount;
     $item->currency = $this->currency->getAbbr();
     return $item;
 }
示例#4
0
 /**
  * Create an object.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = CrowdFundingProject::getInstance(JFactory::getDbo());
  * $project->load($projectId);
  * </code>
  *
  * @param JDatabaseDriver $db
  * @param int $id
  *
  * @return null|CrowdFundingProject
  */
 public static function getInstance(JDatabaseDriver $db, $id)
 {
     if (is_null(self::$instance)) {
         $item = new CrowdFundingProject($db);
         $item->load($id);
         self::$instance = $item;
     }
     return self::$instance;
 }