/**
  * Return the currencies as array with objects.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5),
  *     "codes" => array("USD", "GBP")
  * );
  *
  * $currencies   = new Crowdfunding\Currencies(\JFactory::getDbo());
  * $currencies->load($options);
  *
  * $items = $currencies->getCurrencies();
  * </code>
  *
  * @return array
  */
 public function getCurrencies()
 {
     $results = array();
     $i = 0;
     foreach ($this->items as $item) {
         $currency = new Currency($this->db);
         $currency->bind($item);
         $results[$i] = $currency;
         $i++;
     }
     return $results;
 }
Example #2
0
 /**
  * Create a currency object and return it.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5),
  *     "codes" => array("USD", "GBP")
  * );
  *
  * $currencies   = new Crowdfunding\Currencies(\JFactory::getDbo());
  * $currencies->load($options);
  *
  * $currencyId = 1;
  * $currency = $currencies->getCurrency($currencyId);
  * </code>
  *
  * @param int|string $id Currency ID or Currency code.
  *
  * @throws \UnexpectedValueException
  *
  * @return Currency
  */
 public function getCurrency($id)
 {
     if (!$id) {
         throw new \UnexpectedValueException(\JText::_('LIB_CROWDFUNDING_INVALID_CURRENCY_ID'));
     }
     $currency = null;
     foreach ($this->items as $item) {
         if (is_numeric($id) and (int) $id === (int) $item['id']) {
             $currency = new Currency($this->db);
             $currency->bind($this->items[$id]);
             break;
         } elseif (strcmp($id, $item['code']) === 0) {
             $currency = new Currency($this->db);
             $currency->bind($item);
             break;
         }
     }
     return $currency;
 }
Example #3
0
 /**
  * Create a currency object and return it.
  *
  * <code>
  * $options = array(
  *     "ids" => array(1,2,3,4,5),
  *     "codes" => array("USD", "GBP")
  * );
  *
  * $currencies   = new Crowdfunding\Currencies(\JFactory::getDbo());
  * $currencies->load($options);
  *
  * $currencyId = 1;
  * $currency = $currencies->getCurrency($currencyId);
  * </code>
  *
  * @param int $id
  *
  * @throws \UnexpectedValueException
  *
  * @return null|Currency
  */
 public function getCurrency($id)
 {
     if (!$id) {
         throw new \UnexpectedValueException(\JText::_("LIB_CROWDFUNDING_INVALID_CURRENCY_ID"));
     }
     $currency = null;
     foreach ($this->items as $item) {
         if ($id == $item["id"]) {
             $currency = new Currency();
             $currency->bind($item);
             break;
         }
     }
     return $currency;
 }