コード例 #1
0
ファイル: Plugin.php プロジェクト: bharatthakkar/CrowdFunding
 /**
  * Update rewards properties - availability, distributed,...
  *
  * @param $data
  *
  * @return \Crowdfunding\Reward|null
  */
 protected function updateReward($data)
 {
     // Get reward.
     $keys = array("id" => ArrayHelper::getValue($data, "reward_id"), "project_id" => ArrayHelper::getValue($data, "project_id"));
     $reward = new Crowdfunding\Reward(\JFactory::getDbo());
     $reward->load($keys);
     // DEBUG DATA
     JDEBUG ? $this->log->add(\JText::_($this->textPrefix . "_DEBUG_REWARD_OBJECT"), $this->debugType, $reward->getProperties()) : null;
     // Check for valid reward.
     if (!$reward->getId()) {
         // Log data in the database
         $this->log->add(\JText::_($this->textPrefix . "_ERROR_INVALID_REWARD"), $this->debugType, array("data" => $data, "reward object" => $reward->getProperties()));
         return null;
     }
     // Check for valida amount between reward value and payed by user
     $txnAmount = ArrayHelper::getValue($data, "txn_amount");
     if ($txnAmount < $reward->getAmount()) {
         // Log data in the database
         $this->log->add(\JText::_($this->textPrefix . "_ERROR_INVALID_REWARD_AMOUNT"), $this->debugType, array("data" => $data, "reward object" => $reward->getProperties()));
         return null;
     }
     // Verify the availability of rewards
     if ($reward->isLimited() and !$reward->getAvailable()) {
         // Log data in the database
         $this->log->add(\JText::_($this->textPrefix . "_ERROR_REWARD_NOT_AVAILABLE"), $this->debugType, array("data" => $data, "reward object" => $reward->getProperties()));
         return null;
     }
     // Increase the number of distributed rewards
     // if there is a limit.
     if ($reward->isLimited()) {
         $reward->increaseDistributed();
         $reward->updateDistributed();
     }
     return $reward;
 }
コード例 #2
0
 /**
  * Prepare reward object and inject it in the container.
  *
  * <code>
  * $rewardId = 1;
  * $projectId = 2;
  *
  * $this->prepareReward($container, $rewardId, $projectId);
  * </code>
  *
  * @param Container $container
  * @param int $rewardId
  * @param int $projectId
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \UnexpectedValueException
  * @throws \OutOfBoundsException
  *
  * @return Reward
  */
 protected function prepareReward($container, $rewardId, $projectId)
 {
     $rewardId = (int) abs($rewardId);
     $hash = StringHelper::generateMd5Hash(Constants::CONTAINER_REWARD, array($rewardId, $projectId));
     if (!$container->exists($hash) and $rewardId > 0) {
         $reward = new Reward(\JFactory::getDbo());
         $reward->load(array('id' => $rewardId, 'project_id' => $projectId));
         if (!$reward->getId()) {
             $reward = null;
         }
         $container->set($hash, $reward);
     }
 }
コード例 #3
0
 /**
  * Decrease the number of distributed to a user rewards.
  *
  * @param Transaction $transaction
  * @param Reward|null $reward
  *
  * @throws  \RuntimeException
  * @throws  \InvalidArgumentException
  * @throws  \UnexpectedValueException
  *
  * @return void
  */
 protected function decreaseDistributedReward(Transaction $transaction, $reward)
 {
     // Check for valid reward.
     if ($reward === null or !$reward->getId()) {
         return;
     }
     // Check for valida amount between reward value and payed by user
     $txnAmount = $transaction->getAmount();
     if ($txnAmount < $reward->getAmount()) {
         return;
     }
     // Decrease the number of distributed rewards.
     $reward->decreaseDistributed();
     $reward->updateDistributed();
 }
コード例 #4
0
ファイル: Rewards.php プロジェクト: sis-direct/CrowdFunding
 /**
  * Create a reward object and return it.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5)
  * );
  *
  * $rewards   = new Crowdfunding\Reward\Rewards(\JFactory::getDbo());
  * $rewards->load($options);
  *
  * $rewardId = 1;
  * $reward   = $rewards->getReward($rewardId);
  * </code>
  *
  * @param int|string $id Reward ID.
  *
  * @return null|Reward
  */
 public function getReward($id)
 {
     if (!$id) {
         throw new \UnexpectedValueException(\JText::_('LIB_CROWDFUNDING_INVALID_REWARD_ID'));
     }
     $reward = null;
     foreach ($this->items as $item) {
         if ((int) $id === (int) $item['id']) {
             $reward = new Reward($this->db);
             $reward->bind($item);
             break;
         }
     }
     return $reward;
 }
コード例 #5
0
 /**
  * Return the rewards as array with objects.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5)
  * );
  *
  * $rewards   = new Crowdfunding\Reward\Rewards(\JFactory::getDbo());
  * $rewards->load($options);
  *
  * $items = $rewards->getRewards();
  * </code>
  *
  * @return array
  */
 public function getRewards()
 {
     $results = array();
     $i = 0;
     foreach ($this->items as $item) {
         $reward = new Reward($this->db);
         $reward->bind($item);
         $results[$i] = $reward;
         $i++;
     }
     return $results;
 }