/**
  * Create an object.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = Crowdfunding\Project::getInstance(\JFactory::getDbo(), $projectId);
  * </code>
  *
  * @param \JDatabaseDriver $db
  * @param int $id
  *
  * @return null|self
  *
  * @deprecated v2.8
  */
 public static function getInstance(\JDatabaseDriver $db, $id)
 {
     if (!array_key_exists($id, self::$instances)) {
         $item = new Project($db);
         $item->load($id);
         self::$instances[$id] = $item;
     }
     return self::$instances[$id];
 }
Example #2
0
 /**
  * Create an object.
  *
  * <code>
  * $projectId = 1;
  *
  * $project   = Crowdfunding\Project::getInstance(\JFactory::getDbo(), $projectId);
  * </code>
  *
  * @param \JDatabaseDriver $db
  * @param int $id
  *
  * @return null|self
  */
 public static function getInstance(\JDatabaseDriver $db, $id)
 {
     if (is_null(self::$instance)) {
         $item = new Project($db);
         $item->load($id);
         self::$instance = $item;
     }
     return self::$instance;
 }
 /**
  * Prepare project object and inject it in the container.
  *
  * <code>
  * $projectId = 1;
  *
  * $this->prepareProject($container, $projectId);
  * </code>
  *
  * @param Container $container
  * @param int $projectId
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return Project
  */
 protected function prepareProject($container, $projectId)
 {
     $projectId = (int) abs($projectId);
     $hash = StringHelper::generateMd5Hash(Constants::CONTAINER_PROJECT, $projectId);
     if (!$container->exists($hash) and $projectId > 0) {
         $project = new Project(\JFactory::getDbo());
         $project->load($projectId);
         if (!$project->getId()) {
             $project = null;
         }
         $container->set($hash, $project);
     }
 }
Example #4
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(" ", "", String::strtolower(String::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.
         $project = new Crowdfunding\Project(\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->storeFunds();
         // 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.
         $project = new Crowdfunding\Project(\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->storeFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . "_DEBUG_ACSTC"), $this->debugType, $project->getProperties()) : null;
     }
 }
 /**
  * Return the projects as array with objects.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5)
  * );
  *
  * $projects   = new Crowdfunding\Projects(\JFactory::getDbo());
  * $projects->load($options);
  *
  * $items = $projects->getProjects();
  * </code>
  *
  * @return array
  */
 public function getProjects()
 {
     $results = array();
     $i = 0;
     foreach ($this->items as $item) {
         $project = new Project($this->db);
         $project->bind($item);
         $results[$i] = $project;
         $i++;
     }
     return $results;
 }
Example #6
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 \stdClass $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, true)) {
         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.
     if (strcmp($this->serviceAlias, $item->service_alias) !== 0) {
         return;
     }
     if (strcmp($oldStatus, 'completed') === 0) {
         // Remove funds if someone change the status from completed to other one.
         $project = new Crowdfunding\Project(\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->storeFunds();
         // 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.
         $project = new Crowdfunding\Project(\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->storeFunds();
         // DEBUG DATA
         JDEBUG ? $this->log->add(\JText::_($this->textPrefix . '_DEBUG_ACSTC'), $this->debugType, $project->getProperties()) : null;
     }
 }
Example #7
0
 /**
  * Return project object by ID.
  *
  * <code>
  * $phrase = "Gamification";
  * $projectId = 1;
  *
  * $projects   = new Crowdfunding\Projects(\JFactory::getDbo());
  * $projects->loadByString($phrase);
  *
  * $project = $projects->getProject($projectId);
  * </code>
  *
  * @param int $projectId
  *
  * @return null|Project
  */
 public function getProject($projectId)
 {
     $item = null;
     if (isset($this->items[$projectId])) {
         $item = new Project(\JFactory::getDbo());
         $item->bind($this->items[$projectId]);
     }
     return $item;
 }
Example #8
0
 /**
  * Return project object by ID.
  *
  * <code>
  * $phrase = "Gamification";
  * $projectId = 1;
  *
  * $projects   = new Crowdfunding\Projects(\JFactory::getDbo());
  * $projects->loadByString($phrase);
  *
  * $project = $projects->getProject($projectId);
  * </code>
  *
  * @param int $projectId
  *
  * @return null|Project
  */
 public function getProject($projectId)
 {
     $item = null;
     foreach ($this->items as $project) {
         if ((int) $projectId === (int) $project['id']) {
             $item = new Project(\JFactory::getDbo());
             $item->bind($project);
             break;
         }
     }
     return $item;
 }
Example #9
0
 /**
  * Return project object by ID.
  *
  * <code>
  * $phrase = "Gamification";
  * $projectId = 1;
  *
  * $projects   = new Crowdfunding\Projects(\JFactory::getDbo());
  * $projects->loadByString($phrase);
  *
  * $project = $projects->getProject($projectId);
  * </code>
  *
  * @param int $id
  *
  * @return null|Project
  */
 public function getProject($id)
 {
     if (!$id) {
         throw new \UnexpectedValueException(\JText::_('LIB_CROWDFUNDING_INVALID_PROJECT_ID'));
     }
     $project = null;
     foreach ($this->items as $item) {
         if ((int) $id === (int) $item['id']) {
             $project = new Project($this->db);
             $project->bind($item);
             break;
         }
     }
     return $project;
 }