Пример #1
0
 /**
  * Method to load a row from the database by primary key and bind the fields
  * to the JTable instance properties.
  *
  * @param   mixed   $keys  An optional primary key value to load the row by, or an array of fields to match.  If not
  *                         set the instance property value is used.
  * @param   boolean $reset True to reset the default values before loading the new row.
  *
  * @return  boolean  True if successful. False if row not found or on error (internal error state set in that case).
  *
  * @link    http://docs.joomla.org/JTable/load
  * @since   11.1
  */
 public function load($keys = null, $reset = true)
 {
     parent::load($keys, $reset);
     $this->slug = $this->id . "." . $this->alias;
     // Calculate funded percent
     if (!$this->goal) {
         $this->fundedPercent = 0;
     } else {
         $percentage = new ITPrismMath();
         $percentage->calculatePercentage($this->funded, $this->goal, 0);
         $this->fundedPercent = (string) $percentage;
     }
     // Calculate end date
     if (!empty($this->funding_days)) {
         $fundingStartDateValidator = new ITPrismValidatorDate($this->funding_start);
         if (!$fundingStartDateValidator->isValid()) {
             $this->funding_end = "0000-00-00";
         } else {
             $fundingStartDate = new CrowdFundingDate($this->funding_start);
             $fundingEndDate = $fundingStartDate->calculateEndDate($this->funding_days);
             $this->funding_end = $fundingEndDate->toSql();
         }
     }
     // Calculate days left
     $today = new CrowdFundingDate();
     $this->daysLeft = $today->calculateDaysLeft($this->funding_days, $this->funding_start, $this->funding_end);
     return true;
 }
Пример #2
0
 /**
  * Method to get an object.
  *
  * @param    integer  $id The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState($this->context . '.id');
     }
     $storedId = $this->getStoreId($id);
     if (!isset($this->item[$storedId])) {
         $this->item[$storedId] = null;
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.image,  " . "a.funded, a.goal, a.user_id, " . "a.funding_start, a.funding_end, a.funding_days,  " . $query->concatenate(array("a.id", "a.alias"), "-") . ' AS slug, ' . "b.name AS user_name, " . $query->concatenate(array("c.id", "c.alias"), "-") . ' AS catslug ')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id')->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')->where("a.id = " . (int) $id)->where("a.published = 1")->where("a.approved  = 1");
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate funded percentage.
             $percent = new ITPrismMath();
             $percent->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $percent;
             // Calculate days left
             $today = new CrowdFundingDate();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item[$storedId] = $result;
         }
     }
     return $this->item[$storedId];
 }
Пример #3
0
 public function getItem($itemId, $userId)
 {
     $storedId = $this->getStoreId($itemId . $userId);
     if (!isset($this->items[$storedId])) {
         $db = $this->getDbo();
         /** @var $db JDatabaseDriver */
         // Create a new query object.
         $query = $db->getQuery(true);
         // Select the required fields from the table.
         $query->select('a.id, a.title, a.alias, a.short_desc, a.description, a.image, a.image_square, a.image_small, a.location, ' . 'a.goal, a.funded, a.funding_type, a.funding_start, a.funding_end, a.funding_days, ' . 'a.pitch_video, a.pitch_image, a.hits, a.created, a.featured, a.published, a.approved, a.ordering, a.catid, a.type_id, a.user_id, ' . $query->concatenate(array("a.id", "a.alias"), "-") . ' AS slug, ' . 'b.name AS user_name, ' . $query->concatenate(array("c.id", "c.alias"), "-") . " AS catslug");
         $query->from($db->quoteName('#__crowdf_projects', 'a'));
         $query->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id');
         $query->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id');
         $query->where("a.id = " . (int) $itemId);
         $query->where("a.user_id = " . (int) $userId);
         $db->setQuery($query);
         $item = $db->loadObject();
         if (!empty($item)) {
             // Calculate funding end date
             if (!empty($item->funding_days)) {
                 $fundingStartDate = new CrowdFundingDate($item->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($item->funding_days);
                 $item->funding_end = $fundingEndDate->format("Y-m-d");
             }
             // Calculate funded percentage.
             $percent = new ITPrismMath();
             $percent->calculatePercentage($item->funded, $item->goal, 0);
             $item->funded_percents = (string) $percent;
             // Calculate days left
             $today = new CrowdFundingDate();
             $item->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end);
         } else {
             $item = new stdClass();
         }
         $this->items[$storedId] = $item;
     }
     return $this->items[$storedId];
 }
Пример #4
0
 public function prepareItems($items)
 {
     $result = array();
     if (!empty($items)) {
         foreach ($items as $key => $item) {
             $result[$key] = $item;
             // Calculate funding end date
             if (!empty($item->funding_days)) {
                 $fundingStartDate = new CrowdFundingDate($item->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($item->funding_days);
                 $result[$key]->funding_end = $fundingEndDate->format("Y-m-d");
             }
             // Calculate funded percentage.
             $percent = new ITPrismMath();
             $percent->calculatePercentage($item->funded, $item->goal, 0);
             $result[$key]->funded_percents = (string) $percent;
             // Calculate days left
             $today = new CrowdFundingDate();
             $result[$key]->days_left = $today->calculateDaysLeft($item->funding_days, $item->funding_start, $item->funding_end);
         }
     }
     return $result;
 }
Пример #5
0
 /**
  * Remove amount from current funded one.
  * Calculate funded percent.
  *
  * <code>
  * $projectId = 1;
  * $finds = 50;
  *
  * $project   = new CrowdFundingProject(JFactory::getDbo());
  * $project->load($projectId);
  * $project->removeFunds($finds);
  * $project->store();
  * </code>
  *
  * @param float $amount
  */
 public function removeFunds($amount)
 {
     $this->funded = $this->funded - $amount;
     // Calculate new percentage
     $math = new ITPrismMath();
     $math->calculatePercentage($this->funded, $this->goal, 0);
     $this->setFundedPercent((string) $math);
 }
Пример #6
0
 /**
  * Method to get an object.
  *
  * @param    integer  $id  The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState($this->context . '.id');
     }
     $storedId = $this->getStoreId($id);
     if (!isset($this->item[$storedId])) {
         $this->item[$storedId] = null;
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.description, a.image, a.location, " . "a.funded, a.goal, a.pitch_video, a.pitch_image, " . "a.funding_start, a.funding_end, a.funding_days, a.funding_type,  " . "a.catid, a.user_id, a.published, a.approved, a.hits, " . $query->concatenate(array("a.id", "a.alias"), "-") . ' AS slug, ' . $query->concatenate(array("b.id", "a.alias"), "-") . ' AS catslug')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName("#__categories", "b") . " ON a.catid = b.id")->where("a.id = " . (int) $id);
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate end date
             if (!empty($result->funding_days)) {
                 $fundingStartDateValidator = new ITPrismValidatorDate($result->funding_start);
                 if (!$fundingStartDateValidator->isValid()) {
                     $result->funding_end = "0000-00-00";
                 } else {
                     $fundingStartDate = new CrowdFundingDate($result->funding_start);
                     $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days);
                     $result->funding_end = $fundingEndDate->format("Y-m-d");
                 }
             }
             // Calculate funded percentage.
             $math = new ITPrismMath();
             $math->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $math;
             // Calculate days left.
             $today = new CrowdFundingDate();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item[$storedId] = $result;
         }
     }
     return $this->item[$storedId];
 }
Пример #7
0
 /**
  * @param JApplicationSite $app
  */
 protected function prepareInformation($app)
 {
     if ($this->params->get("debug_payment_disabled", 0)) {
         $app->redirect(JRoute::_('index.php?option=com_virtualcurrency&view=payment', false));
     }
     $paymentSessionData = $app->getUserState("payment.data");
     $itemId = $paymentSessionData["item_id"];
     $this->amount = $paymentSessionData["amount"];
     jimport("virtualcurrency.currency");
     $this->item = new VirtualCurrencyCurrency(JFactory::getDbo());
     $this->item->load($itemId);
     // Calculate total amount that should be paid.
     jimport("itprism.math");
     $total = new ITPrismMath();
     $total->calculateTotal(array($this->amount, $this->item->getParam("amount")));
     $this->total = (string) $total;
     // Get real currency
     $realCurrencyId = $this->params->get("payments_currency_id");
     jimport("virtualcurrency.realcurrency");
     $this->realCurrency = VirtualCurrencyRealCurrency::getInstance(JFactory::getDbo(), $realCurrencyId, $this->params);
 }
Пример #8
0
 /**
  * Method to get an object.
  *
  * @param    integer $id   The id of the object to get.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if (empty($id)) {
         $id = $this->getState('id');
     }
     if (is_null($this->item)) {
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("a.id, a.title, a.short_desc, a.image, " . "a.funded, a.goal, a.pitch_video, a.pitch_image, " . "a.funding_start, a.funding_end, a.funding_days, " . "a.funding_type, a.user_id,  a.type_id, " . "b.name AS user_name, " . $query->concatenate(array("a.id", "a.alias"), "-") . ' AS slug, ' . $query->concatenate(array("c.id", "c.alias"), "-") . ' AS catslug')->from($db->quoteName("#__crowdf_projects", "a"))->innerJoin($db->quoteName('#__users', 'b') . ' ON a.user_id = b.id')->innerJoin($db->quoteName('#__categories', 'c') . ' ON a.catid = c.id')->where("a.id = " . (int) $id)->where("a.published = 1")->where("a.approved  = 1");
         $db->setQuery($query, 0, 1);
         $result = $db->loadObject();
         // Attempt to load the row.
         if (!empty($result)) {
             // Calculate ending date by days left.
             if (!empty($result->funding_days)) {
                 $fundingStartDate = new CrowdFundingDate($result->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($result->funding_days);
                 $result->funding_end = $fundingEndDate->format("Y-m-d");
             }
             // Calculate funded percent
             $percent = new ITPrismMath();
             $percent->calculatePercentage($result->funded, $result->goal, 0);
             $result->funded_percents = (string) $percent;
             // Calculate days left.
             $today = new CrowdFundingDate();
             $result->days_left = $today->calculateDaysLeft($result->funding_days, $result->funding_start, $result->funding_end);
             $this->item = $result;
         }
     }
     return $this->item;
 }